diff options
Diffstat (limited to 'internal/color/color_test.go')
| -rw-r--r-- | internal/color/color_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/color/color_test.go b/internal/color/color_test.go index f6b79f0..9efa19c 100644 --- a/internal/color/color_test.go +++ b/internal/color/color_test.go @@ -207,3 +207,61 @@ func TestExpandDialogTags_NoColorMode(t *testing.T) { t.Errorf("no-color mode should preserve text, got %q", got) } } + +func TestExpandTagsNamed_ResolvesNamedColor(t *testing.T) { + named := map[string]ColorSpec{"command": Parse("0A bold")} + got := ExpandTagsNamed("xterm256", named, "Type {command}look sign{/} now") + want := StyleCode("bold") + FgCode("xterm256", 10) + if !strings.Contains(got, want+"look sign"+Reset) { + t.Errorf("named tag did not resolve: %q", got) + } + if strings.Contains(got, "{command}") { + t.Errorf("named tag leaked literally: %q", got) + } +} + +func TestExpandTagsNamed_UnknownNameFallsBackToParse(t *testing.T) { + // "0B bold" is not a named key, so it must keep parsing as a spec. + named := map[string]ColorSpec{"command": Parse("0A bold")} + got := ExpandTagsNamed("xterm256", named, "x{0B bold}y{/}z") + if !strings.Contains(got, StyleCode("bold")+FgCode("xterm256", 11)+"y"+Reset) { + t.Errorf("unknown named tag should fall back to spec parsing, got %q", got) + } + // A string that is neither named nor a valid spec stays literal. + got = ExpandTagsNamed("xterm256", named, "{not_a_color}hi{/}") + if !strings.Contains(got, "{not_a_color}hi") { + t.Errorf("unknown tag should remain literal, got %q", got) + } +} + +func TestExpandTagsNamed_OffResolvesPlain(t *testing.T) { + named := map[string]ColorSpec{"command": NoColor()} + got := ExpandTagsNamed("xterm256", named, "A {command}bet{/}.") + if strings.Contains(got, "\033") { + t.Errorf("off category should render plain, got %q", got) + } + if !strings.Contains(got, "A bet.") { + t.Errorf("off category should keep the inner text, got %q", got) + } +} + +func TestExpandTagsNamed_NoColorMode(t *testing.T) { + named := map[string]ColorSpec{"command": Parse("0A bold")} + got := ExpandTagsNamed("none", named, "Type {command}look sign{/} now") + if strings.Contains(got, "\033") { + t.Errorf("no-color mode should strip ANSI, got %q", got) + } + if !strings.Contains(got, "Type look sign now") { + t.Errorf("no-color mode should keep text, got %q", got) + } +} + +func TestExpandDialogTagsNamed_ResolvesInsideQuotes(t *testing.T) { + named := map[string]ColorSpec{"command": Parse("0A bold")} + dialogSpec := Parse("D0") + got := ExpandDialogTagsNamed("xterm256", dialogSpec, named, `"Please be sure {command}look{/} at the sign."`) + want := StyleCode("bold") + FgCode("xterm256", 10) + if !strings.Contains(got, want+"look"+Reset) { + t.Errorf("named tag inside quoted dialog did not resolve: %q", got) + } +} |
