(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…