motd-assist/internal/motd/sanitize_test.go
Tronax d56659e21a
feat: add motd-assist TUI for managing dynamic MOTDs
Initial Go project built with Bubble Tea and Lip Gloss:
- Live preview and management of /etc/update-motd.d scripts
- Embedded presets (ubuntu-default, minimal, server-dashboard)
- Bundled POSIX sh style scripts (brand header, sysinfo panel, footer)
- Snapshot/restore safety around applying changes
- CLI subcommands preview, apply, restore, list-presets
- Unit tests for detect, sanitize, and apply logic
2026-08-24 14:19:28 +02:00

34 lines
957 B
Go

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")
}
}