Add unit tests for escape sequence parse functions (#2116)

This commit is contained in:
Joe Lim authored and GitHub committed 2025-08-26 14:49:33 +10:00
1 parent 04afd78e65
commit 8f97bf806a
4 files changed
+67 -28

No files matched your search

+34
View File
@@ -7,6 +7,8 @@ import (
"strings"
"testing"
"time"
"github.com/gdamore/tcell/v2"
)
func TestIsRoot(t *testing.T) {
@@ -361,6 +363,38 @@ func TestGetFileExtension(t *testing.T) {
}
}
func TestOptionToFmtstr(t *testing.T) {
tests := []struct {
s string
exp string
}{
{"\033[1m", "\033[1m%s\033[0m"},
{"\033[1;7;31;42m", "\033[1;7;31;42m%s\033[0m"},
}
for _, test := range tests {
if got := optionToFmtstr(test.s); got != test.exp {
t.Errorf("at input %q expected %q but got %q", test.s, test.exp, got)
}
}
}
func TestParseEscapeSequence(t *testing.T) {
tests := []struct {
s string
exp tcell.Style
}{
{"\033[1m", tcell.StyleDefault.Bold(true)},
{"\033[1;7;31;42m", tcell.StyleDefault.Bold(true).Reverse(true).Foreground(tcell.ColorMaroon).Background(tcell.ColorGreen)},
}
for _, test := range tests {
if got := parseEscapeSequence(test.s); got != test.exp {
t.Errorf("at input %q expected '%v' but got '%v'", test.s, test.exp, got)
}
}
}
func TestStripAnsi(t *testing.T) {
tests := []struct {
s string