MCPcopy
hub / github.com/tidwall/sjson / TestDeleteIssue21

Function TestDeleteIssue21

sjson_test.go:159–241  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestDeleteIssue21(t *testing.T) {
160 json := `{"country_code_from":"NZ","country_code_to":"SA","date_created":"2018-09-13T02:56:11.25783Z","date_updated":"2018-09-14T03:15:16.67356Z","disabled":false,"last_edited_by":"Developers","id":"a3e...bc454","merchant_id":"f2b...b91abf","signed_date":"2018-02-01T00:00:00Z","start_date":"2018-03-01T00:00:00Z","url":"https://www.google.com"}`
161 res1 := gjson.Get(json, "date_updated")
162 var err error
163 json, err = Delete(json, "date_updated")
164 if err != nil {
165 t.Fatal(err)
166 }
167 res2 := gjson.Get(json, "date_updated")
168 res3 := gjson.Get(json, "date_created")
169 if !res1.Exists() || res2.Exists() || !res3.Exists() {
170 t.Fatal("bad news")
171 }
172
173 // We change the number of characters in this to make the section of the string before the section that we want to delete a certain length
174
175 //---------------------------
176 lenBeforeToDeleteIs307AsBytes := `{"1":"","0":"012345678901234567890123456789012345678901234567890123456789012345678901234567","to_delete":"0","2":""}`
177
178 expectedForLenBefore307AsBytes := `{"1":"","0":"012345678901234567890123456789012345678901234567890123456789012345678901234567","2":""}`
179 //---------------------------
180
181 //---------------------------
182 lenBeforeToDeleteIs308AsBytes := `{"1":"","0":"0123456789012345678901234567890123456789012345678901234567890123456789012345678","to_delete":"0","2":""}`
183
184 expectedForLenBefore308AsBytes := `{"1":"","0":"0123456789012345678901234567890123456789012345678901234567890123456789012345678","2":""}`
185 //---------------------------
186
187 //---------------------------
188 lenBeforeToDeleteIs309AsBytes := `{"1":"","0":"01234567890123456789012345678901234567890123456789012345678901234567890123456","to_delete":"0","2":""}`
189
190 expectedForLenBefore309AsBytes := `{"1":"","0":"01234567890123456789012345678901234567890123456789012345678901234567890123456","2":""}`
191 //---------------------------
192
193 var data = []struct {
194 desc string
195 input string
196 expected string
197 }{
198 {
199 desc: "len before \"to_delete\"... = 307",
200 input: lenBeforeToDeleteIs307AsBytes,
201 expected: expectedForLenBefore307AsBytes,
202 },
203 {
204 desc: "len before \"to_delete\"... = 308",
205 input: lenBeforeToDeleteIs308AsBytes,
206 expected: expectedForLenBefore308AsBytes,
207 },
208 {
209 desc: "len before \"to_delete\"... = 309",
210 input: lenBeforeToDeleteIs309AsBytes,
211 expected: expectedForLenBefore309AsBytes,
212 },
213 }
214
215 for i, d := range data {
216 result, err := Delete(d.input, "to_delete")

Callers

nothing calls this directly

Calls 3

DeleteFunction · 0.85
fmtErrorfFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…