-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrich_text_test.go
99 lines (77 loc) · 1.91 KB
/
rich_text_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
88
89
90
91
92
93
94
95
96
97
98
99
package scold_test
import (
"fmt"
"testing"
"github.com/kuredoro/scold"
"github.com/logrusorgru/aurora"
)
func TestRichTextColorize(t *testing.T) {
t.Run("identity mask", func(t *testing.T) {
rt := scold.RichText{
"test", make([]bool, 4),
}
got := rt.Colorize(0)
want := "test"
if got != want {
t.Errorf("got rich text %q, want %q", got, want)
}
})
t.Run("the mask may crop the string", func(t *testing.T) {
rt := scold.RichText{
"test", make([]bool, 2),
}
got := rt.Colorize(0)
want := "te"
if got != want {
t.Errorf("got rich text %q, want %q", got, want)
}
})
t.Run("nil mask produces emtpy string", func(t *testing.T) {
rt := scold.RichText{
"test", nil,
}
got := rt.Colorize(0)
want := ""
if got != want {
t.Errorf("got rich text %q, want %q", got, want)
}
})
t.Run("second half is highlighted", func(t *testing.T) {
rt := scold.RichText{
"abcdef", []bool{false, false, false, true, true, true},
}
got := rt.Colorize(aurora.BoldFm)
want := fmt.Sprint("abc", aurora.Bold("def"))
if got != want {
t.Errorf("got rich text '%s', want '%s'", got, want)
}
})
t.Run("checkerboard", func(t *testing.T) {
rt := scold.RichText{
"gray", []bool{true, false, true, false},
}
got := rt.Colorize(aurora.BoldFm)
want := fmt.Sprint(aurora.Bold("g"), "r", aurora.Bold("a"), "y")
if got != want {
t.Errorf("got rich text '%s', want '%s'", got, want)
}
})
}
func TestRichTextColorful(t *testing.T) {
t.Run("no colors", func(t *testing.T) {
rt := scold.RichText{
"abc", make([]bool, 3),
}
if rt.Colorful() {
t.Errorf("got rich text '%s' to be colorful, but it's not", rt.Colorize(aurora.BoldFm))
}
})
t.Run("with colors", func(t *testing.T) {
rt := scold.RichText{
"yay", []bool{false, true, true},
}
if !rt.Colorful() {
t.Errorf("got rich text '%s' to be not colorful, but it is", rt.Colorize(aurora.BoldFm))
}
})
}