-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool_test.go
68 lines (59 loc) · 1.17 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
57
58
59
60
61
62
63
64
65
66
67
68
package dirsyn
import (
"testing"
)
func TestBoolean_codecov(t *testing.T) {
var r RFC4517
for idx, raw := range []any{
`TRUE`,
`FALSCH`,
`FALSE`,
`troo`,
`true`,
``,
true,
struct{}{},
nil,
rune(10),
"True",
} {
even := idx%2 == 0
_, err := r.Boolean(raw)
ok := err == nil
if !ok && even {
t.Errorf("%s[%d] %T failed: %v", t.Name(), idx, raw, err)
} else if ok && !even {
t.Errorf("%s[%d] %T succeeded but should have failed", t.Name(), idx, raw)
}
}
var b Boolean
_ = b.Undefined()
_ = b.String()
_ = boolean(`TRUE`)
_ = boolean(`FALSCH`)
b.Set(`TRUE`)
_ = b.String()
b.Set(`FALSE`)
_ = b.String()
b.Set(nil)
_ = b.String()
b.Set(false)
_ = b.String()
var truthy bool
b.Set(&truthy)
_ = b.String()
_, _ = booleanMatch(struct{}{}, true)
_, _ = booleanMatch(true, struct{}{})
_, _ = booleanMatch(false, true)
_, _ = booleanMatch(Boolean{}, true)
}
func TestBoolean_Match(t *testing.T) {
var b bool
result, err := booleanMatch(`TRUE`, Boolean{&b})
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
} else if !result.False() {
t.Errorf("%s failed:\nwant: %s\ngot: %s", t.Name(), `FALSE`, result)
return
}
}