Debian Codegraph @

src/tui/tui_test.go

raw
1 package tui
2
3 import "testing"
4
5 func TestWrapLine(t *testing.T) {
6 // Basic wrapping
7 lines := WrapLine("hello world", 0, 7, 8, 2)
8 if len(lines) != 2 || lines[0].Text != "hello w" || lines[1].Text != "orld" {
9 t.Errorf("Basic wrap: %v", lines)
10 }
11
12 // Exact fit - no wrapping needed
13 lines = WrapLine("hello", 0, 5, 8, 2)
14 if len(lines) != 1 || lines[0].Text != "hello" || lines[0].DisplayWidth != 5 {
15 t.Errorf("Exact fit: %v", lines)
16 }
17
18 // With prefix length
19 lines = WrapLine("hello", 3, 5, 8, 2)
20 if len(lines) != 2 || lines[0].Text != "he" || lines[1].Text != "llo" {
21 t.Errorf("Prefix length: %v", lines)
22 }
23
24 // Empty string
25 lines = WrapLine("", 0, 10, 8, 2)
26 if len(lines) != 1 || lines[0].Text != "" || lines[0].DisplayWidth != 0 {
27 t.Errorf("Empty string: %v", lines)
28 }
29
30 // Continuation lines account for wrapSignWidth
31 lines = WrapLine("abcdefghij", 0, 5, 8, 2)
32 // First line: "abcde" (5 chars fit in width 5)
33 // Continuation max: 5-2=3, so "fgh" then "ij"
34 if len(lines) != 3 || lines[0].Text != "abcde" || lines[1].Text != "fgh" || lines[2].Text != "ij" {
35 t.Errorf("Continuation: %v", lines)
36 }
37
38 // Tab expansion
39 lines = WrapLine("\there", 0, 10, 4, 2)
40 if len(lines) != 1 || lines[0].DisplayWidth != 8 {
41 t.Errorf("Tab: %v", lines)
42 }
43 }
44
45 func TestHexToColor(t *testing.T) {
46 assert := func(expr string, r, g, b int) {
47 color := HexToColor(expr)
48 if !color.is24() ||
49 int((color>>16)&0xff) != r ||
50 int((color>>8)&0xff) != g ||
51 int((color)&0xff) != b {
52 t.Fail()
53 }
54 }
55
56 assert("#ff0000", 255, 0, 0)
57 assert("#010203", 1, 2, 3)
58 assert("#102030", 16, 32, 48)
59 assert("#ffffff", 255, 255, 255)
60 }