okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffauffeat(api)!: migrate daemon and clients to protocol 361c43ca

main
1.3 KiB35 linesraw
1// Grapheme boundaries and terminal cell arithmetic are not visible through
2// daemon E2E. Verify rendered output rather than the canvas representation.
3package tui
4
5import (
6	"github.com/charmbracelet/x/ansi"
7	"strings"
8	"testing"
9	"unicode/utf8"
10)
11
12func TestAgentCanvasKeepsCellWidthWhenUnicodeLabelsAreOverwritten(t *testing.T) {
13	canvas := newCanvas(16, 1)
14	hue := rgb{}
15	canvas.put(1, 0, "東京e\u0301πŸ‘©β€πŸ’»", hue)
16	line := ansi.Strip(canvas.line(0))
17	if !strings.Contains(line, "東京e\u0301πŸ‘©β€πŸ’»") || ansi.StringWidth(line) != 16 {
18		t.Fatalf("Unicode label changed canvas width: %q", line)
19	}
20	// A graph edge landing in a wide glyph must clear the whole glyph.
21	canvas.put(2, 0, "β”‚", hue)
22	canvas.put(15, 0, "η•Œ", hue)
23	line = ansi.Strip(canvas.line(0))
24	if ansi.StringWidth(line) != 16 || !utf8.ValidString(line) || strings.Contains(line, "東") || strings.Contains(line, "η•Œ") {
25		t.Fatalf("overwriting or clipping a wide glyph corrupted the row: %q", line)
26	}
27}
28
29func TestPythonBurstLabelTruncatesWholeUnicodeCharacters(t *testing.T) {
30	code := strings.Repeat("#", 44) + "東京e\u0301η•Œ\nprint('done')"
31	label := pyLabel(code)
32	if !utf8.ValidString(label) || ansi.StringWidth(label) > 48 || !strings.HasSuffix(label, "…") {
33		t.Fatalf("truncated label is not valid terminal text: %q", label)
34	}
35}