-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
bareitem_test.go
67 lines (55 loc) · 1.14 KB
/
bareitem_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
package httpsfv
import (
"reflect"
"strings"
"testing"
"time"
)
func TestParseBareItem(t *testing.T) {
t.Parallel()
data := []struct {
in string
out interface{}
err bool
}{
{"?1", true, false},
{"?0", false, false},
{"22", int64(22), false},
{"-2.2", -2.2, false},
{`"foo"`, "foo", false},
{"abc", Token("abc"), false},
{"*abc", Token("*abc"), false},
{":YWJj:", []byte("abc"), false},
{"", nil, true},
{"~", nil, true},
}
for _, d := range data {
s := &scanner{data: d.in}
i, err := parseBareItem(s)
if d.err && err == nil {
t.Errorf("parseBareItem(%s): error expected", d.in)
}
if !d.err && !reflect.DeepEqual(d.out, i) {
t.Errorf("parseBareItem(%s) = %v, %v; %v, <nil> expected", d.in, i, err, d.out)
}
}
}
func TestMarshalBareItem(t *testing.T) {
t.Parallel()
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
var b strings.Builder
_ = marshalBareItem(&b, time.Second)
}
func TestAssertBareItem(t *testing.T) {
t.Parallel()
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
assertBareItem(time.Second)
}