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

Function TestCompilePathRoundTrip

path_compiler_test.go:170–201  ·  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:boundary:nominal SYS-REQ-114:malformed_input:nominal

(t *testing.T)

Source from the content-addressed store, hash-verified

168// SYS-REQ-114:boundary:nominal
169// SYS-REQ-114:malformed_input:nominal
170func TestCompilePathRoundTrip(t *testing.T) {
171 data := []byte(`{"users":[{"profile":{"name":"Ada","age":36}}]}`)
172 path, err := CompilePath("$.users[0].profile.age")
173 if err != nil {
174 t.Fatalf("CompilePath returned error: %v", err)
175 }
176
177 compiledValue, compiledType, compiledOffset, compiledErr := path.Get(data)
178 directValue, directType, directOffset, directErr := Get(data, "users", "[0]", "profile", "age")
179 if !bytes.Equal(compiledValue, directValue) ||
180 compiledType != directType ||
181 compiledOffset != directOffset ||
182 compiledErr != directErr {
183 t.Fatalf(
184 "compiled Get = (%s, %v, %d, %v), direct Get = (%s, %v, %d, %v)",
185 compiledValue, compiledType, compiledOffset, compiledErr,
186 directValue, directType, directOffset, directErr,
187 )
188 }
189
190 compiledSet, err := path.Set(data, []byte(`37`))
191 if err != nil {
192 t.Fatalf("compiled Set returned error: %v", err)
193 }
194 directSet, err := Set(data, []byte(`37`), "users", "[0]", "profile", "age")
195 if err != nil {
196 t.Fatalf("direct Set returned error: %v", err)
197 }
198 if !bytes.Equal(compiledSet, directSet) {
199 t.Fatalf("compiled Set = %s, direct Set = %s", compiledSet, directSet)
200 }
201}
202
203// Verifies: SYS-REQ-114 (JSONPath compiled paths)
204// reqproof:proptest:skip targeted witness/regression test; not a property-test subject

Callers

nothing calls this directly

Calls 5

CompilePathFunction · 0.85
GetFunction · 0.85
SetFunction · 0.85
GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected