feat: adopt x/ansi instead of hand rolling escape sequences (#96)

also contains the lipgloss width change from #94
This commit is contained in:
Kieran Klukas
2026-08-01 16:30:52 +07:00
committed by GitHub
parent efc49bacfe
commit df42c95fa9
3 changed files with 121 additions and 130 deletions
+32
View File
@@ -4,6 +4,7 @@ import (
"strings"
"testing"
"github.com/charmbracelet/x/ansi"
"github.com/versenilvis/iris/spec"
)
@@ -126,3 +127,34 @@ func TestHideMenu_PreservesTypedQueryForAI(t *testing.T) {
t.Fatalf("Expected AI suggestion to be injected into Items[0] and Visible=true")
}
}
func TestRenderMatchedTitle_ASCII(t *testing.T) {
out := renderMatchedTitle("git status", "git", false, 40)
stripped := ansi.Strip(out)
if stripped != "git status"+strings.Repeat(" ", 30) {
t.Fatalf("unexpected content: %q", stripped)
}
if !strings.Contains(out, "git") {
t.Fatalf("missing match segment: %q", out)
}
}
func TestRenderMatchedTitle_WideRunes(t *testing.T) {
out := renderMatchedTitle("日記を表示する", "日記", false, 20)
stripped := ansi.Strip(out)
if !strings.HasPrefix(stripped, "日記を表示する") {
t.Fatalf("content mangled: %q", stripped)
}
// split must occur after 日記 (width 4), not mid-grapheme
if !strings.Contains(stripped, "を") {
t.Fatalf("lost remainder: %q", stripped)
}
}
func TestRenderMatchedTitle_CaseInsensitive(t *testing.T) {
out := renderMatchedTitle("GitHub CLI", "git", false, 40)
stripped := ansi.Strip(out)
if !strings.HasPrefix(stripped, "GitHub CLI") {
t.Fatalf("case-insensitive match mangled content: %q", stripped)
}
}