-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolorizer_test.go
More file actions
80 lines (68 loc) · 1.79 KB
/
colorizer_test.go
File metadata and controls
80 lines (68 loc) · 1.79 KB
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
package prettyprint
import (
"fmt"
"strings"
"testing"
)
func TestColorize(t *testing.T) {
out := Colorize("{{.Red}}Hello {{.Default}}World{{.UnderGreen}}!{{.Default}}")
expected := "\033[0;31mHello \033[0mWorld\033[4;32m!\033[0m"
if out != expected {
t.Errorf("Expected '%s', got '%s'", expected, out)
}
}
func TestColorizeVars(t *testing.T) {
vars := map[string]string{"Who": "World"}
tpl := "{{.C.Red}}Hello {{.C.Default}}{{.V.Who}}{{.C.UnderGreen}}!{{.C.Default}}"
out := ColorizeVars(tpl, vars)
expected := "\033[0;31mHello \033[0mWorld\033[4;32m!\033[0m"
if out != expected {
t.Errorf("Expected '%s', got '%s'", expected, out)
}
}
func TestNoColor(t *testing.T) {
tpl := "{{.Red}}{{.Yellow}}{{.Green}}coffee all the things!{{.Default}}"
expected := "coffee all the things!"
out := NoColor(tpl)
if out != expected {
t.Errorf("Expected `%s`, got `%s`", expected, out)
}
}
func ExampleColorize() {
out := Colorize("{{.Red}}Hello {{.Default}}World{{.UnderGreen}}!{{.Default}}")
fmt.Println(out)
}
func ExampleColorizeVars() {
vars := map[string]string{"Who": "World"}
tpl := "{{.C.Red}}Hello {{.C.Default}}{{.V.Who}}!"
out := ColorizeVars(tpl, vars)
fmt.Println(out)
}
func TestDryccIfy(t *testing.T) {
d := DryccIfy("Test")
if strings.Contains(d, "Drycc1") {
t.Errorf("Failed to compile template")
}
if !strings.Contains(d, "Test") {
t.Errorf("Failed to render template")
}
}
func TestLogo(t *testing.T) {
l := Logo()
if l != Colors["Drycc"] {
t.Errorf("Expected \n%s\n, Got\n%s\n", Colors["Drycc"], Logo())
}
}
func TestPrettyTabs(t *testing.T) {
test := map[string]string{
"test": "testing",
"foo": "bar",
}
expected := `foo bar
test testing
`
output := PrettyTabs(test, 1)
if output != expected {
t.Errorf("Expected '%s', Got '%s'", expected, output)
}
}