-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathconcat_test.go
114 lines (99 loc) · 4.12 KB
/
concat_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/wacul/ptr"
)
func TestConcatConfig(t *testing.T) {
assert.Nil(t, concatConfig(nil, nil), "concat(NIL,NIL)")
assert.Equal(t, &Config{CoverThreshold: ptr.Int(1)}, concatConfig(&Config{CoverThreshold: ptr.Int(1)}, nil), "concat(VAL, NIL)")
assert.Equal(t, &Config{CoverThreshold: ptr.Int(1)}, concatConfig(&Config{CoverThreshold: ptr.Int(1)}, &Config{CoverThreshold: ptr.Int(2)}), "concat(VAL, VAL)")
assert.Equal(t, &Config{CoverThreshold: ptr.Int(2)}, concatConfig(nil, &Config{CoverThreshold: ptr.Int(2)}), "concat(NIL, VAL)")
}
func TestActualConfig(t *testing.T) {
t.Run("initial actual config", func(t *testing.T) {
act := actualConfig(nil)
if act == nil {
t.Error("expected that the actual config never be nil, but not")
t.FailNow()
}
if act.BuildStyle == nil {
t.Error("expect that any property of the actual config never be nil, but not")
}
})
t.Run("actual config will save a value", func(t *testing.T) {
act := actualConfig(&Config{
CoverThreshold: ptr.Int(10),
})
if act == nil {
t.Error("expect that the actual config never be nil, but not")
t.FailNow()
}
if act.CoverThreshold == nil {
t.Error("expect that any property of the actual config never be nil, but not")
t.FailNow()
}
if *act.CoverThreshold != 10 {
t.Error("expect that the actual config will save a value, but not")
}
})
}
func TestConcatColor(t *testing.T) {
color := func(n uint8) *Color {
return &Color{Type: ColorType8Bit, Value8: n}
}
assert.Nil(t, concatColor(nil, nil), "concat(NIL,NIL)")
assert.Equal(t, color(1), concatColor(color(1), nil), "concat(VAL, NIL)")
assert.Equal(t, color(1), concatColor(color(1), color(2)), "concat(VAL, VAL)")
assert.Equal(t, color(2), concatColor(nil, color(2)), "concat(NIL, VAL)")
}
func TestActualColor(t *testing.T) {
color := func(n uint8) *Color {
return &Color{Type: ColorType8Bit, Value8: n}
}
assert.Equal(t, &Color{Type: ColorTypeNone}, actualColor(nil), "actual(NIL)")
assert.Equal(t, color(1), actualColor(color(1)), "actual(VAL)")
}
func TestConcatLabelType(t *testing.T) {
foo := (*LabelType)(ptr.String("foo"))
bar := (*LabelType)(ptr.String("bar"))
assert.Nil(t, concatLabelType(nil, nil), "concat(NIL,NIL)")
assert.Equal(t, foo, concatLabelType(foo, nil), "concat(VAL, NIL)")
assert.Equal(t, foo, concatLabelType(foo, bar), "concat(VAL, VAL)")
assert.Equal(t, bar, concatLabelType(nil, bar), "concat(NIL, VAL)")
}
func TestActualLabelType(t *testing.T) {
long := LabelTypeLong
foo := (*LabelType)(ptr.String("foo"))
assert.Equal(t, &long, actualLabelType(nil), "actual(NIL)")
assert.Equal(t, foo, actualLabelType(foo), "actual(VAL)")
}
func TestConcatStyle(t *testing.T) {
style := func(n uint8) *Style {
return &Style{Foreground: &Color{Type: ColorType8Bit, Value8: n}}
}
assert.Nil(t, concatStyle(nil, nil), "concat(NIL,NIL)")
assert.Equal(t, style(1), concatStyle(style(1), nil), "concat(VAL, NIL)")
assert.Equal(t, style(1), concatStyle(style(1), style(2)), "concat(VAL, VAL)")
assert.Equal(t, style(2), concatStyle(nil, style(2)), "concat(NIL, VAL)")
}
func TestConcatInt(t *testing.T) {
assert.Nil(t, concatInt(nil, nil), "concat(NIL,NIL)")
assert.Equal(t, ptr.Int(1), concatInt(ptr.Int(1), nil), "concat(VAL, NIL)")
assert.Equal(t, ptr.Int(1), concatInt(ptr.Int(1), ptr.Int(2)), "concat(VAL, VAL)")
assert.Equal(t, ptr.Int(2), concatInt(nil, ptr.Int(2)), "concat(NIL, VAL)")
}
func TestActualInt(t *testing.T) {
assert.Equal(t, ptr.Int(0), actualInt(nil), "actual(NIL)")
assert.Equal(t, ptr.Int(1), actualInt(ptr.Int(1)), "actual(VAL)")
}
func TestConcatBool(t *testing.T) {
assert.Nil(t, concatBool(nil, nil), "concat(NIL,NIL)")
assert.Equal(t, ptr.Bool(true), concatBool(ptr.Bool(true), nil), "concat(VAL, NIL)")
assert.Equal(t, ptr.Bool(true), concatBool(ptr.Bool(true), ptr.Bool(false)), "concat(VAL, VAL)")
assert.Equal(t, ptr.Bool(false), concatBool(nil, ptr.Bool(false)), "concat(NIL, VAL)")
}
func TestActualBool(t *testing.T) {
assert.Equal(t, ptr.Bool(false), actualBool(nil), "actual(NIL)")
assert.Equal(t, ptr.Bool(true), actualBool(ptr.Bool(true)), "actual(VAL)")
}