forked from Oudwins/zog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boolean_test.go
48 lines (42 loc) · 873 Bytes
/
boolean_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
package zog
import (
"testing"
)
func TestBoolParse(t *testing.T) {
tests := []struct {
name string
data interface{}
expectErr bool
expected bool
}{
{
name: "Valid true value",
data: true,
expected: true,
},
{
name: "Valid false value",
data: false,
expected: false,
},
{
name: "Invalid value",
data: "invalid",
expectErr: true,
expected: false, // Since it's an invalid value, it should default to false
},
}
boolProc := Bool()
for i, test := range tests {
t.Run(test.name, func(t *testing.T) {
var result bool
errs := boolProc.Parse(test.data, &result)
if len(errs) > 0 && !test.expectErr {
t.Errorf("Unexpected errors i = %d: %v", i, errs)
}
if result != test.expected {
t.Errorf("Expected %v, but got %v", test.expected, result)
}
})
}
}