Debian Codegraph @

obligation_property_test.go

raw symbols SCIP
1 package jsonparserscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.13 bytes/"
5 "encoding/jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/"
6 "errorsscip-go gomod github.com/golang/go/src go1.13 errors/"
7 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
8 "mathscip-go gomod github.com/golang/go/src go1.13 math/"
9 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
10 "testingscip-go gomod github.com/golang/go/src go1.13 testing/"
11 )
12
13 // =============================================================================
14 // Determinism tests
15 // =============================================================================
16
17 // Verifies: SYS-REQ-086
18 // MCDC SYS-REQ-086: get_called_twice_with_same_input=T, get_returns_identical_results=T => TRUE
19 func TestGetDeterminismscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetDeterminism().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 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.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
36 data := []byte(tc.data)
37 v1, dt1, off1, err1 := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(data, tc.keys...)
38 v2, dt2, off2, err2 := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(data, tc.keys...)
39
40 if !bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Equalscip-go gomod github.com/golang/go/src go1.13 bytes/Equal().(v1, v2) {
41 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get value mismatch: %q vs %q", v1, v2)
42 }
43 if dt1 != dt2 {
44 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get type mismatch: %v vs %v", dt1, dt2)
45 }
46 if off1 != off2 {
47 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get offset mismatch: %d vs %d", off1, off2)
48 }
49 if (err1 == nil) != (err2 == nil) {
50 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#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
58 func TestGetStringDeterminismscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetStringDeterminism().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
59 cases := []struct {
60 name string
61 data string
62 keys []string
63 }{
64 {name: "simple", data: `{"s":"hello"}`, keys: []string{"s"}},
65 {name: "escaped", data: `{"s":"hello\nworld"}`, keys: []string{"s"}},
66 {name: "unicode", data: `{"s":"\u00e9"}`, keys: []string{"s"}},
67 {name: "missing", data: `{"a":1}`, keys: []string{"s"}},
68 }
69 for _, tc := range cases {
70 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
71 data := []byte(tc.data)
72 v1, err1 := GetStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetString().(data, tc.keys...)
73 v2, err2 := GetStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetString().(data, tc.keys...)
74 if v1 != v2 {
75 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString value mismatch: %q vs %q", v1, v2)
76 }
77 if (err1 == nil) != (err2 == nil) {
78 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString error mismatch: %v vs %v", err1, err2)
79 }
80 })
81 }
82 }
83
84 // Verifies: SYS-REQ-094
85 // MCDC SYS-REQ-094: typed_getter_called_twice_with_same_input=T, typed_getter_returns_identical_results=T => TRUE
86 func TestTypedGetterDeterminismscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestTypedGetterDeterminism().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
87 data := []byte(`{"i":42,"f":3.14,"b":true}`)
88
89 // GetInt
90 i1, ie1 := GetIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetInt().(data, "i")
91 i2, ie2 := GetIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetInt().(data, "i")
92 if i1 != i2 || (ie1 == nil) != (ie2 == nil) {
93 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetInt not deterministic: (%d,%v) vs (%d,%v)", i1, ie1, i2, ie2)
94 }
95
96 // GetFloat
97 f1, fe1 := GetFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetFloat().(data, "f")
98 f2, fe2 := GetFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetFloat().(data, "f")
99 if f1 != f2 || (fe1 == nil) != (fe2 == nil) {
100 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetFloat not deterministic: (%f,%v) vs (%f,%v)", f1, fe1, f2, fe2)
101 }
102
103 // GetBoolean
104 b1, be1 := GetBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetBoolean().(data, "b")
105 b2, be2 := GetBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetBoolean().(data, "b")
106 if b1 != b2 || (be1 == nil) != (be2 == nil) {
107 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetBoolean not deterministic: (%v,%v) vs (%v,%v)", b1, be1, b2, be2)
108 }
109 }
110
111 // Verifies: SYS-REQ-097
112 // MCDC SYS-REQ-097: traversal_called_twice_with_same_input=T, traversal_returns_identical_results=T => TRUE
113 func TestTraversalDeterminismscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestTraversalDeterminism().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
114 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("ArrayEach", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
115 data := []byte(`{"arr":[1,2,3]}`)
116 var vals1, vals2 []string
117
118 ArrayEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ArrayEach().(data, func(value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int, err error) {
119 vals1 = append(vals1, string(value))
120 }, "arr")
121 ArrayEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ArrayEach().(data, func(value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int, err error) {
122 vals2 = append(vals2, string(value))
123 }, "arr")
124
125 if len(vals1) != len(vals2) {
126 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach length mismatch: %d vs %d", len(vals1), len(vals2))
127 }
128 for i := range vals1 {
129 if vals1[i] != vals2[i] {
130 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach element %d mismatch: %q vs %q", i, vals1[i], vals2[i])
131 }
132 }
133 })
134
135 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("ObjectEach", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
136 data := []byte(`{"a":1,"b":2,"c":3}`)
137 var keys1, keys2 []string
138
139 ObjectEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ObjectEach().(data, func(key []byte, value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int) error {
140 keys1 = append(keys1, string(key))
141 return nil
142 })
143 ObjectEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ObjectEach().(data, func(key []byte, value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int) error {
144 keys2 = append(keys2, string(key))
145 return nil
146 })
147
148 if len(keys1) != len(keys2) {
149 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach length mismatch: %d vs %d", len(keys1), len(keys2))
150 }
151 for i := range keys1 {
152 if keys1[i] != keys2[i] {
153 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach key %d mismatch: %q vs %q", i, keys1[i], keys2[i])
154 }
155 }
156 })
157
158 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("EachKey", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
159 data := []byte(`{"name":"test","age":30}`)
160 paths := [][]string{{"name"}, {"age"}, {"missing"}}
161 var results1, results2 []string
162
163 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
164 results1 = append(results1, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%d:%s:%v", idx, string(value), vt))
165 }, paths...)
166 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
167 results2 = append(results2, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%d:%s:%v", idx, string(value), vt))
168 }, paths...)
169
170 if len(results1) != len(results2) {
171 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey length mismatch: %d vs %d", len(results1), len(results2))
172 }
173 for i := range results1 {
174 if results1[i] != results2[i] {
175 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey result %d mismatch: %q vs %q", i, results1[i], results2[i])
176 }
177 }
178 })
179 }
180
181 // Verifies: SYS-REQ-103
182 // MCDC SYS-REQ-103: getunsafestring_called_twice_with_same_input=T, getunsafestring_returns_identical_results=T => TRUE
183 func TestGetUnsafeStringDeterminismscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetUnsafeStringDeterminism().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
184 data := []byte(`{"s":"hello\\world"}`)
185 v1, e1 := GetUnsafeStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetUnsafeString().(data, "s")
186 v2, e2 := GetUnsafeStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetUnsafeString().(data, "s")
187 if v1 != v2 {
188 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetUnsafeString value mismatch: %q vs %q", v1, v2)
189 }
190 if (e1 == nil) != (e2 == nil) {
191 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetUnsafeString error mismatch: %v vs %v", e1, e2)
192 }
193 }
194
195 // Verifies: SYS-REQ-106
196 // MCDC SYS-REQ-106: parse_helper_called_twice_with_same_input=T, parse_helper_returns_identical_results=T => TRUE
197 func TestParseHelperDeterminismscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestParseHelperDeterminism().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
198 // ParseBoolean
199 b1, be1 := ParseBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseBoolean().([]byte("true"))
200 b2, be2 := ParseBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseBoolean().([]byte("true"))
201 if b1 != b2 || (be1 == nil) != (be2 == nil) {
202 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseBoolean not deterministic")
203 }
204
205 // ParseInt
206 i1, ie1 := ParseIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseInt().([]byte("42"))
207 i2, ie2 := ParseIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseInt().([]byte("42"))
208 if i1 != i2 || (ie1 == nil) != (ie2 == nil) {
209 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseInt not deterministic")
210 }
211
212 // ParseFloat
213 f1, fe1 := ParseFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseFloat().([]byte("3.14"))
214 f2, fe2 := ParseFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseFloat().([]byte("3.14"))
215 if f1 != f2 || (fe1 == nil) != (fe2 == nil) {
216 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseFloat not deterministic")
217 }
218
219 // ParseString
220 s1, se1 := ParseStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseString().([]byte(`hello\nworld`))
221 s2, se2 := ParseStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseString().([]byte(`hello\nworld`))
222 if s1 != s2 || (se1 == nil) != (se2 == nil) {
223 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseString not deterministic")
224 }
225 }
226
227 // =============================================================================
228 // Idempotency tests
229 // =============================================================================
230
231 // Verifies: SYS-REQ-087
232 // MCDC SYS-REQ-087: get_called_on_valid_input=T, get_does_not_mutate_input=T => TRUE
233 func TestGetIdempotencyInputNotMutatedscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetIdempotencyInputNotMutated().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
234 original := `{"name":"alice","age":30,"nested":{"key":"value"}}`
235 data := []byte(original)
236 snapshot := make([]byte, len(data))
237 copy(snapshot, data)
238
239 // Call Get multiple times with different key paths
240 Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(data, "name")
241 Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(data, "age")
242 Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(data, "nested", "key")
243 Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(data, "missing")
244
245 if !bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Equalscip-go gomod github.com/golang/go/src go1.13 bytes/Equal().(data, snapshot) {
246 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get mutated input: original %q, after %q", snapshot, data)
247 }
248 }
249
250 // Verifies: SYS-REQ-100
251 // MCDC SYS-REQ-100: set_applied_twice_with_same_args=T, set_second_call_produces_same_result=T => TRUE
252 func TestSetIdempotencyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestSetIdempotency().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
253 data := []byte(`{"name":"alice","age":30}`)
254 setValue := []byte(`"bob"`)
255
256 // First Set application
257 result1, err1 := Setscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Set().(data, setValue, "name")
258 if err1 != nil {
259 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("First Set returned error: %v", err1)
260 }
261
262 // Second Set application on the result of the first
263 result2, err2 := Setscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Set().(result1, setValue, "name")
264 if err2 != nil {
265 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Second Set returned error: %v", err2)
266 }
267
268 // The results should be identical -- setting the same key to the same value twice
269 if !bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Equalscip-go gomod github.com/golang/go/src go1.13 bytes/Equal().(result1, result2) {
270 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Set not idempotent: first %q, second %q", result1, result2)
271 }
272 }
273
274 // =============================================================================
275 // Nil safety tests
276 // =============================================================================
277
278 // Verifies: SYS-REQ-088
279 // MCDC SYS-REQ-088: get_input_is_nil=T, get_returns_safe_result_for_nil=T => TRUE
280 func TestGetNilSafetyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetNilSafety().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
281 defer func() {
282 if r := recover(); r != nil {
283 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get(nil) panicked: %v", r)
284 }
285 }()
286
287 _, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(nil, "key")
288 if err == nil {
289 t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Get(nil, 'key') returned no error (acceptable if not-found)")
290 }
291
292 // Also test nil with no keys
293 _, _, _, err = Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(nil)
294 _ = err
295 }
296
297 // Verifies: SYS-REQ-091
298 // MCDC SYS-REQ-091: getstring_input_is_nil=T, getstring_returns_safe_result_for_nil=T => TRUE
299 func TestGetStringNilSafetyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetStringNilSafety().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
300 defer func() {
301 if r := recover(); r != nil {
302 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString(nil) panicked: %v", r)
303 }
304 }()
305
306 val, err := GetStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetString().(nil, "key")
307 if val != "" && err == nil {
308 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString(nil) returned non-empty value without error: %q", val)
309 }
310 }
311
312 // Verifies: SYS-REQ-095
313 // MCDC SYS-REQ-095: typed_getter_input_is_nil=T, typed_getter_returns_safe_result_for_nil=T => TRUE
314 func TestTypedGetterNilSafetyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestTypedGetterNilSafety().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
315 defer func() {
316 if r := recover(); r != nil {
317 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Typed getter on nil panicked: %v", r)
318 }
319 }()
320
321 ival, ierr := GetIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetInt().(nil, "key")
322 if ival != 0 && ierr == nil {
323 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetInt(nil) returned non-zero without error: %d", ival)
324 }
325
326 fval, ferr := GetFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetFloat().(nil, "key")
327 if fval != 0 && ferr == nil {
328 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetFloat(nil) returned non-zero without error: %f", fval)
329 }
330
331 bval, berr := GetBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetBoolean().(nil, "key")
332 if bval && berr == nil {
333 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetBoolean(nil) returned true without error")
334 }
335 }
336
337 // Verifies: SYS-REQ-098
338 // MCDC SYS-REQ-098: traversal_input_is_nil=T, traversal_returns_safe_result_for_nil=T => TRUE
339 func TestTraversalNilSafetyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestTraversalNilSafety().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
340 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("ArrayEach_nil", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
341 defer func() {
342 if r := recover(); r != nil {
343 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach(nil) panicked: %v", r)
344 }
345 }()
346
347 callbackCalled := false
348 _, err := ArrayEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ArrayEach().(nil, func(value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int, err error) {
349 callbackCalled = true
350 })
351 if callbackCalled {
352 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach(nil) invoked callback")
353 }
354 if err == nil {
355 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach(nil) returned no error")
356 }
357 })
358
359 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("ObjectEach_nil", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
360 defer func() {
361 if r := recover(); r != nil {
362 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach(nil) panicked: %v", r)
363 }
364 }()
365
366 callbackCalled := false
367 err := ObjectEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ObjectEach().(nil, func(key []byte, value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int) error {
368 callbackCalled = true
369 return nil
370 })
371 if callbackCalled {
372 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach(nil) invoked callback")
373 }
374 if err == nil {
375 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach(nil) returned no error")
376 }
377 })
378
379 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("EachKey_nil", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
380 defer func() {
381 if r := recover(); r != nil {
382 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey(nil) panicked: %v", r)
383 }
384 }()
385
386 callbackCalled := false
387 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(nil, func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
388 callbackCalled = true
389 }, []string{"key"})
390 if callbackCalled {
391 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey(nil) invoked callback")
392 }
393 })
394 }
395
396 // Verifies: SYS-REQ-101
397 // MCDC SYS-REQ-101: mutation_input_is_nil=T, mutation_returns_safe_result_for_nil=T => TRUE
398 func TestMutationNilSafetyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestMutationNilSafety().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
399 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("Set_nil", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
400 defer func() {
401 if r := recover(); r != nil {
402 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Set(nil) panicked: %v", r)
403 }
404 }()
405
406 _, err := Setscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Set().(nil, []byte(`"value"`), "key")
407 // Set on nil should return an error or handle gracefully
408 _ = err
409 })
410
411 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("Delete_nil", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
412 defer func() {
413 if r := recover(); r != nil {
414 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete(nil) panicked: %v", r)
415 }
416 }()
417
418 result := Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().(nil, "key")
419 // Delete on nil should return nil or empty without panic
420 _ = result
421 })
422 }
423
424 // Verifies: SYS-REQ-104
425 // MCDC SYS-REQ-104: getunsafestring_input_is_nil=T, getunsafestring_returns_safe_result_for_nil=T => TRUE
426 func TestGetUnsafeStringNilSafetyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetUnsafeStringNilSafety().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
427 defer func() {
428 if r := recover(); r != nil {
429 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetUnsafeString(nil) panicked: %v", r)
430 }
431 }()
432
433 val, err := GetUnsafeStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetUnsafeString().(nil, "key")
434 if val != "" && err == nil {
435 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetUnsafeString(nil) returned non-empty value without error: %q", val)
436 }
437 }
438
439 // Verifies: SYS-REQ-107
440 // MCDC SYS-REQ-107: parse_helper_input_is_nil=T, parse_helper_returns_safe_result_for_nil=T => TRUE
441 func TestParseHelperNilSafetyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestParseHelperNilSafety().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
442 defer func() {
443 if r := recover(); r != nil {
444 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Parse helper on nil panicked: %v", r)
445 }
446 }()
447
448 // ParseBoolean(nil)
449 bval, berr := ParseBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseBoolean().(nil)
450 if bval && berr == nil {
451 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseBoolean(nil) returned true without error")
452 }
453
454 // ParseInt(nil)
455 ival, ierr := ParseIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseInt().(nil)
456 if ival != 0 && ierr == nil {
457 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseInt(nil) returned non-zero without error: %d", ival)
458 }
459
460 // ParseFloat(nil)
461 fval, ferr := ParseFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseFloat().(nil)
462 if fval != 0 && ferr == nil {
463 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseFloat(nil) returned non-zero without error: %f", fval)
464 }
465
466 // ParseString(nil) -- should return empty string
467 sval, serr := ParseStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseString().(nil)
468 _ = serr
469 _ = sval
470 }
471
472 // =============================================================================
473 // Encoding safety tests
474 // =============================================================================
475
476 // Verifies: SYS-REQ-092
477 // MCDC SYS-REQ-092: getstring_input_has_escaped_unicode=T, getstring_decodes_and_preserves_semantics=T => TRUE
478 func TestGetStringEncodingSafetyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetStringEncodingSafety().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
479 cases := []struct {
480 name string
481 jsonData string
482 key string
483 expected string
484 }{
485 {name: "basic latin escape", jsonData: `{"s":"\u0041"}`, key: "s", expected: "A"},
486 {name: "e-acute", jsonData: `{"s":"\u00e9"}`, key: "s", expected: "\u00e9"},
487 {name: "emoji surrogate pair", jsonData: `{"s":"\uD83D\uDE00"}`, key: "s", expected: "\U0001F600"},
488 {name: "newline escape", jsonData: `{"s":"line1\nline2"}`, key: "s", expected: "line1\nline2"},
489 {name: "tab escape", jsonData: `{"s":"col1\tcol2"}`, key: "s", expected: "col1\tcol2"},
490 {name: "backslash escape", jsonData: `{"s":"path\\to\\file"}`, key: "s", expected: `path\to\file`},
491 {name: "quote escape", jsonData: `{"s":"say \"hello\""}`, key: "s", expected: `say "hello"`},
492 {name: "solidus escape", jsonData: `{"s":"a\/b"}`, key: "s", expected: "a/b"},
493 }
494 for _, tc := range cases {
495 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
496 val, err := GetStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetString().([]byte(tc.jsonData), tc.key)
497 if err != nil {
498 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString returned error: %v", err)
499 }
500 if val != tc.expected {
501 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString decoded %q, expected %q", val, tc.expected)
502 }
503 })
504 }
505 }
506
507 // Verifies: SYS-REQ-108
508 // MCDC SYS-REQ-108: parsestring_input_has_standard_escapes=T, parsestring_roundtrip_preserves_semantics=T => TRUE
509 func TestParseStringEncodingSafetyRoundtripscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestParseStringEncodingSafetyRoundtrip().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
510 cases := []struct {
511 name string
512 input string
513 expected string
514 }{
515 {name: "newline", input: `hello\nworld`, expected: "hello\nworld"},
516 {name: "tab", input: `col1\tcol2`, expected: "col1\tcol2"},
517 {name: "backslash", input: `path\\to\\file`, expected: `path\to\file`},
518 {name: "quote", input: `say \"hi\"`, expected: `say "hi"`},
519 {name: "unicode BMP", input: `\u0048\u0065\u006C\u006C\u006F`, expected: "Hello"},
520 {name: "solidus", input: `a\/b`, expected: "a/b"},
521 {name: "backspace", input: `a\bc`, expected: "a\bc"},
522 {name: "formfeed", input: `a\fc`, expected: "a\fc"},
523 {name: "carriage return", input: `a\rc`, expected: "a\rc"},
524 }
525 for _, tc := range cases {
526 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
527 decoded, err := ParseStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseString().([]byte(tc.input))
528 if err != nil {
529 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseString returned error: %v", err)
530 }
531 if decoded != tc.expected {
532 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseString decoded %q, expected %q", decoded, tc.expected)
533 }
534
535 // Round-trip check: re-encode and verify the decoded string marshals
536 // back to JSON that, when decoded again, gives the same Go string.
537 reEncoded, err := jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/Marshal().(decoded)
538 if err != nil {
539 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("json.Marshal failed: %v", err)
540 }
541 var reDecoded string
542 if err := jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/Unmarshal().(reEncoded, &reDecoded); err != nil {
543 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("json.Unmarshal failed: %v", err)
544 }
545 if reDecoded != decoded {
546 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Round-trip mismatch: original %q, round-tripped %q", decoded, reDecoded)
547 }
548 })
549 }
550 }
551
552 // =============================================================================
553 // Edge case tests
554 // =============================================================================
555
556 // Verifies: SYS-REQ-089
557 // MCDC SYS-REQ-089: get_input_is_deeply_nested=T, get_handles_deep_nesting_safely=T => TRUE
558 func TestGetDeepNestingscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetDeepNesting().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
559 defer func() {
560 if r := recover(); r != nil {
561 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get on deeply nested JSON panicked: %v", r)
562 }
563 }()
564
565 // Build 64-level nested JSON: {"a":{"a":{"a":...42...}}}
566 depth := 64
567 var keys []string
568 prefix := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Repeatscip-go gomod github.com/golang/go/src go1.13 strings/Repeat().(`{"a":`, depth)
569 suffix := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Repeatscip-go gomod github.com/golang/go/src go1.13 strings/Repeat().(`}`, depth)
570 data := []byte(prefix + `42` + suffix)
571 for i := 0; i < depth; i++ {
572 keys = append(keys, "a")
573 }
574
575 val, dt, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(data, keys...)
576 if err != nil {
577 t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("Get on %d-deep nesting returned error (acceptable): %v", depth, err)
578 return
579 }
580 if dt != Numberscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Number. {
581 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected Number type at depth %d, got %v", depth, dt)
582 }
583 if string(val) != "42" {
584 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected value 42, got %q", val)
585 }
586 }
587
588 // Verifies: SYS-REQ-093
589 // MCDC SYS-REQ-093: getstring_input_has_unicode_edge_cases=T, getstring_handles_unicode_edges_safely=T => TRUE
590 func TestGetStringUnicodeEdgeCasesscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetStringUnicodeEdgeCases().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
591 cases := []struct {
592 name string
593 jsonData string
594 key string
595 wantErr bool
596 }{
597 {
598 name: "BOM character",
599 jsonData: `{"s":"\uFEFF"}`,
600 key: "s",
601 },
602 {
603 name: "zero-width joiner",
604 jsonData: `{"s":"\u200D"}`,
605 key: "s",
606 },
607 {
608 name: "replacement character",
609 jsonData: `{"s":"\uFFFD"}`,
610 key: "s",
611 },
612 {
613 name: "null character escape",
614 jsonData: `{"s":"\u0000"}`,
615 key: "s",
616 },
617 {
618 name: "max BMP codepoint",
619 jsonData: `{"s":"\uFFFF"}`,
620 key: "s",
621 },
622 {
623 name: "multi-byte UTF-8 literal in value",
624 jsonData: "{\"s\":\"\xe2\x80\x8b\"}", // zero-width space (U+200B) as raw UTF-8
625 key: "s",
626 },
627 }
628 for _, tc := range cases {
629 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
630 defer func() {
631 if r := recover(); r != nil {
632 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString panicked on %s: %v", tc.name, r)
633 }
634 }()
635
636 val, err := GetStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetString().([]byte(tc.jsonData), tc.key)
637 if tc.wantErr && err == nil {
638 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected error for %s", tc.name)
639 }
640 if !tc.wantErr && err != nil {
641 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString(%s) returned error: %v", tc.name, err)
642 }
643 _ = val
644 })
645 }
646 }
647
648 // Verifies: SYS-REQ-096
649 // MCDC SYS-REQ-096: getint_input_has_large_number_edge_case=T, getint_handles_large_numbers_safely=T => TRUE
650 func TestGetIntLargeNumberEdgeCasesscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetIntLargeNumberEdgeCases().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
651 cases := []struct {
652 name string
653 data string
654 key string
655 wantVal int64
656 wantErr bool
657 }{
658 {
659 name: "max int64",
660 data: fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().(`{"n":%d}`, mathscip-go gomod github.com/golang/go/src go1.13 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.13 math/MaxInt64.),
661 key: "n",
662 wantVal: mathscip-go gomod github.com/golang/go/src go1.13 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.13 math/MaxInt64.,
663 },
664 {
665 name: "min int64",
666 data: fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().(`{"n":%d}`, mathscip-go gomod github.com/golang/go/src go1.13 math/.MinInt64scip-go gomod github.com/golang/go/src go1.13 math/MinInt64.),
667 key: "n",
668 wantVal: mathscip-go gomod github.com/golang/go/src go1.13 math/.MinInt64scip-go gomod github.com/golang/go/src go1.13 math/MinInt64.,
669 },
670 {
671 name: "overflow beyond max int64",
672 data: `{"n":9223372036854775808}`,
673 key: "n",
674 wantErr: true,
675 },
676 {
677 name: "negative zero",
678 data: `{"n":-0}`,
679 key: "n",
680 wantVal: 0,
681 },
682 {
683 name: "zero",
684 data: `{"n":0}`,
685 key: "n",
686 wantVal: 0,
687 },
688 }
689 for _, tc := range cases {
690 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
691 defer func() {
692 if r := recover(); r != nil {
693 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetInt panicked: %v", r)
694 }
695 }()
696
697 val, err := GetIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetInt().([]byte(tc.data), tc.key)
698 if tc.wantErr {
699 if err == nil {
700 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected error, got value %d", val)
701 }
702 return
703 }
704 if err != nil {
705 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetInt returned error: %v", err)
706 }
707 if val != tc.wantVal {
708 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetInt = %d, want %d", val, tc.wantVal)
709 }
710 })
711 }
712 }
713
714 // Verifies: SYS-REQ-099
715 // MCDC SYS-REQ-099: traversal_input_is_deeply_nested=T, traversal_handles_deep_nesting_safely=T => TRUE
716 func TestTraversalDeepNestingscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestTraversalDeepNesting().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
717 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("ArrayEach_deep", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
718 defer func() {
719 if r := recover(); r != nil {
720 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach on deep nesting panicked: %v", r)
721 }
722 }()
723
724 // Build deeply nested array: [[[[...42...]]]]
725 depth := 64
726 prefix := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Repeatscip-go gomod github.com/golang/go/src go1.13 strings/Repeat().("[", depth)
727 suffix := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Repeatscip-go gomod github.com/golang/go/src go1.13 strings/Repeat().("]", depth)
728 data := []byte(prefix + "42" + suffix)
729
730 // ArrayEach on the outer array
731 _, err := ArrayEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ArrayEach().(data, func(value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int, err error) {
732 // The inner element is another deeply nested array or the final value
733 })
734 // We accept any result as long as no panic
735 _ = err
736 })
737
738 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("ObjectEach_deep", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
739 defer func() {
740 if r := recover(); r != nil {
741 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach on deep nesting panicked: %v", r)
742 }
743 }()
744
745 // Build deeply nested object: {"a":{"a":{"a":...{"a":42}...}}}
746 depth := 64
747 prefix := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Repeatscip-go gomod github.com/golang/go/src go1.13 strings/Repeat().(`{"a":`, depth)
748 suffix := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Repeatscip-go gomod github.com/golang/go/src go1.13 strings/Repeat().("}", depth)
749 data := []byte(prefix + "42" + suffix)
750
751 err := ObjectEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ObjectEach().(data, func(key []byte, value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int) error {
752 return nil
753 })
754 _ = err
755 })
756 }
757
758 // Verifies: SYS-REQ-102
759 // MCDC SYS-REQ-102: mutation_input_has_unicode_keys=T, mutation_handles_unicode_keys_safely=T => TRUE
760 func TestMutationUnicodeKeysscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestMutationUnicodeKeys().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
761 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("Set_unicode_key", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
762 defer func() {
763 if r := recover(); r != nil {
764 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Set with unicode key panicked: %v", r)
765 }
766 }()
767
768 data := []byte(`{"caf\u00e9":"latte","normal":"value"}`)
769 // Try to set a value using a Unicode key
770 result, err := Setscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Set().(data, []byte(`"espresso"`), "normal")
771 if err != nil {
772 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Set returned error: %v", err)
773 }
774 // Verify the mutation was applied
775 val, err := GetStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetString().(result, "normal")
776 if err != nil {
777 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetString after Set returned error: %v", err)
778 }
779 if val != "espresso" {
780 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected 'espresso', got %q", val)
781 }
782 })
783
784 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("Delete_unicode_key", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
785 defer func() {
786 if r := recover(); r != nil {
787 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete with unicode key panicked: %v", r)
788 }
789 }()
790
791 // Test Delete on document with a raw UTF-8 key
792 data := []byte("{\"caf\xc3\xa9\":\"latte\",\"tea\":\"green\"}")
793 result := Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().(data, "tea")
794 // Verify tea was removed and the document is still parseable
795 _, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(result, "tea")
796 if !errorsscip-go gomod github.com/golang/go/src go1.13 errors/.Isscip-go gomod github.com/golang/go/src go1.13 errors/Is().(err, KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.) {
797 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected KeyPathNotFoundError after Delete, got: %v", err)
798 }
799 })
800 }
801
802 // Verifies: SYS-REQ-105
803 // MCDC SYS-REQ-105: getunsafestring_input_has_unicode_edge_cases=T, getunsafestring_handles_unicode_edges_safely=T => TRUE
804 func TestGetUnsafeStringUnicodeEdgeCasesscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetUnsafeStringUnicodeEdgeCases().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
805 cases := []struct {
806 name string
807 data string
808 key string
809 }{
810 {name: "BOM in value", data: `{"s":"\uFEFF"}`, key: "s"},
811 {name: "raw multi-byte UTF-8", data: "{\"s\":\"\xc3\xa9\"}", key: "s"},
812 {name: "emoji in value", data: "{\"s\":\"\xf0\x9f\x98\x80\"}", key: "s"},
813 {name: "ZWJ sequence", data: "{\"s\":\"\xe2\x80\x8d\"}", key: "s"},
814 }
815 for _, tc := range cases {
816 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
817 defer func() {
818 if r := recover(); r != nil {
819 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetUnsafeString panicked on %s: %v", tc.name, r)
820 }
821 }()
822
823 val, err := GetUnsafeStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetUnsafeString().([]byte(tc.data), tc.key)
824 // GetUnsafeString returns raw bytes -- we just verify no panic
825 _ = val
826 _ = err
827 })
828 }
829 }
830
831 // Verifies: SYS-REQ-109
832 // MCDC SYS-REQ-109: parseint_input_has_edge_case_number=T, parseint_handles_edge_numbers_safely=T => TRUE
833 func TestParseIntEdgeCaseNumbersscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestParseIntEdgeCaseNumbers().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
834 cases := []struct {
835 name string
836 input string
837 wantVal int64
838 wantErr bool
839 }{
840 {name: "negative zero", input: "-0", wantVal: 0},
841 {name: "positive zero", input: "0", wantVal: 0},
842 {name: "max int64", input: "9223372036854775807", wantVal: mathscip-go gomod github.com/golang/go/src go1.13 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.13 math/MaxInt64.},
843 {name: "min int64", input: "-9223372036854775808", wantVal: mathscip-go gomod github.com/golang/go/src go1.13 math/.MinInt64scip-go gomod github.com/golang/go/src go1.13 math/MinInt64.},
844 {name: "max+1 overflow", input: "9223372036854775808", wantErr: true},
845 {name: "min-1 overflow", input: "-9223372036854775809", wantErr: true},
846 {name: "100-digit number", input: stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Repeatscip-go gomod github.com/golang/go/src go1.13 strings/Repeat().("9", 100), wantErr: true},
847 {name: "single digit", input: "7", wantVal: 7},
848 {name: "negative single digit", input: "-3", wantVal: -3},
849 }
850 for _, tc := range cases {
851 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
852 defer func() {
853 if r := recover(); r != nil {
854 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseInt panicked: %v", r)
855 }
856 }()
857
858 val, err := ParseIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ParseInt().([]byte(tc.input))
859 if tc.wantErr {
860 if err == nil {
861 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Expected error for %q, got value %d", tc.input, val)
862 }
863 return
864 }
865 if err != nil {
866 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseInt(%q) returned error: %v", tc.input, err)
867 }
868 if val != tc.wantVal {
869 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ParseInt(%q) = %d, want %d", tc.input, val, tc.wantVal)
870 }
871 })
872 }
873 }