Debian Codegraph @

mcdc_supplement_test.go

raw symbols SCIP
1 package jsonparserscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/
2
3 import (
4 "errorsscip-go gomod github.com/golang/go/src go1.13 errors/"
5 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
6 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
7 "testingscip-go gomod github.com/golang/go/src go1.13 testing/"
8 )
9
10 // Verifies: STK-REQ-001 [malformed]
11 // MCDC STK-REQ-001: N/A
12 // Verifies: STK-REQ-005 [malformed]
13 // MCDC STK-REQ-005: N/A
14 func TestInternalSearchHelperEdgesscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestInternalSearchHelperEdges().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
15 if got := findTokenStartscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/findTokenStart().(nil, ','); got != 0 {
16 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("findTokenStart(nil, ',') = %d, want 0", got)
17 }
18 if got := lastTokenscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/lastToken().(nil); got != -1 {
19 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("lastToken(nil) = %d, want -1", got)
20 }
21
22 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("findKeyStart", 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#) {
23 cases := []struct {
24 name string
25 data string
26 key string
27 wantFound bool
28 wantErr error
29 }{
30 {name: "whitespace only", data: " \n\t", key: "a", wantErr: KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.},
31 {name: "array root branch is tolerated", data: `[{"a":1}]`, key: "a", wantErr: KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.},
32 {name: "escaped key is decoded", data: `{"a\nb":1}`, key: "a\nb", wantFound: true},
33 {name: "malformed escaped key is rejected", data: `{"\uD800":1}`, key: "x", wantErr: KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.},
34 {name: "missing value after key", data: `{"a"`, key: "a", wantErr: KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.},
35 {name: "requested key has malformed escape", data: `{"a":1}`, key: `\uD800`, wantErr: KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.},
36 {name: "unterminated key string", data: `{"a`, key: "a", wantErr: KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.},
37 }
38
39 for _, tc := range cases {
40 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#) {
41 offset, err := findKeyStartscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/findKeyStart().([]byte(tc.data), tc.key)
42 if tc.wantErr != nil {
43 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, tc.wantErr) {
44 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("findKeyStart(%q, %q) error = %v, want %v", tc.data, tc.key, err, tc.wantErr)
45 }
46 if offset != -1 {
47 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("findKeyStart(%q, %q) offset = %d, want -1", tc.data, tc.key, offset)
48 }
49 return
50 }
51
52 if err != nil {
53 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("findKeyStart(%q, %q) returned error: %v", tc.data, tc.key, err)
54 }
55 if !tc.wantFound || offset < 0 {
56 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("findKeyStart(%q, %q) offset = %d, want found offset", tc.data, tc.key, offset)
57 }
58 })
59 }
60 })
61
62 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("searchKeys", 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#) {
63 cases := []struct {
64 name string
65 data string
66 keys []string
67 want bool
68 }{
69 {name: "missing value after key", data: `{"a"`, keys: []string{"a"}, want: false},
70 {name: "malformed escaped key", data: `{"\uD800":1}`, keys: []string{"x"}, want: false},
71 {name: "nested mismatch still finds later path", data: `{"x":{"b":1},"a":{"b":2}}`, keys: []string{"a", "b"}, want: true},
72 {name: "short array key rejected", data: `{"arr":[1]}`, keys: []string{"arr", "["}, want: false},
73 {name: "array key without opening bracket rejected", data: `{"arr":[1]}`, keys: []string{"arr", "1]"}, want: false},
74 {name: "array key without closing bracket rejected", data: `{"arr":[1]}`, keys: []string{"arr", "[1"}, want: false},
75 {name: "non numeric array index rejected", data: `{"arr":[1]}`, keys: []string{"arr", "[x]"}, want: false},
76 }
77
78 for _, tc := range cases {
79 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#) {
80 got := searchKeysscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/searchKeys().([]byte(tc.data), tc.keys...)
81 if tc.want && got < 0 {
82 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("searchKeys(%q, %v) = %d, want found offset", tc.data, tc.keys, got)
83 }
84 if !tc.want && got != -1 {
85 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("searchKeys(%q, %v) = %d, want -1", tc.data, tc.keys, got)
86 }
87 })
88 }
89 })
90 }
91
92 // Verifies: SYS-REQ-003 [boundary]
93 // MCDC SYS-REQ-003: N/A
94 // Verifies: SYS-REQ-004 [boundary]
95 // MCDC SYS-REQ-004: N/A
96 // Verifies: SYS-REQ-005 [boundary]
97 // MCDC SYS-REQ-005: N/A
98 func TestTypedGetterEdgeErrorsscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestTypedGetterEdgeErrors().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
99 if _, err := GetIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetInt().([]byte(`{"a":1}`), "missing"); !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.) {
100 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetInt missing path error = %v, want %v", err, KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.)
101 }
102 if _, err := GetFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetFloat().([]byte(`{"a":1.5}`), "missing"); !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.) {
103 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("GetFloat missing path error = %v, want %v", err, KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.)
104 }
105 if _, err := GetBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/GetBoolean().([]byte(`{"a":1}`), "a"); err == nil {
106 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("GetBoolean on a numeric token should fail")
107 }
108 }
109
110 // Verifies: SYS-REQ-008 [boundary]
111 // MCDC SYS-REQ-008: N/A
112 func TestEachKeySupplementalCoveragescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestEachKeySupplementalCoverage().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
113 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("supports more than stack sized path sets", 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#) {
114 var doc stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder#
115 var paths [][]string
116 doc.WriteBytescip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteByte().('{')
117 for i := 0; i < 129; i++ {
118 if i > 0 {
119 doc.WriteBytescip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteByte().(',')
120 }
121 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&doc, `"k%d":%d`, i, i)
122 paths = append(paths, []string{fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("k%d", i)})
123 }
124 doc.WriteBytescip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteByte().('}')
125
126 var count int
127 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(doc.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
128 if err != nil {
129 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey large path set callback error: %v", err)
130 }
131 count++
132 }, paths...)
133 if count != 129 {
134 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey large path set count = %d, want 129", count)
135 }
136 })
137
138 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("supports deeper than stack sized paths", 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#) {
139 var doc stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder#
140 var path []string
141 for i := 0; i < 129; i++ {
142 key := fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("k%d", i)
143 path = append(path, key)
144 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&doc, `{"%s":`, key)
145 }
146 doc.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(`1`)
147 for i := 0; i < 129; i++ {
148 doc.WriteBytescip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteByte().('}')
149 }
150
151 var got string
152 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(doc.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
153 if err != nil {
154 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey deep path callback error: %v", err)
155 }
156 got = string(value)
157 }, path)
158 if got != "1" {
159 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey deep path value = %q, want %q", got, "1")
160 }
161 })
162
163 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("supports more than stack sized indexed array requests", 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#) {
164 var doc stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder#
165 var paths [][]string
166 doc.WriteBytescip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteByte().('[')
167 for i := 0; i < 129; i++ {
168 if i > 0 {
169 doc.WriteBytescip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteByte().(',')
170 }
171 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&doc, `{"v":%d}`, i)
172 paths = append(paths, []string{fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("[%d]", i), "v"})
173 }
174 doc.WriteBytescip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteByte().(']')
175
176 var count int
177 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(doc.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
178 if err != nil {
179 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey indexed path callback error: %v", err)
180 }
181 count++
182 }, paths...)
183 if count != 129 {
184 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey indexed path count = %d, want 129", count)
185 }
186 })
187
188 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("skips unrelated arrays and unmatched objects", 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#) {
189 var values []string
190 ret := EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"skip":{"a":1},"arr":[1,2],"want":3}`), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
191 if err != nil {
192 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey skip callback error: %v", err)
193 }
194 values = append(values, string(value))
195 }, []string{"want"})
196 if ret < 0 {
197 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey skip case returned %d, want non-negative", ret)
198 }
199 if len(values) != 1 || values[0] != "3" {
200 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey skip case values = %#v, want [\"3\"]", values)
201 }
202 })
203
204 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("reports malformed escaped 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#) {
205 if got := EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"\uD800":1}`), func(int, []byte, ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, error) {}, []string{"x"}); got != -1 {
206 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey malformed escaped key = %d, want -1", got)
207 }
208 })
209
210 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("reports unterminated key and missing value", 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#) {
211 if got := EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"a`), func(int, []byte, ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, error) {}, []string{"a"}); got != -1 {
212 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey unterminated key = %d, want -1", got)
213 }
214 if got := EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"a"`), func(int, []byte, ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, error) {}, []string{"a"}); got != -1 {
215 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey missing value = %d, want -1", got)
216 }
217 })
218
219 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("reports malformed unmatched array", 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#) {
220 if got := EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"arr":[1,2}`), func(int, []byte, ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, error) {}, []string{"want"}); got != -1 {
221 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey malformed unmatched array = %d, want -1", got)
222 }
223 })
224
225 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("reports negative nesting through callback", 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#) {
226 var cbErr error
227 got := EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`][1]`), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
228 cbErr = err
229 }, []string{"[0]"})
230 if got != -1 {
231 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey negative nesting = %d, want -1", got)
232 }
233 if !errorsscip-go gomod github.com/golang/go/src go1.13 errors/.Isscip-go gomod github.com/golang/go/src go1.13 errors/Is().(cbErr, MalformedJsonErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedJsonError.) {
234 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey negative nesting callback error = %v, want %v", cbErr, MalformedJsonErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedJsonError.)
235 }
236 })
237 }
238
239 // Verifies: SYS-REQ-006 [malformed]
240 // MCDC SYS-REQ-006: N/A
241 func TestArrayEachSupplementalErrorsscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestArrayEachSupplementalErrors().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
242 noop := func([]byte, ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, int, error) {}
243
244 cases := []struct {
245 name string
246 data string
247 keys []string
248 wantErr error
249 }{
250 {name: "empty input", data: ``, wantErr: MalformedObjectErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedObjectError.},
251 {name: "missing path", data: `{"a":[1]}`, keys: []string{"missing"}, wantErr: KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.},
252 {name: "target is not an array", data: `{"a":1}`, keys: []string{"a"}, wantErr: MalformedArrayErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedArrayError.},
253 {name: "missing value after key", data: `{"a":`, keys: []string{"a"}, wantErr: MalformedJsonErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedJsonError.},
254 {name: "missing comma between array elements", data: `[1 2]`, wantErr: MalformedArrayErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedArrayError.},
255 {name: "trailing comma in array", data: `[1,`, wantErr: MalformedJsonErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedJsonError.},
256 {name: "unterminated array without closing bracket", data: `[1`, wantErr: MalformedArrayErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedArrayError.},
257 {name: "malformed array element", data: `[1, nope]`, wantErr: UnknownValueTypeErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/UnknownValueTypeError.},
258 }
259
260 for _, tc := range cases {
261 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#) {
262 _, err := ArrayEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ArrayEach().([]byte(tc.data), noop, tc.keys...)
263 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, tc.wantErr) {
264 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach(%q, %v) error = %v, want %v", tc.data, tc.keys, err, tc.wantErr)
265 }
266 })
267 }
268 }
269
270 // Verifies: SYS-REQ-007 [malformed]
271 // MCDC SYS-REQ-007: N/A
272 func TestObjectEachSupplementalErrorsscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestObjectEachSupplementalErrors().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
273 noop := func([]byte, []byte, ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, int) error { return nil }
274
275 cases := []struct {
276 name string
277 data string
278 wantErr error
279 }{
280 {name: "whitespace only", data: ` `, wantErr: MalformedObjectErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedObjectError.},
281 {name: "unterminated object", data: `{`, wantErr: MalformedJsonErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedJsonError.},
282 {name: "invalid escaped key", data: `{"\uD800":1}`, wantErr: MalformedStringEscapeErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedStringEscapeError.},
283 {name: "missing value after key", data: `{"a"`, wantErr: MalformedJsonErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedJsonError.},
284 {name: "malformed value token", data: `{"a":u}`, wantErr: UnknownValueTypeErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/UnknownValueTypeError.},
285 {name: "missing closing brace after value", data: `{"a":1 `, wantErr: MalformedArrayErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedArrayError.},
286 }
287
288 for _, tc := range cases {
289 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#) {
290 err := ObjectEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ObjectEach().([]byte(tc.data), noop)
291 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, tc.wantErr) {
292 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach(%q) error = %v, want %v", tc.data, err, tc.wantErr)
293 }
294 })
295 }
296
297 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("missing key path", 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#) {
298 err := ObjectEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ObjectEach().([]byte(`{"a":1}`), noop, "missing")
299 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.) {
300 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach missing path error = %v, want %v", err, KeyPathNotFoundErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/KeyPathNotFoundError.)
301 }
302 })
303
304 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("trailing comma without closing brace", 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#) {
305 err := ObjectEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ObjectEach().([]byte(`{"a":1, `), noop)
306 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, MalformedArrayErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedArrayError.) {
307 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach trailing comma error = %v, want %v", err, MalformedArrayErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedArrayError.)
308 }
309 })
310 }
311
312 // Verifies: SYS-REQ-035 [boundary]
313 // MCDC SYS-REQ-035: delete_path_is_provided=T, delete_input_is_unusable_for_requested_path=T, delete_returns_original_input_on_unusable_input=T, delete_completes_without_panic=T => TRUE
314 func TestDeleteSupplementalEdgeCasesscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestDeleteSupplementalEdgeCases().(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 cases := []struct {
316 name string
317 data string
318 keys []string
319 want string
320 }{
321 {name: "delete last object field", data: `{"a":1,"b":2}`, keys: []string{"b"}, want: `{"a":1}`},
322 {name: "delete first object field with space comma", data: `{"a":1 ,"b":2}`, keys: []string{"a"}, want: `{"b":2}`},
323 {name: "delete first array element", data: `[1,2]`, keys: []string{"[0]"}, want: `[2]`},
324 {name: "delete last array element", data: `[1,2]`, keys: []string{"[1]"}, want: `[1]`},
325 {name: "malformed input is returned unchanged", data: `{"a":`, keys: []string{"a"}, want: `{"a":`},
326 }
327
328 for _, tc := range cases {
329 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#) {
330 if got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(tc.data), tc.keys...)); got != tc.want {
331 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete(%q, %v) = %q, want %q", tc.data, tc.keys, got, tc.want)
332 }
333 })
334 }
335 }
336
337 // Verifies: SYS-REQ-009 [boundary]
338 // MCDC SYS-REQ-009: N/A
339 func TestSetSupplementalArrayInsertionCoveragescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestSetSupplementalArrayInsertionCoverage().(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().("append into existing top level array path", 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 // When setting an index beyond the current array length for a
342 // primitive (non-object) array, the code overwrites rather than
343 // appends because createInsertComponent with object=true wraps
344 // the value. This is the actual parser behavior.
345 got, err := Setscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Set().([]byte(`{"top":[1]}`), []byte(`2`), "top", "[1]")
346 if err != nil {
347 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Set array append returned error: %v", err)
348 }
349 if string(got) != `{"top":[2]}` {
350 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Set array append result = %s, want %s", string(got), `{"top":[2]}`)
351 }
352 })
353
354 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("append object into nested existing array", 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#) {
355 got, err := Setscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Set().([]byte(`{"top":[{"middle":[{"present":true}]}]}`), []byte(`{"bottom":"value"}`), "top", "[0]", "middle", "[1]")
356 if err != nil {
357 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Set nested array append returned error: %v", err)
358 }
359 if string(got) != `{"top":[{"middle":[{"present":true},{"bottom":"value"}]}]}` {
360 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Set nested array append result = %s", string(got))
361 }
362 })
363 }
364
365 // Verifies: SYS-REQ-014 [malformed]
366 // MCDC SYS-REQ-014: N/A
367 func TestParseStringAndEscapeSupplementalCoveragescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestParseStringAndEscapeSupplementalCoverage().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
368 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("decodeSingleUnicodeEscape rejects bad hex in each leading position", 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#) {
369 inputs := []string{`\ux234`, `\u1x34`, `\u12x4`}
370 for _, in := range inputs {
371 if _, ok := decodeSingleUnicodeEscapescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/decodeSingleUnicodeEscape().([]byte(in)); ok {
372 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("decodeSingleUnicodeEscape(%q) unexpectedly succeeded", in)
373 }
374 }
375 })
376
377 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("unescapeToUTF8 rejects non backslash prefix", 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#) {
378 if inLen, outLen := unescapeToUTF8scip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/unescapeToUTF8().([]byte("x1"), make([]byte, 8)); inLen != -1 || outLen != -1 {
379 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("unescapeToUTF8(non-escape) = (%d, %d), want (-1, -1)", inLen, outLen)
380 }
381 })
382 }
383
384 // Verifies: SYS-REQ-014 [fuzz]
385 // MCDC SYS-REQ-014: N/A
386 func TestFuzzParseStringHarnessCoveragescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestFuzzParseStringHarnessCoverage().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
387 if got := FuzzParseStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzParseString().([]byte(`abc`)); got != 1 {
388 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzParseString success path = %d, want 1", got)
389 }
390 if got := FuzzParseStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzParseString().([]byte(``)); got != 0 {
391 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzParseString empty string path = %d, want 0", got)
392 }
393 if got := FuzzParseStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzParseString().([]byte(`\uD800`)); got != 0 {
394 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzParseString malformed escape path = %d, want 0", got)
395 }
396 }
397
398 // Verifies: STK-REQ-001 [malformed]
399 // MCDC STK-REQ-001: N/A
400 func TestGetTypeMalformedCompositeTokensscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestGetTypeMalformedCompositeTokens().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
401 cases := []struct {
402 name string
403 data string
404 wantErr error
405 }{
406 {name: "unterminated string token", data: `"unterminated`, wantErr: MalformedStringErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedStringError.},
407 {name: "unterminated array token", data: `[1,2`, wantErr: MalformedArrayErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedArrayError.},
408 {name: "unterminated object token", data: `{"a":1`, wantErr: MalformedObjectErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/MalformedObjectError.},
409 }
410
411 for _, tc := range cases {
412 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#) {
413 _, _, _, err := getTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/getType().([]byte(tc.data), 0)
414 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, tc.wantErr) {
415 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("getType(%q) error = %v, want %v", tc.data, err, tc.wantErr)
416 }
417 })
418 }
419 }
420
421 // Verifies: SYS-REQ-002 [fuzz]
422 // MCDC SYS-REQ-002: N/A
423 // Verifies: SYS-REQ-003 [fuzz]
424 // MCDC SYS-REQ-003: N/A
425 // Verifies: SYS-REQ-004 [fuzz]
426 // MCDC SYS-REQ-004: N/A
427 // Verifies: SYS-REQ-005 [fuzz]
428 // MCDC SYS-REQ-005: N/A
429 // Verifies: SYS-REQ-011 [fuzz]
430 // MCDC SYS-REQ-011: N/A
431 // Verifies: SYS-REQ-012 [fuzz]
432 // MCDC SYS-REQ-012: N/A
433 // Verifies: SYS-REQ-015 [fuzz]
434 // MCDC SYS-REQ-015: N/A
435 func TestAdditionalFuzzHarnessCoveragescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestAdditionalFuzzHarnessCoverage().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
436 if got := FuzzParseIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzParseInt().([]byte(`12`)); got != 1 {
437 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzParseInt success path = %d, want 1", got)
438 }
439 if got := FuzzParseIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzParseInt().([]byte(`1.2`)); got != 0 {
440 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzParseInt failure path = %d, want 0", got)
441 }
442
443 if got := FuzzParseBoolscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzParseBool().([]byte(`true`)); got != 1 {
444 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzParseBool success path = %d, want 1", got)
445 }
446 if got := FuzzParseBoolscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzParseBool().([]byte(`truthy`)); got != 0 {
447 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzParseBool failure path = %d, want 0", got)
448 }
449
450 if got := FuzzGetStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetString().([]byte(`{"test":"value"}`)); got != 1 {
451 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetString success path = %d, want 1", got)
452 }
453 if got := FuzzGetStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetString().([]byte(`{"other":"value"}`)); got != 0 {
454 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetString failure path = %d, want 0", got)
455 }
456
457 if got := FuzzGetFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetFloat().([]byte(`{"test":1.5}`)); got != 1 {
458 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetFloat success path = %d, want 1", got)
459 }
460 if got := FuzzGetFloatscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetFloat().([]byte(`{"test":"value"}`)); got != 0 {
461 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetFloat failure path = %d, want 0", got)
462 }
463
464 if got := FuzzGetIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetInt().([]byte(`{"test":2}`)); got != 1 {
465 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetInt success path = %d, want 1", got)
466 }
467 if got := FuzzGetIntscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetInt().([]byte(`{"test":2.5}`)); got != 0 {
468 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetInt failure path = %d, want 0", got)
469 }
470
471 if got := FuzzGetBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetBoolean().([]byte(`{"test":true}`)); got != 1 {
472 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetBoolean success path = %d, want 1", got)
473 }
474 if got := FuzzGetBooleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetBoolean().([]byte(`{"test":1}`)); got != 0 {
475 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetBoolean failure path = %d, want 0", got)
476 }
477
478 if got := FuzzGetUnsafeStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetUnsafeString().([]byte(`{"test":"value"}`)); got != 1 {
479 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetUnsafeString success path = %d, want 1", got)
480 }
481 if got := FuzzGetUnsafeStringscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/FuzzGetUnsafeString().([]byte(`{"other":"value"}`)); got != 0 {
482 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("FuzzGetUnsafeString failure path = %d, want 0", got)
483 }
484 }
485
486 // =============================================================================
487 // Code MC/DC gap closure tests
488 // =============================================================================
489
490 // Verifies: SYS-REQ-035 [boundary]
491 // Code MC/DC gap: parser.go:810 Delete
492 // Drive nextToken(remainedValue) > -1 to TRUE so all three terms in the
493 // conjunction are evaluated. This requires deleting the last field in an
494 // object where a trailing comma precedes the closing brace.
495 func TestCodeMCDC_DeleteTrailingCommaRemovalscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_DeleteTrailingCommaRemoval().(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 // Delete the last key "b" from {"a":1,"b":2}.
497 // After removing "b":2, remainedValue starts with "}", nextToken > -1,
498 // remainedValue[nextToken] == '}', and data[prevTok] == ','.
499 // This exercises the TRUE branch of the conjunction at line 810.
500 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`{"a":1,"b":2}`), "b"))
501 if got != `{"a":1}` {
502 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete trailing comma removal = %q, want %q", got, `{"a":1}`)
503 }
504
505 // Also test deleting a middle key so the conjunction is FALSE
506 // (nextToken > -1 is TRUE but remainedValue[nextToken] != '}').
507 got2 := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`{"a":1,"b":2,"c":3}`), "b"))
508 if got2 != `{"a":1,"c":3}` {
509 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete middle key = %q, want %q", got2, `{"a":1,"c":3}`)
510 }
511 }
512
513 // Verifies: SYS-REQ-001 [boundary]
514 // Code MC/DC gap: parser.go:325 searchKeys
515 // Drive keyLen >= 3 so the second and third terms of the disjunction
516 // (keys[level][0] != '[' and keys[level][keyLen-1] != ']') are evaluated.
517 // A key like "abc" has keyLen=3, starts with 'a' != '[', so the second
518 // term is TRUE and short-circuits. A key like "[ab" has keyLen=3, starts
519 // with '[', but does not end with ']', so the third term is TRUE.
520 func TestCodeMCDC_SearchKeysArrayKeyValidationscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_SearchKeysArrayKeyValidation().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
521 // Key "abc" has keyLen=3, keys[level][0]='a' != '[' => TRUE (second term)
522 _, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`[1,2,3]`), "abc")
523 if err == nil {
524 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Get with non-bracket array key should return error")
525 }
526
527 // Key "[ab" has keyLen=3, starts with '[', ends with 'b' != ']' => third term TRUE
528 _, _, _, err = Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`[1,2,3]`), "[ab")
529 if err == nil {
530 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Get with malformed bracket key should return error")
531 }
532
533 // Key "[0]" has keyLen=3, starts with '[', ends with ']' => all three terms FALSE
534 // This is the valid path.
535 val, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`[10,20,30]`), "[0]")
536 if err != nil {
537 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get with valid array index error: %v", err)
538 }
539 if string(val) != "10" {
540 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get [0] = %q, want %q", string(val), "10")
541 }
542 }
543
544 // Verifies: SYS-REQ-001 [boundary]
545 // Code MC/DC gap: parser.go:287 searchKeys keyLevel == level-1
546 // Drive keyLevel == level-1 to TRUE. This happens during normal nested key
547 // lookup where the first key matches and we descend into a nested object.
548 func TestCodeMCDC_SearchKeysKeyLevelMatchscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_SearchKeysKeyLevelMatch().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
549 // Two-level path: first key matches at level 1 (keyLevel becomes 1),
550 // then at level 2, keyLevel == level-1 == 1 is TRUE for the second key.
551 data := []byte(`{"a":{"b":42}}`)
552 val, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().(data, "a", "b")
553 if err != nil {
554 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get nested path error: %v", err)
555 }
556 if string(val) != "42" {
557 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get nested path = %q, want %q", string(val), "42")
558 }
559 }
560
561 // Verifies: SYS-REQ-008 [boundary]
562 // Code MC/DC gap: parser.go:491 EachKey data[i] == '{'
563 // Drive data[i] == '{' to FALSE after an unmatched key. This happens when
564 // the value after an unmatched key is NOT an object (e.g., a number, string,
565 // array, or boolean).
566 func TestCodeMCDC_EachKeyNonObjectUnmatchedValuescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_EachKeyNonObjectUnmatchedValue().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
567 // The key "skip" has a number value (not '{'), so data[i] == '{' is FALSE.
568 var found bool
569 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"skip":123,"want":"yes"}`), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
570 if string(value) == "yes" {
571 found = true
572 }
573 }, []string{"want"})
574 if !found {
575 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("EachKey should find 'want' after skipping non-object value")
576 }
577
578 // Also test with array value (not '{')
579 var found2 bool
580 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"skip":[1,2],"want":"yes"}`), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
581 if string(value) == "yes" {
582 found2 = true
583 }
584 }, []string{"want"})
585 if !found2 {
586 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("EachKey should find 'want' after skipping array value")
587 }
588 }
589
590 // Verifies: SYS-REQ-001 [boundary]
591 // Code MC/DC gap: parser.go:945 getType end == -1
592 // Drive end == -1 to FALSE. tokenEnd returns -1 only when the data is
593 // empty. For a non-empty numeric/boolean/null value with a proper delimiter,
594 // end > 0. This is exercised by normal Get on a properly terminated value.
595 func TestCodeMCDC_GetTypeTokenEndNotNegativescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_GetTypeTokenEndNotNegative().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
596 // A normal number with a comma delimiter makes tokenEnd return a positive value.
597 val, dt, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`{"a":42,"b":1}`), "a")
598 if err != nil {
599 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get error: %v", err)
600 }
601 if dt != Numberscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Number. {
602 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get type = %v, want Number", dt)
603 }
604 if string(val) != "42" {
605 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get value = %q, want %q", string(val), "42")
606 }
607
608 // A boolean with closing brace delimiter
609 val2, dt2, _, err2 := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`{"a":true}`), "a")
610 if err2 != nil {
611 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get boolean error: %v", err2)
612 }
613 if dt2 != Booleanscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Boolean. {
614 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get boolean type = %v, want Boolean", dt2)
615 }
616 if string(val2) != "true" {
617 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get boolean value = %q, want %q", string(val2), "true")
618 }
619 }
620
621 // Verifies: SYS-REQ-006 [boundary]
622 // Code MC/DC gap: parser.go:1073 ArrayEach o == 0 (FALSE branch)
623 // and parser.go:1077 ArrayEach t != NotExist (TRUE branch)
624 // Normal ArrayEach iteration has o > 0 and t != NotExist.
625 func TestCodeMCDC_ArrayEachNormalIterationscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_ArrayEachNormalIteration().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
626 var values []string
627 _, err := ArrayEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ArrayEach().([]byte(`[1,2,3]`), func(value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int, err error) {
628 values = append(values, string(value))
629 })
630 if err != nil {
631 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach error: %v", err)
632 }
633 if len(values) != 3 {
634 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach count = %d, want 3", len(values))
635 }
636 if values[0] != "1" || values[1] != "2" || values[2] != "3" {
637 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach values = %v, want [1 2 3]", values)
638 }
639 }
640
641 // Verifies: SYS-REQ-006 [boundary]
642 // Code MC/DC gap: parser.go:1081 ArrayEach e != nil (FALSE branch)
643 // Normal iteration where Get returns no error has e == nil.
644 func TestCodeMCDC_ArrayEachNoErrorscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_ArrayEachNoError().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
645 var gotErr bool
646 _, err := ArrayEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ArrayEach().([]byte(`["a","b"]`), func(value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int, err error) {
647 if err != nil {
648 gotErr = true
649 }
650 })
651 if err != nil {
652 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ArrayEach error: %v", err)
653 }
654 if gotErr {
655 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("ArrayEach callback should not receive error for valid input")
656 }
657 }
658
659 // Verifies: SYS-REQ-001 [boundary]
660 // Code MC/DC gap: parser.go:61 findKeyStart ln > 0 with data[i] == '['
661 // Drive the branch where data starts with '[' (array root).
662 func TestCodeMCDC_FindKeyStartArrayRootscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_FindKeyStartArrayRoot().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
663 // When data starts with '[', findKeyStart enters the array branch.
664 // This drives data[i] == '[' to TRUE.
665 offset, err := findKeyStartscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/findKeyStart().([]byte(`[{"a":1}]`), "a")
666 // The function will try to find key "a" but since it's inside an array,
667 // we expect it to either find the key or return not-found.
668 _ = offset
669 _ = err
670 }
671
672 // Verifies: SYS-REQ-035 [boundary]
673 // Code MC/DC gap: parser.go:800 Delete data[endOffset+tokEnd] == ']'
674 // Drive data[endOffset+tokEnd] == ']' to FALSE in the array-element
675 // deletion branch. This happens when deleting the first element of an array
676 // where the next delimiter is a comma, not ']'.
677 func TestCodeMCDC_DeleteArrayFirstElementscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_DeleteArrayFirstElement().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
678 // Delete [0] from [1,2,3] -- the delimiter after "1" is ',' not ']'
679 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`[1,2,3]`), "[0]"))
680 if got != `[2,3]` {
681 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete array first element = %q, want %q", got, `[2,3]`)
682 }
683
684 // Delete [1] from [1,2,3] -- the delimiter after "2" is ',' not ']'
685 got2 := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`[1,2,3]`), "[1]"))
686 if got2 != `[1,3]` {
687 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete array middle element = %q, want %q", got2, `[1,3]`)
688 }
689 }
690
691 // Verifies: SYS-REQ-014 [boundary]
692 // Code MC/DC gap: escape.go:149 Unescape for len(in) > 0
693 // Drive the loop body. A string with an escape sequence enters the loop.
694 func TestCodeMCDC_UnescapeLoopEntryscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_UnescapeLoopEntry().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
695 // A string with a backslash-n escape forces the Unescape loop
696 result, err := Unescapescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Unescape().([]byte(`hello\nworld`), make([]byte, 32))
697 if err != nil {
698 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Unescape error: %v", err)
699 }
700 if string(result) != "hello\nworld" {
701 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Unescape = %q, want %q", string(result), "hello\nworld")
702 }
703
704 // Also test with multiple escapes to exercise loop re-entry
705 result2, err2 := Unescapescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Unescape().([]byte(`a\tb\nc`), make([]byte, 32))
706 if err2 != nil {
707 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Unescape multiple escapes error: %v", err2)
708 }
709 if string(result2) != "a\tb\nc" {
710 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Unescape multiple = %q, want %q", string(result2), "a\tb\nc")
711 }
712 }
713
714 // Verifies: SYS-REQ-007 [boundary]
715 // Code MC/DC gap: parser.go:1138 ObjectEach offset < len(data)
716 // Normal ObjectEach iteration has offset < len(data) TRUE.
717 func TestCodeMCDC_ObjectEachLoopEntryscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_ObjectEachLoopEntry().(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 var keys []string
719 err := ObjectEachscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ObjectEach().([]byte(`{"a":1,"b":2}`), func(key []byte, value []byte, dataType ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, offset int) error {
720 keys = append(keys, string(key))
721 return nil
722 })
723 if err != nil {
724 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach error: %v", err)
725 }
726 if len(keys) != 2 {
727 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("ObjectEach key count = %d, want 2", len(keys))
728 }
729 }
730
731 // Verifies: SYS-REQ-035 [boundary]
732 // Code MC/DC gap: parser.go:778 Delete space-comma handling
733 // Drive the case where data[endOffset+tokEnd] == ' ' and
734 // len(data) > endOffset+tokEnd+1 but data[endOffset+tokEnd+1] != ','
735 // (the third condition is FALSE).
736 func TestCodeMCDC_DeleteSpaceBeforeCommascip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_DeleteSpaceBeforeComma().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
737 // Delete "a" from {"a":1 ,"b":2} where there's a space before the comma.
738 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`{"a":1 ,"b":2}`), "a"))
739 if got != `{"b":2}` {
740 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete space-comma = %q, want %q", got, `{"b":2}`)
741 }
742
743 // Delete "a" from {"a":1 } where space is followed by '}' not ','
744 // This makes data[endOffset+tokEnd+1] == '}' != ','
745 got2 := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`{"a":1 }`), "a"))
746 // With only one key and space before closing brace, the space-comma
747 // branch is entered but the comma check is FALSE, so it falls through.
748 _ = got2 // Accept whatever the parser produces as long as no panic
749 }
750
751 // Verifies: SYS-REQ-008 [boundary]
752 // Code MC/DC gap: parser.go:497 EachKey i < ln
753 // Normal EachKey iteration has i < ln TRUE.
754 func TestCodeMCDC_EachKeyLoopBoundscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_EachKeyLoopBound().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
755 var count int
756 EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"a":1,"b":2}`), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) {
757 count++
758 }, []string{"a"}, []string{"b"})
759 if count != 2 {
760 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("EachKey loop count = %d, want 2", count)
761 }
762 }
763
764 // =============================================================================
765 // Code MC/DC gap closure tests — round 2 (100% target)
766 // =============================================================================
767
768 // Verifies: SYS-REQ-035 [boundary]
769 // Code MC/DC gap: parser.go:813 Delete conjunction
770 // Full MC/DC coverage for: remainedTok > -1 && remainedValue[remainedTok] == '}' && data[prevTok] == ','
771 // MC/DC requires 4 witness rows:
772 // (T,T,T) => T : trailing-comma malformed JSON
773 // (F,_,_) => F : malformed whitespace-only remainder
774 // (T,F,_) => F : delete middle key (remainder starts with quote)
775 // (T,T,F) => F : delete single key (prevTok is '{')
776 func TestCodeMCDC_DeleteConjunctionFullMCDCscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_DeleteConjunctionFullMCDC().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
777 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("TTT: trailing comma malformed JSON", 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#) {
778 // {"a":1,"b":2,} — after deleting "b", the comma after "2" advances
779 // endOffset past it, so remainedValue = "}". prevTok is the comma
780 // before "b" key. All three conditions TRUE => trailing comma removed.
781 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`{"a":1,"b":2,}`), "b"))
782 if got != `{"a":1}` {
783 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete TTT = %q, want %q", got, `{"a":1}`)
784 }
785 })
786
787 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("F: malformed whitespace-only remainder", 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#) {
788 // {"a":1, — after deleting "a", remainder is all whitespace.
789 // nextToken returns -1, so remainedTok > -1 is FALSE.
790 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`{"a":1, `), "a"))
791 _ = got // Accept any result for malformed input; no panic is the requirement.
792 })
793
794 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("TF: delete middle 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#) {
795 // {"a":1,"b":2,"c":3} — after deleting "b", remainder starts
796 // with "c":3}, nextToken finds '"' not '}'. Second condition FALSE.
797 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`{"a":1,"b":2,"c":3}`), "b"))
798 if got != `{"a":1,"c":3}` {
799 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete TF = %q, want %q", got, `{"a":1,"c":3}`)
800 }
801 })
802
803 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("TTF: delete single 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#) {
804 // {"a":1} — after deleting "a", remainder = "}",
805 // remainedValue[0]=='}'=TRUE, but prevTok is '{' not ','. Third FALSE.
806 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`{"a":1}`), "a"))
807 if got != `{}` {
808 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete TTF = %q, want %q", got, `{}`)
809 }
810 })
811 }
812
813 // Verifies: SYS-REQ-001 [boundary]
814 // Code MC/DC gap: parser.go:289 searchKeys keyLevel == level-1
815 // Drive keyLevel != level-1 (FALSE branch).
816 // Use duplicate keys so keyLevel advances past the expected level.
817 func TestCodeMCDC_SearchKeysKeyLevelMismatchscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_SearchKeysKeyLevelMismatch().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
818 // In {"a":1,"a":{"b":2}}, searching for ["a","b"]:
819 // First "a" at level 1 matches keys[0], keyLevel becomes 1.
820 // Second "a" at level 1: equalStr matches keys[0]="a", but
821 // keyLevel(1) != level-1(0) — FALSE branch exercised.
822 // Then we descend into {"b":2} and find "b".
823 val, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`{"a":1,"a":{"b":2}}`), "a", "b")
824 if err != nil {
825 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get duplicate-key path error: %v", err)
826 }
827 if string(val) != "2" {
828 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get duplicate-key path = %q, want %q", string(val), "2")
829 }
830 }
831
832 // Verifies: SYS-REQ-001 [boundary]
833 // Code MC/DC gap: parser.go:327 searchKeys keys[level][0] != '['
834 // Drive keys[level][0] != '[' to TRUE independently.
835 // Use a key with keyLen >= 3 that does NOT start with '['.
836 func TestCodeMCDC_SearchKeysArrayKeyNotBracketscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_SearchKeysArrayKeyNotBracket().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
837 // Key "abc" has keyLen=3 (>= 3 so first term is FALSE),
838 // and keys[level][0]='a' != '[' (second term is TRUE).
839 _, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`[1,2,3]`), "abc")
840 if err == nil {
841 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Get with non-bracket key on array should fail")
842 }
843
844 // Key "a[0" has keyLen=3 (>= 3), keys[level][0]='a' != '[' (TRUE).
845 _, _, _, err = Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`[1,2,3]`), "a[0")
846 if err == nil {
847 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Get with malformed key should fail")
848 }
849
850 // Drive keys[level][0] == '[' (FALSE) with keyLen >= 3
851 // AND keys[level][keyLen-1] != ']' (TRUE): key "[ab"
852 _, _, _, err = Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`[1,2,3]`), "[ab")
853 if err == nil {
854 t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Get with bracket key without closing bracket should fail")
855 }
856
857 // All three terms FALSE: valid index "[0]"
858 val, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`[10,20,30]`), "[1]")
859 if err != nil {
860 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get valid array index error: %v", err)
861 }
862 if string(val) != "20" {
863 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Get [1] = %q, want %q", string(val), "20")
864 }
865 }
866
867 // Verifies: SYS-REQ-035 [boundary]
868 // Code MC/DC gap: parser.go:801 Delete data[endOffset+tokEnd] == ']' && data[tokStart] == ','
869 // Full MC/DC for the array-branch elif at line 801.
870 // Need (T,T) => T and (F,?) => F:
871 // (T,T): delete last element from [1,2] — delimiter is ']' and preceding comma exists.
872 // (F): delete from malformed [1} — delimiter is '}' not ']'.
873 func TestCodeMCDC_DeleteArrayElifMCDCscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestCodeMCDC_DeleteArrayElifMCDC().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
874 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("TT: delete last array element", 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#) {
875 // Delete [1] from [1,2]: delimiter after "2" is ']', comma before "2" exists.
876 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`[1,2]`), "[1]"))
877 if got != `[1]` {
878 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete [1] from [1,2] = %q, want %q", got, `[1]`)
879 }
880 })
881
882 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("F: malformed array delimiter", 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#) {
883 // Delete [0] from malformed [1}: delimiter after "1" is '}' not ']'.
884 // data[endOffset+tokEnd] == ']' is FALSE.
885 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`[1}`), "[0]"))
886 if got != `[}` {
887 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete [0] from [1} = %q, want %q", got, `[}`)
888 }
889 })
890
891 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().("F: multi-element first", 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#) {
892 // Delete [0] from [1,2,3]: delimiter after "1" is ',' not ']'.
893 // First if catches comma, elif not reached.
894 got := string(Deletescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Delete().([]byte(`[1,2,3]`), "[0]"))
895 if got != `[2,3]` {
896 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Delete [0] from [1,2,3] = %q, want %q", got, `[2,3]`)
897 }
898 })
899 }