-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbool_test.go
56 lines (50 loc) · 1.09 KB
/
bool_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
package g
import (
"testing"
)
func TestStringToBool(t *testing.T) {
tests := []struct {
input string
expected bool
def bool
err bool
}{
{"true", true, false, false},
{"false", false, false, false},
{"yes", true, false, false},
{"no", false, false, false},
{"on", true, false, false},
{"off", false, false, false},
{"", true, true, true},
{"", false, false, true},
{"abc", false, false, true},
}
for _, test := range tests {
result, err := StringToBool(test.input, test.def)
if (err != nil) != test.err {
t.Errorf("StringToBool(%q) error = %v, wantErr %v",
test.input, err, test.err)
continue
}
if result != test.expected {
t.Errorf("StringToBool(%q) = %v, want %v",
test.input, result, test.expected)
}
}
}
func TestBoolToString(t *testing.T) {
tests := []struct {
input bool
expected string
}{
{true, "true"},
{false, "false"},
}
for _, test := range tests {
result := BoolToString(test.input)
if result != test.expected {
t.Errorf("BoolToString(%v) = %q, want %q",
test.input, result, test.expected)
}
}
}