diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-25 18:00:59 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-25 18:00:59 +0300 |
| commit | b642f71049ba6030e45c9ddead6d1cc2b7e289e2 (patch) | |
| tree | b577f7f3eadcfb34028293c79b4688ad0cec73ae /internal/ui/taskdetail_test.go | |
| parent | cb36d8f78ce688db6f74cac57e7c10cd334e5f6e (diff) | |
Fix UTF-8 word wrapping for sq0
Diffstat (limited to 'internal/ui/taskdetail_test.go')
| -rw-r--r-- | internal/ui/taskdetail_test.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/internal/ui/taskdetail_test.go b/internal/ui/taskdetail_test.go new file mode 100644 index 0000000..04905db --- /dev/null +++ b/internal/ui/taskdetail_test.go @@ -0,0 +1,86 @@ +package ui + +import ( + "reflect" + "testing" +) + +func TestWordWrapPreservesASCIIWrapping(t *testing.T) { + tests := []struct { + name string + text string + width int + want []string + }{ + { + name: "wraps at word boundary", + text: "alpha beta gamma delta", + width: 12, + want: []string{"alpha beta", "gamma delta"}, + }, + { + name: "normalizes ascii whitespace", + text: "alpha beta\ngamma", + width: 10, + want: []string{"alpha beta", "gamma"}, + }, + { + name: "keeps over-width word intact", + text: "alphabetagamma delta", + width: 8, + want: []string{"alphabetagamma", "delta"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := wordWrap(tt.text, tt.width) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("wordWrap(%q, %d) = %#v, want %#v", tt.text, tt.width, got, tt.want) + } + }) + } +} + +func TestWordWrapCountsUTF8Runes(t *testing.T) { + tests := []struct { + name string + text string + width int + want []string + }{ + { + name: "accented text fits by rune count", + text: "café latte", + width: 10, + want: []string{"café latte"}, + }, + { + name: "cjk text fits by rune count", + text: "漢字 test", + width: 7, + want: []string{"漢字 test"}, + }, + { + name: "emoji text fits by rune count", + text: "fix 😀 bug", + width: 9, + want: []string{"fix 😀 bug"}, + }, + { + name: "wraps multibyte text when rune count exceeds width", + text: "café latte crème", + width: 10, + want: []string{"café latte", "crème"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := wordWrap(tt.text, tt.width) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("wordWrap(%q, %d) = %#v, want %#v", tt.text, tt.width, got, tt.want) + } + }) + } +} |
