-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers_test.go
87 lines (78 loc) · 1.67 KB
/
helpers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package pretty
import (
"testing"
"github.com/muesli/termenv"
)
func TestFgColor(t *testing.T) {
txt := String("disgusting red on green")
FgColor(termenv.RGBColor("#ff0000")).Format(txt)
BgColor(termenv.RGBColor("#00ff00")).Format(txt)
t.Logf("txt: %v", txt.debugString())
t.Logf("txt: %s", txt)
}
func TestLineWrap(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input string
width int
expected string
}{
{
name: "None",
input: "The crazy fox jumped",
width: 100,
expected: "The crazy fox jumped",
},
{
name: "Basic",
input: "The crazy fox jumped",
width: 10,
expected: "The crazy\nfox jumped",
},
{
name: "WordBoundary",
input: "The crazy_fox_jumped",
width: 10,
expected: "The\ncrazy_fox_jumped",
},
{
name: "MultiLine",
input: "aabb cc dd ee ff",
width: 4,
expected: "aabb\ncc\ndd\nee\nff",
},
{
name: "EmptyString",
input: "",
width: 10,
expected: "",
},
{
name: "SingleWordLongerThanWrap",
input: "supercalifragilisticexpialidocious",
width: 10,
expected: "supercalifragilisticexpialidocious",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
txt := String(tc.input)
LineWrap(tc.width).Format(txt)
requireText(t, txt, tc.expected)
})
}
}
func TestXPad(t *testing.T) {
txt := String("a")
XPad(1, 2).Format(txt)
requireText(t, txt, " a ")
}
func TestStyle(t *testing.T) {
errorStyle := Style{
FgColor(termenv.RGBColor("#ff0000")),
BgColor(termenv.RGBColor("#000000")),
CSI(termenv.BoldSeq),
}
t.Logf("%s", Sprint(errorStyle, "SOME ERROR"))
}