forked from manifoldco/promptui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
codes_test.go
30 lines (26 loc) · 791 Bytes
/
codes_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
package promptui
import "testing"
func TestStyler(t *testing.T) {
t.Run("renders a single code", func(t *testing.T) {
red := Styler(FGRed)("hi")
expected := "\033[31mhi\033[0m"
if red != expected {
t.Errorf("style did not match: %s != %s", red, expected)
}
})
t.Run("combines multiple codes", func(t *testing.T) {
boldRed := Styler(FGRed, FGBold)("hi")
expected := "\033[31;1mhi\033[0m"
if boldRed != expected {
t.Errorf("style did not match: %s != %s", boldRed, expected)
}
})
t.Run("should not repeat reset codes for nested styles", func(t *testing.T) {
red := Styler(FGRed)("hi")
boldRed := Styler(FGBold)(red)
expected := "\033[1m\033[31mhi\033[0m"
if boldRed != expected {
t.Errorf("style did not match: %s != %s", boldRed, expected)
}
})
}