-
Notifications
You must be signed in to change notification settings - Fork 136
/
scanner_test.go
39 lines (35 loc) · 715 Bytes
/
scanner_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
package fastjson
import (
"bytes"
"fmt"
"testing"
)
func TestScanner(t *testing.T) {
var sc Scanner
t.Run("success", func(t *testing.T) {
sc.InitBytes([]byte(`[] {} "" 123`))
var bb bytes.Buffer
for sc.Next() {
v := sc.Value()
fmt.Fprintf(&bb, "%s", v)
}
if err := sc.Error(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
s := bb.String()
if s != `[]{}""123` {
t.Fatalf("unexpected string obtained; got %q; want %q", s, `[]{}""123`)
}
})
t.Run("error", func(t *testing.T) {
sc.Init(`[] sdfdsfdf`)
for sc.Next() {
}
if err := sc.Error(); err == nil {
t.Fatalf("expecting non-nil error")
}
if sc.Next() {
t.Fatalf("Next must return false")
}
})
}