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

Function TestGetDeterminism

obligation_property_test.go:19–54  ·  view source on GitHub ↗

============================================================================= Determinism tests ============================================================================= Verifies: SYS-REQ-086 MCDC SYS-REQ-086: get_called_twice_with_same_input=T, get_returns_identical_results=T => TRUE

(t *testing.T)

Source from the content-addressed store, hash-verified

17// Verifies: SYS-REQ-086
18// MCDC SYS-REQ-086: get_called_twice_with_same_input=T, get_returns_identical_results=T => TRUE
19func TestGetDeterminism(t *testing.T) {
20 cases := []struct {
21 name string
22 data string
23 keys []string
24 }{
25 {name: "simple string", data: `{"name":"alice"}`, keys: []string{"name"}},
26 {name: "nested object", data: `{"a":{"b":{"c":42}}}`, keys: []string{"a", "b", "c"}},
27 {name: "array index", data: `{"arr":[10,20,30]}`, keys: []string{"arr", "[1]"}},
28 {name: "missing key", data: `{"a":1}`, keys: []string{"b"}},
29 {name: "empty object", data: `{}`, keys: []string{"x"}},
30 {name: "root value no keys", data: `{"a":1}`, keys: nil},
31 {name: "boolean value", data: `{"ok":true}`, keys: []string{"ok"}},
32 {name: "null value", data: `{"x":null}`, keys: []string{"x"}},
33 }
34 for _, tc := range cases {
35 t.Run(tc.name, func(t *testing.T) {
36 data := []byte(tc.data)
37 v1, dt1, off1, err1 := Get(data, tc.keys...)
38 v2, dt2, off2, err2 := Get(data, tc.keys...)
39
40 if !bytes.Equal(v1, v2) {
41 t.Fatalf("Get value mismatch: %q vs %q", v1, v2)
42 }
43 if dt1 != dt2 {
44 t.Fatalf("Get type mismatch: %v vs %v", dt1, dt2)
45 }
46 if off1 != off2 {
47 t.Fatalf("Get offset mismatch: %d vs %d", off1, off2)
48 }
49 if (err1 == nil) != (err2 == nil) {
50 t.Fatalf("Get error mismatch: %v vs %v", err1, err2)
51 }
52 })
53 }
54}
55
56// Verifies: SYS-REQ-090
57// MCDC SYS-REQ-090: getstring_called_twice_with_same_input=T, getstring_returns_identical_results=T => TRUE

Callers

nothing calls this directly

Calls 1

GetFunction · 0.85

Tested by

no test coverage detected