tui_test.go
This file
Path
src/tui/tui_test.go
60 lines · 1.6 KiB · Go
Last changed by
Clean up non-ascii charactersJunegunn Choibefore adoption8b66489
History of this fileTake it
The walk stopped after 200 commits: lines older than 76efddd point at it.
bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 1–11why, one step back1package tui23import "testing"45func TestWrapLine(t *testing.T) {6 // Basic wrapping7 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 }11Clean up non-ascii charactersJunegunn Choibefore adoption8b66489
line 12why, one step back12 // Exact fit - no wrapping neededbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 13–60why, one step back13 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 }1718 // With prefix length19 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 }2324 // Empty string25 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 }2930 // Continuation lines account for wrapSignWidth31 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 }3738 // Tab expansion39 lines = WrapLine("\there", 0, 10, 4, 2)40 if len(lines) != 1 || lines[0].DisplayWidth != 8 {41 t.Errorf("Tab: %v", lines)42 }43}4445func 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 }5556 assert("#ff0000", 255, 0, 0)57 assert("#010203", 1, 2, 3)58 assert("#102030", 16, 32, 48)59 assert("#ffffff", 255, 255, 255)60}