MCPcopy Create free account
hub / github.com/buger/jsonparser / TestParsePath

Function TestParsePath

path_compiler_test.go:13–82  ·  view source on GitHub ↗

Verifies: SYS-REQ-114 (JSONPath compiled paths) reqproof:proptest:skip targeted witness/regression test; not a property-test subject SYS-REQ-114:nominal:nominal SYS-REQ-114:malformed_input:nominal

(t *testing.T)

Source from the content-addressed store, hash-verified

11// SYS-REQ-114:nominal:nominal
12// SYS-REQ-114:malformed_input:nominal
13func TestParsePath(t *testing.T) {
14 tests := []struct {
15 name string
16 path string
17 want []string
18 }{
19 {
20 name: "dot notation",
21 path: "person.name.fullName",
22 want: []string{"person", "name", "fullName"},
23 },
24 {
25 name: "optional root prefix",
26 path: "$.person.name.fullName",
27 want: []string{"person", "name", "fullName"},
28 },
29 {
30 name: "array index",
31 path: "users[0].name",
32 want: []string{"users", "[0]", "name"},
33 },
34 {
35 name: "root array and multiple brackets",
36 path: "[0][1]",
37 want: []string{"[0]", "[1]"},
38 },
39 {
40 name: "root array with dollar",
41 path: "$[0][1]",
42 want: []string{"[0]", "[1]"},
43 },
44 {
45 name: "wildcard",
46 path: "data.items[*].id",
47 want: []string{"data", "items", "[*]", "id"},
48 },
49 {
50 name: "quoted key",
51 path: `$."my key".value`,
52 want: []string{"my key", "value"},
53 },
54 {
55 name: "quoted syntax characters",
56 path: `$."key.with[syntax]".value`,
57 want: []string{"key.with[syntax]", "value"},
58 },
59 {
60 name: "quoted escaped key",
61 path: `$."say \"hello\"".value`,
62 want: []string{`say "hello"`, "value"},
63 },
64 {
65 name: "root",
66 path: "$",
67 want: []string{},
68 },
69 }
70

Callers

nothing calls this directly

Calls 1

ParsePathFunction · 0.85

Tested by

no test coverage detected