forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
style_test.go
88 lines (72 loc) · 2.71 KB
/
style_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
package style_test
import (
"testing"
"github.com/heroku/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/buildpacks/pack/internal/style"
h "github.com/buildpacks/pack/testhelpers"
)
func TestStyle(t *testing.T) {
color.Disable(true)
defer color.Disable(false)
spec.Run(t, "testStyle", testStyle, spec.Parallel(), spec.Report(report.Terminal{}))
}
func testStyle(t *testing.T, when spec.G, it spec.S) {
when("#Symbol", func() {
it("It should return the expected value", func() {
h.AssertEq(t, style.Symbol("Symbol"), "'Symbol'")
})
it("It should return an empty string", func() {
h.AssertEq(t, style.Symbol(""), "''")
})
it("It should return the expected value while color enabled", func() {
color.Disable(false)
defer color.Disable(true)
h.AssertEq(t, style.Symbol("Symbol"), "\x1b[94mSymbol\x1b[0m")
})
it("It should return an empty string while color enabled", func() {
color.Disable(false)
defer color.Disable(true)
h.AssertEq(t, style.Symbol(""), "\x1b[94m\x1b[0m")
})
})
when("#SymbolF", func() {
it("It should return the expected value", func() {
h.AssertEq(t, style.SymbolF("values %s %d", "hello", 1), "'values hello 1'")
})
it("It should return an empty string", func() {
h.AssertEq(t, style.SymbolF(""), "''")
})
it("It should return the expected value while color enabled", func() {
color.Disable(false)
defer color.Disable(true)
h.AssertEq(t, style.SymbolF("values %s %d", "hello", 1), "\x1b[94mvalues hello 1\x1b[0m")
})
it("It should return an empty string while color enabled", func() {
color.Disable(false)
defer color.Disable(true)
h.AssertEq(t, style.SymbolF(""), "\x1b[94m\x1b[0m")
})
})
when("#Map", func() {
it("It should return a string with all key value pairs", func() {
h.AssertEq(t, style.Map(map[string]string{"FOO": "foo", "BAR": "bar"}, "", " "), "'BAR=bar FOO=foo'")
h.AssertEq(t, style.Map(map[string]string{"BAR": "bar", "FOO": "foo"}, " ", "\n"), "'BAR=bar\n FOO=foo'")
})
it("It should return a string with all key value pairs while color enabled", func() {
color.Disable(false)
defer color.Disable(true)
h.AssertEq(t, style.Map(map[string]string{"FOO": "foo", "BAR": "bar"}, "", " "), "\x1b[94mBAR=bar FOO=foo\x1b[0m")
h.AssertEq(t, style.Map(map[string]string{"BAR": "bar", "FOO": "foo"}, " ", "\n"), "\x1b[94mBAR=bar\n FOO=foo\x1b[0m")
})
it("It should return an empty string", func() {
h.AssertEq(t, style.Map(map[string]string{}, "", " "), "''")
})
it("It should return an empty string while color enabled", func() {
color.Disable(false)
defer color.Disable(true)
h.AssertEq(t, style.Map(map[string]string{}, "", " "), "\x1b[94m\x1b[0m")
})
})
}