MCPcopy Create free account
hub / github.com/uptrace/bun / TestArrayParser

Function TestArrayParser

dialect/pgdialect/array_parser_test.go:10–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestArrayParser(t *testing.T) {
11 tests := []struct {
12 s string
13 els []string
14 }{
15 {`{}`, []string{}},
16 {`{""}`, []string{""}},
17 {`{"\\"}`, []string{`\`}},
18 {`{"''"}`, []string{"'"}},
19 {`{{"'\"{}"}}`, []string{`{"'\"{}"}`}},
20 {`{"'\"{}"}`, []string{`'"{}`}},
21
22 {"{1,2}", []string{"1", "2"}},
23 {"{1,NULL}", []string{"1", ""}},
24 {`{"1","2"}`, []string{"1", "2"}},
25 {`{"{1}","{2}"}`, []string{"{1}", "{2}"}},
26 {`{[1,2),[3,4)}`, []string{"[1,2)", "[3,4)"}},
27
28 {`[]`, []string{}},
29 {`[{"'\"[]"}]`, []string{`{"'\"[]"}`}},
30 {`[{"id": 1}, {"id":2, "name":"bob"}]`, []string{"{\"id\": 1}", "{\"id\":2, \"name\":\"bob\"}"}},
31 }
32
33 for i, test := range tests {
34 t.Run(fmt.Sprint(i), func(t *testing.T) {
35 p := newArrayParser([]byte(test.s))
36
37 got := make([]string, 0)
38 for p.Next() {
39 elem := p.Elem()
40 got = append(got, string(elem))
41 }
42
43 require.NoError(t, p.Err())
44 require.Equal(t, test.els, got)
45 })
46 }
47}

Callers

nothing calls this directly

Calls 4

newArrayParserFunction · 0.85
ElemMethod · 0.80
NextMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…