package motd import "testing" func TestSanitizeKeepsSGRStripsRest(t *testing.T) { in := "\x1b[1;32mgrün\x1b[0m\x1b[2J\x1b[?25lnormal\r\nnext\x1b]0;title\x07" want := "\x1b[1;32mgrün\x1b[0mnormal\x1b[0m\nnext" if got := Sanitize(in, 40); got != want { t.Errorf("Sanitize() = %q, want %q", got, want) } } func TestSanitizeTruncatesToWidth(t *testing.T) { if got := Sanitize("abcdefghij", 4); got != "abcd" { t.Errorf("plain: got %q, want %q", got, "abcd") } got := Sanitize("\x1b[31mabcdefghij\x1b[0m", 4) want := "\x1b[31mabcd\x1b[0m" if got != want { t.Errorf("colored: got %q, want %q", got, want) } } func TestSanitizeExpandsTabsAndStripsCharset(t *testing.T) { if got := Sanitize("\x1b(Ba\tb", 20); got != "a b" { t.Errorf("got %q, want %q", got, "a b") } } func TestSanitizeDropsOtherControlChars(t *testing.T) { if got := Sanitize("a\x00\x07\x08\x0bb", 20); got != "ab" { t.Errorf("got %q, want %q", got, "ab") } }