File: scanner_test.go

package info (click to toggle)
golang-github-valyala-fastjson 1.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,828 kB
  • sloc: makefile: 2
file content (39 lines) | stat: -rw-r--r-- 715 bytes parent folder | download | duplicates (3)
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")
		}
	})
}