curl_test.go (1158B)
1 package handlers 2 3 import ( 4 "os" 5 "strings" 6 "testing" 7 8 "git.prime8.dev/moncheeta/prime8dev/internal/config" 9 "github.com/charmbracelet/x/ansi" 10 ) 11 12 func TestTerminalFetchColoredLogoAligned(t *testing.T) { 13 if err := os.Chdir("../../.."); err != nil { 14 t.Fatal(err) 15 } 16 out := terminalFetch(config.GetAbout(), config.CurrentJob(config.GetExperience())) 17 // aic picks its color level from COLORTERM at init (the Docker image sets 18 // COLORTERM=truecolor); without it the logo is plain but must still align. 19 if strings.Contains(os.Getenv("COLORTERM"), "truecolor") && !strings.Contains(out, "\x1b[38;2;") { 20 t.Fatal("logo is not truecolor") 21 } 22 lines := strings.Split(strings.Trim(out, "\n"), "\n") 23 for i, l := range lines { 24 plain := ansi.Strip(l) 25 if ansi.StringWidth(plain) <= curlLogoWidth { 26 continue 27 } 28 // the info column starts right after the padded logo and 3 spaces 29 if got := []rune(plain)[curlLogoWidth : curlLogoWidth+3]; string(got) != " " { 30 t.Errorf("line %d misaligned: %q", i, plain) 31 } 32 } 33 if !strings.Contains(ansi.Strip(lines[0]), "moncheeta@prime8") { 34 t.Errorf("first line missing title: %q", ansi.Strip(lines[0])) 35 } 36 }