package player import ( "fmt" "testing" "github.com/lwoodard/rtsp-streamer/internal/logbuf" ) func TestLastLinePrefersRealMessageOverStatus(t *testing.T) { w := logbuf.New(20) fmt.Fprintln(w, "Failed to open rtsps://host/x: Connection refused") fmt.Fprint(w, "\x1b[KV: 00:00:35 / 00:00:35 (100%)\n") // ANSI-wrapped status if got := lastLine(w); got != "Failed to open rtsps://host/x: Connection refused" { t.Errorf("lastLine = %q, want the error line", got) } } func TestLastLineFallsBackToStatusWhenOnlyStatus(t *testing.T) { w := logbuf.New(20) fmt.Fprint(w, "\x1b[KV: 00:00:20 / 00:00:20 (100%)\n") if got := lastLine(w); got != "V: 00:00:20 / 00:00:20 (100%)" { t.Errorf("lastLine = %q, want the stripped status line", got) } } func TestLastLineNil(t *testing.T) { if got := lastLine(nil); got != "" { t.Errorf("lastLine(nil) = %q, want empty", got) } }