-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathboolean_test.go
54 lines (42 loc) · 848 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
49
50
51
52
53
54
package httpsfv
import (
"strings"
"testing"
)
func TestBooleanMarshalSFV(t *testing.T) {
t.Parallel()
var b strings.Builder
_ = marshalBoolean(&b, true)
if b.String() != "?1" {
t.Error("Invalid marshaling")
}
b.Reset()
_ = marshalBoolean(&b, false)
if b.String() != "?0" {
t.Error("Invalid marshaling")
}
}
func TestParseBoolean(t *testing.T) {
t.Parallel()
data := []struct {
in string
out bool
err bool
}{
{"?1", true, false},
{"?0", false, false},
{"?2", false, true},
{"", false, true},
{"?", false, true},
}
for _, d := range data {
s := &scanner{data: d.in}
i, err := parseBoolean(s)
if d.err && err == nil {
t.Errorf("parseBoolean(%s): error expected", d.in)
}
if !d.err && d.out != i {
t.Errorf("parseBoolean(%s) = %v, %v; %v, <nil> expected", d.in, i, err, d.out)
}
}
}