Skip to content

Commit 6f4c196

Browse files
committed
add more testcase
1 parent 8302a17 commit 6f4c196

File tree

1 file changed

+206
-7
lines changed

1 file changed

+206
-7
lines changed

misc_tests/jsoniter_object_test.go

Lines changed: 206 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,221 @@ func Test_unmarshal_into_existing_value(t *testing.T) {
152152
// for issue421
153153
func Test_unmarshal_anonymous_struct_invalid(t *testing.T) {
154154
should := require.New(t)
155-
t1 := struct {
155+
t0 := struct {
156156
Field1 string
157157
}{}
158158

159159
cfg := jsoniter.ConfigCompatibleWithStandardLibrary
160-
err := cfg.UnmarshalFromString(`{"Field1":`, &t1)
160+
err := cfg.UnmarshalFromString(`{"Field1":`, &t0)
161161
should.NotNil(err)
162-
should.NotContains(err.Error(), reflect.TypeOf(t1).String())
162+
should.NotContains(err.Error(), reflect.TypeOf(t0).String())
163163

164-
type TestObject struct {
164+
cfgCaseSensitive := jsoniter.Config{
165+
CaseSensitive: true,
166+
}.Froze()
167+
168+
type TestObject1 struct {
165169
Field1 struct {
166170
InnerField1 string
167171
}
168172
}
169-
t2 := TestObject{}
170-
err = cfg.UnmarshalFromString(`{"Field1":{"InnerField1"`, &t2)
173+
t1 := TestObject1{}
174+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field1":{"InnerField1"`, &t1)
175+
should.NotNil(err)
176+
should.NotContains(err.Error(), reflect.TypeOf(t1.Field1).String())
177+
should.Contains(err.Error(), reflect.TypeOf(t1).String())
178+
179+
type TestObject2 struct {
180+
Field1 int
181+
Field2 struct {
182+
InnerField1 string
183+
InnerField2 string
184+
}
185+
}
186+
t2 := TestObject2{}
187+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field2":{"InnerField2"`, &t2)
188+
should.NotNil(err)
189+
should.NotContains(err.Error(), reflect.TypeOf(t2.Field2).String())
190+
should.Contains(err.Error(), reflect.TypeOf(t2).String())
191+
192+
type TestObject3 struct {
193+
Field1 int
194+
Field2 int
195+
Field3 struct {
196+
InnerField1 string
197+
InnerField2 string
198+
InnerField3 string
199+
}
200+
}
201+
t3 := TestObject3{}
202+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field3":{"InnerField3"`, &t3)
203+
should.NotNil(err)
204+
should.NotContains(err.Error(), reflect.TypeOf(t3.Field3).String())
205+
should.Contains(err.Error(), reflect.TypeOf(t3).String())
206+
207+
type TestObject4 struct {
208+
Field1 int
209+
Field2 int
210+
Field3 int
211+
Field4 struct {
212+
InnerField1 string
213+
InnerField2 string
214+
InnerField3 string
215+
InnerField4 string
216+
}
217+
}
218+
t4 := TestObject4{}
219+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field4":{"InnerField4"`, &t4)
220+
should.NotNil(err)
221+
should.NotContains(err.Error(), reflect.TypeOf(t4.Field4).String())
222+
should.Contains(err.Error(), reflect.TypeOf(t4).String())
223+
224+
type TestObject5 struct {
225+
Field1 int
226+
Field2 int
227+
Field3 int
228+
Field4 int
229+
Field5 struct {
230+
InnerField1 string
231+
InnerField2 string
232+
InnerField3 string
233+
InnerField4 string
234+
InnerField5 string
235+
}
236+
}
237+
t5 := TestObject5{}
238+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field5":{"InnerField5"`, &t5)
239+
should.NotNil(err)
240+
should.NotContains(err.Error(), reflect.TypeOf(t5.Field5).String())
241+
should.Contains(err.Error(), reflect.TypeOf(t5).String())
242+
243+
type TestObject6 struct {
244+
Field1 int
245+
Field2 int
246+
Field3 int
247+
Field4 int
248+
Field5 int
249+
Field6 struct {
250+
InnerField1 string
251+
InnerField2 string
252+
InnerField3 string
253+
InnerField4 string
254+
InnerField5 string
255+
InnerField6 string
256+
}
257+
}
258+
t6 := TestObject6{}
259+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field6":{"InnerField6"`, &t6)
260+
should.NotNil(err)
261+
should.NotContains(err.Error(), reflect.TypeOf(t6.Field6).String())
262+
should.Contains(err.Error(), reflect.TypeOf(t6).String())
263+
264+
type TestObject7 struct {
265+
Field1 int
266+
Field2 int
267+
Field3 int
268+
Field4 int
269+
Field5 int
270+
Field6 int
271+
Field7 struct {
272+
InnerField1 string
273+
InnerField2 string
274+
InnerField3 string
275+
InnerField4 string
276+
InnerField5 string
277+
InnerField6 string
278+
InnerField7 string
279+
}
280+
}
281+
t7 := TestObject7{}
282+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field7":{"InnerField7"`, &t7)
283+
should.NotNil(err)
284+
should.NotContains(err.Error(), reflect.TypeOf(t7.Field7).String())
285+
should.Contains(err.Error(), reflect.TypeOf(t7).String())
286+
287+
type TestObject8 struct {
288+
Field1 int
289+
Field2 int
290+
Field3 int
291+
Field4 int
292+
Field5 int
293+
Field6 int
294+
Field7 int
295+
Field8 struct {
296+
InnerField1 string
297+
InnerField2 string
298+
InnerField3 string
299+
InnerField4 string
300+
InnerField5 string
301+
InnerField6 string
302+
InnerField7 string
303+
InnerField8 string
304+
}
305+
}
306+
t8 := TestObject8{}
307+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field8":{"InnerField8"`, &t8)
308+
should.NotNil(err)
309+
should.NotContains(err.Error(), reflect.TypeOf(t8.Field8).String())
310+
should.Contains(err.Error(), reflect.TypeOf(t8).String())
311+
312+
type TestObject9 struct {
313+
Field1 int
314+
Field2 int
315+
Field3 int
316+
Field4 int
317+
Field5 int
318+
Field6 int
319+
Field7 int
320+
Field8 int
321+
Field9 struct {
322+
InnerField1 string
323+
InnerField2 string
324+
InnerField3 string
325+
InnerField4 string
326+
InnerField5 string
327+
InnerField6 string
328+
InnerField7 string
329+
InnerField8 string
330+
InnerField9 string
331+
}
332+
}
333+
t9 := TestObject9{}
334+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field9":{"InnerField9"`, &t9)
335+
should.NotNil(err)
336+
should.NotContains(err.Error(), reflect.TypeOf(t9.Field9).String())
337+
should.Contains(err.Error(), reflect.TypeOf(t9).String())
338+
339+
type TestObject10 struct {
340+
Field1 int
341+
Field2 int
342+
Field3 int
343+
Field4 int
344+
Field5 int
345+
Field6 int
346+
Field7 int
347+
Field8 int
348+
Field9 int
349+
Field10 struct {
350+
InnerField1 string
351+
InnerField2 string
352+
InnerField3 string
353+
InnerField4 string
354+
InnerField5 string
355+
InnerField6 string
356+
InnerField7 string
357+
InnerField8 string
358+
InnerField9 string
359+
InnerField10 string
360+
}
361+
}
362+
t10 := TestObject10{}
363+
err = cfgCaseSensitive.UnmarshalFromString(`{"Field10":{"InnerField10"`, &t10)
364+
should.NotNil(err)
365+
should.NotContains(err.Error(), reflect.TypeOf(t10.Field10).String())
366+
should.Contains(err.Error(), reflect.TypeOf(t10).String())
367+
368+
err = cfg.UnmarshalFromString(`{"Field10":{"InnerField10"`, &t10)
171369
should.NotNil(err)
172-
should.NotContains(err.Error(), reflect.TypeOf(t2.Field1).String())
370+
should.NotContains(err.Error(), reflect.TypeOf(t10.Field10).String())
371+
should.Contains(err.Error(), reflect.TypeOf(t10).String())
173372
}

0 commit comments

Comments
 (0)