-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtextattribs_test.go
157 lines (138 loc) · 3.33 KB
/
textattribs_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package washeet
import (
"testing"
)
func TestDefaultTextAttributes(t *testing.T) {
tattribs := newDefaultTextAttributes()
if tattribs.isBold() {
t.Error("should not have bold set")
}
if tattribs.isItalics() {
t.Error("should not have italics set")
}
if tattribs.isUnderline() {
t.Error("should not have underline set")
}
}
func TestSetUnsetAttributes(t *testing.T) {
type flagSetType uint8
const (
dndFlag flagSetType = iota
setFlag
unsetFlag
)
type testCase struct {
tattribs textAttribs
boldSet flagSetType
italicsSet flagSetType
underlineSet flagSetType
boldExpect bool
italicsExpect bool
underlineExpect bool
}
tcases := []testCase{
// Test setting of flags one by one when all others are unset.
// #0
testCase{
tattribs: defaultTextAttributes,
boldSet: setFlag,
italicsSet: dndFlag,
underlineSet: dndFlag,
boldExpect: true,
italicsExpect: false,
underlineExpect: false,
},
// #1
testCase{
tattribs: defaultTextAttributes,
boldSet: dndFlag,
italicsSet: setFlag,
underlineSet: dndFlag,
boldExpect: false,
italicsExpect: true,
underlineExpect: false,
},
// #2
testCase{
tattribs: defaultTextAttributes,
boldSet: dndFlag,
italicsSet: dndFlag,
underlineSet: setFlag,
boldExpect: false,
italicsExpect: false,
underlineExpect: true,
},
// Test getting of flags one by one when all are set.
// #3
testCase{
tattribs: 0x07,
boldSet: dndFlag,
italicsSet: dndFlag,
underlineSet: dndFlag,
boldExpect: true,
italicsExpect: true,
underlineExpect: true,
},
// Test unsetting of flags one by one when all are set.
// #4
testCase{
tattribs: 0x07,
boldSet: unsetFlag,
italicsSet: dndFlag,
underlineSet: dndFlag,
boldExpect: false,
italicsExpect: true,
underlineExpect: true,
},
// #5
testCase{
tattribs: 0x07,
boldSet: dndFlag,
italicsSet: unsetFlag,
underlineSet: dndFlag,
boldExpect: true,
italicsExpect: false,
underlineExpect: true,
},
// #6
testCase{
tattribs: 0x07,
boldSet: dndFlag,
italicsSet: dndFlag,
underlineSet: unsetFlag,
boldExpect: true,
italicsExpect: true,
underlineExpect: false,
},
}
for idx, tcase := range tcases {
attrib := tcase.tattribs
switch tcase.boldSet {
case setFlag:
attrib.setBold(true)
case unsetFlag:
attrib.setBold(false)
}
switch tcase.italicsSet {
case setFlag:
attrib.setItalics(true)
case unsetFlag:
attrib.setItalics(false)
}
switch tcase.underlineSet {
case setFlag:
attrib.setUnderline(true)
case unsetFlag:
attrib.setUnderline(false)
}
if attrib.isBold() != tcase.boldExpect {
t.Errorf("testcase#%d : isBold() : expected = %v, got = %v", idx, tcase.boldExpect, attrib.isBold())
}
if attrib.isItalics() != tcase.italicsExpect {
t.Errorf("testcase#%d : isItalics() : expected = %v, got = %v", idx, tcase.italicsExpect, attrib.isItalics())
}
if attrib.isUnderline() != tcase.underlineExpect {
t.Errorf("testcase#%d : isUnderline() : expected = %v, got = %v", idx, tcase.underlineExpect, attrib.isUnderline())
}
}
}