MCPcopy Create free account
hub / github.com/segmentio/encoding / TestParseString

Function TestParseString

json/parse_test.go:9–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestParseString(t *testing.T) {
10 tests := []struct {
11 in string
12 out string
13 ext string
14 err string
15 }{
16 {`""`, `""`, ``, ``},
17 {`"1234567890"`, `"1234567890"`, ``, ``},
18 {`"Hello World!"`, `"Hello World!"`, ``, ``},
19 {`"Hello\"World!"`, `"Hello\"World!"`, ``, ``},
20 {`"\\"`, `"\\"`, ``, ``},
21 {`"\u0061\u0062\u0063"`, `"\u0061\u0062\u0063"`, ``, ``},
22 {`"\u0"`, ``, ``, `json: unicode code point must have at least 4 characters: 0"`},
23 }
24
25 d := decoder{}
26 for _, test := range tests {
27 t.Run(test.in, func(t *testing.T) {
28 out, ext, _, err := d.parseString([]byte(test.in))
29
30 if test.err == "" {
31 if err != nil {
32 t.Errorf("%s => %s", test.in, err)
33 return
34 }
35 } else {
36 if s := err.Error(); s != test.err {
37 t.Error("invalid error")
38 t.Logf("expected: %s", test.err)
39 t.Logf("found: %s", s)
40 }
41 }
42
43 if s := string(out); s != test.out {
44 t.Error("invalid output")
45 t.Logf("expected: %s", test.out)
46 t.Logf("found: %s", s)
47 }
48
49 if s := string(ext); s != test.ext {
50 t.Error("invalid extra bytes")
51 t.Logf("expected: %s", test.ext)
52 t.Logf("found: %s", s)
53 }
54 })
55 }
56}
57
58func TestParseStringUnquote(t *testing.T) {
59 tests := []struct {

Callers

nothing calls this directly

Calls 2

parseStringMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…