-
Notifications
You must be signed in to change notification settings - Fork 14
/
objFixtures_test.go
1295 lines (1266 loc) · 55.8 KB
/
objFixtures_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package obj
import (
"fmt"
"reflect"
"testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/polydawn/refmt/obj/atlas"
. "github.com/polydawn/refmt/tok"
"github.com/polydawn/refmt/tok/fixtures"
)
var skipMe = fmt.Errorf("skipme")
type marshalResults struct {
title string
// Yields a value to hand to the marshaller.
// A func returning a wildcard is used rather than just an `interface{}`, because `&target` conveys very different type information.
valueFn func() interface{}
expectErr error
errString string
}
type unmarshalResults struct {
title string
// Yields the handle we should give to the unmarshaller to fill.
// Like `valueFn`, the indirection here is to help
slotFn func() interface{}
// Yields the value we will compare the unmarshal result against.
// A func returning a wildcard is used rather than just an `interface{}`, because `&target` conveys very different type information.
valueFn func() interface{}
expectErr error
errString string
}
type tObjStr struct {
X string
}
type tObjStr2 struct {
X string
Y string
}
type tObjK struct {
K []tObjK2
}
type tObjK2 struct {
K2 int
}
type tDefStr string
type tDefInt int
type tDefBytes []byte
type tObjStrp struct {
X *string
}
type tObjPtrObjStrp struct {
P *tObjStrp
}
type tObjPtrObjStrp2 struct {
P1 *tObjStrp
P2 *tObjStrp
}
type tObjMap struct {
X map[string]interface{}
}
type tObjPtrObjMap struct {
P *tObjMap
}
var objFixtures = []struct {
title string
// The serial sequence of tokens the value is isomorphic to.
sequence fixtures.Sequence
// The suite of mappings to use.
atlas atlas.Atlas
// The results to expect from various marshalling starting points.
// This is a slice because we occasionally have several different kinds of objects
// which we expect will converge on the same token fixture given the same atlas.
marshalResults []marshalResults
// The results to expect from various unmarshal situations.
// This is a slice because unmarshal may have different outcomes (usually,
// erroring vs not) depending on the type of value it was given to populate.
unmarshalResults []unmarshalResults
}{
{title: "string literal",
sequence: fixtures.SequenceMap["flat string"],
marshalResults: []marshalResults{
{title: "from string literal",
valueFn: func() interface{} { str := "value"; return str }},
{title: "from *string",
valueFn: func() interface{} { str := "value"; return &str }},
{title: "from **string",
valueFn: func() interface{} { str := "value"; strp := &str; return &strp }},
{title: "from string in iface slot",
valueFn: func() interface{} { var iface interface{}; iface = "value"; return iface }},
{title: "from string in *iface slot",
valueFn: func() interface{} { var iface interface{}; iface = "value"; return &iface }},
{title: "from *string in iface slot",
valueFn: func() interface{} { str := "value"; var iface interface{}; iface = &str; return iface }},
{title: "from *string in *iface slot",
valueFn: func() interface{} { str := "value"; var iface interface{}; iface = &str; return &iface }},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
valueFn: func() interface{} { str := "value"; return str }},
{title: "into **string",
slotFn: func() interface{} { var strp *string; return &strp },
valueFn: func() interface{} { str := "value"; return &str }},
{title: "into ***string",
slotFn: func() interface{} { var strpp **string; return &strpp },
valueFn: func() interface{} { str := "value"; strp := &str; return &strp }},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { str := "value"; return str }},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}(nil))}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TString, Str: "value"}, reflect.ValueOf(map[string]interface{}(nil))}},
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
expectErr: skipMe},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
expectErr: skipMe},
},
},
{title: "empty maps",
sequence: fixtures.SequenceMap["empty map"],
marshalResults: []marshalResults{
{title: "from map[str]iface",
valueFn: func() interface{} { return map[string]interface{}{} }},
{title: "from map[str]str",
valueFn: func() interface{} { return map[string]string{} }},
{title: "from *map[str]str",
valueFn: func() interface{} { m := map[string]string{}; return &m }},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TMapOpen, Length: 0}, reflect.ValueOf("")}},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}{} }},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}(nil))}},
{title: "into made map[str]iface",
slotFn: func() interface{} { v := make(map[string]interface{}); return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}{})}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}{} }},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
valueFn: func() interface{} { return map[string]string{} }},
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
expectErr: skipMe},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
expectErr: skipMe},
},
},
{title: "object with one string field, with atlas entry",
sequence: fixtures.SequenceMap["single row map"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjStr{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "key"}).
Complete(),
),
marshalResults: []marshalResults{
{title: "from object with one field",
valueFn: func() interface{} { return tObjStr{"value"} }},
{title: "from map[str]iface with one entry",
valueFn: func() interface{} { return map[string]interface{}{"key": "value"} }},
{title: "from map[str]str with one entry",
valueFn: func() interface{} { return map[string]string{"key": "value"} }},
{title: "from *map[str]str",
valueFn: func() interface{} { m := map[string]string{"key": "value"}; return &m }},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TMapOpen, Length: 1}, reflect.ValueOf("")}},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}{"key": "value"} }},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}(nil))}},
{title: "into made map[str]iface",
slotFn: func() interface{} { v := make(map[string]interface{}); return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}{})}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}{"key": "value"} }},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
valueFn: func() interface{} { return map[string]string{"key": "value"} }},
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
expectErr: skipMe},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
expectErr: skipMe},
},
},
{title: "object with two string fields, with atlas entry",
sequence: fixtures.SequenceMap["duo row map"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjStr2{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "key"}).
AddField("Y", atlas.StructMapEntry{SerialName: "k2"}).
Complete(),
),
marshalResults: []marshalResults{
{title: "from object with two fields",
valueFn: func() interface{} { return tObjStr2{"value", "v2"} }},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TMapOpen, Length: 2}, reflect.ValueOf("")}},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}{"key": "value", "k2": "v2"} }},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}(nil))}},
{title: "into made map[str]iface",
slotFn: func() interface{} { v := make(map[string]interface{}); return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}{})}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}{"key": "value", "k2": "v2"} }},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
valueFn: func() interface{} { return map[string]string{"key": "value", "k2": "v2"} }},
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
expectErr: skipMe},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
expectErr: skipMe},
{title: "into tObjStr2",
slotFn: func() interface{} { return tObjStr2{} },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(tObjStr2{})}},
{title: "into *tObjStr2",
slotFn: func() interface{} { return &tObjStr2{} },
valueFn: func() interface{} { return tObjStr2{"value", "v2"} }},
},
},
{title: "object with two string fields, with atlas entry, unmarshalling accepts alt2 serial ordering",
sequence: fixtures.SequenceMap["duo row map alt2"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjStr2{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "key"}).
AddField("Y", atlas.StructMapEntry{SerialName: "k2"}).
Complete(),
),
unmarshalResults: []unmarshalResults{
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}{"key": "value", "k2": "v2"} }},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}{"key": "value", "k2": "v2"} }},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
valueFn: func() interface{} { return map[string]string{"key": "value", "k2": "v2"} }},
{title: "into *tObjStr2",
slotFn: func() interface{} { return &tObjStr2{} },
valueFn: func() interface{} { return tObjStr2{"value", "v2"} }},
},
},
{title: "object with two string fields, with atlas entry, unmarshalling rejects when fields mismatch",
sequence: fixtures.SequenceMap["duo row map"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjStr2{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "key"}).
AddField("Y", atlas.StructMapEntry{SerialName: "mismatch"}). // we alter this to not line up with the token stream
Complete(),
),
unmarshalResults: []unmarshalResults{
{title: "into *tObjStr2",
slotFn: func() interface{} { return &tObjStr2{} },
expectErr: ErrNoSuchField{"k2"}},
},
},
{title: "empty primitive arrays",
sequence: fixtures.SequenceMap["empty array"],
marshalResults: []marshalResults{
{title: "from int array",
valueFn: func() interface{} { return [0]int{} }},
{title: "from int slice",
valueFn: func() interface{} { return []int{} }},
{title: "from iface array",
valueFn: func() interface{} { return [0]interface{}{} }},
{title: "from iface slice",
valueFn: func() interface{} { return []interface{}{} }},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TArrOpen, Length: 0}, reflect.ValueOf("")}},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { return []interface{}{} }},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
expectErr: skipMe},
{title: "into made map[str]iface",
slotFn: func() interface{} { v := make(map[string]interface{}); return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}{})}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
expectErr: skipMe},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
expectErr: skipMe},
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
// array/slice direct: theoretically possible, as long as it's short enough. but not supported right now.
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]interface{}{})}},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
valueFn: func() interface{} { return []interface{}{} }},
{title: "into []str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[]str",
slotFn: func() interface{} { var v []string; return &v },
valueFn: func() interface{} { return []string{} }},
{title: "into [0]str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[0]str",
slotFn: func() interface{} { var v [0]string; return &v },
valueFn: func() interface{} { return [0]string{} }},
{title: "into [2]str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[2]str",
slotFn: func() interface{} { var v [2]string; return &v },
valueFn: func() interface{} { return [2]string{} }},
{title: "into []int",
slotFn: func() interface{} { var v []int; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]int{})}},
{title: "into *[]int",
slotFn: func() interface{} { var v []int; return &v },
valueFn: func() interface{} { return []int{} }}, // fine *despite the type mismatch* because with no tokens, well, nobody's the wiser.
},
},
{title: "short primitive arrays",
sequence: fixtures.SequenceMap["duo entry array"],
marshalResults: []marshalResults{
{title: "from str array",
valueFn: func() interface{} { return [2]string{"value", "v2"} }},
{title: "from str slice",
valueFn: func() interface{} { return []string{"value", "v2"} }},
{title: "from iface array",
valueFn: func() interface{} { return [2]interface{}{"value", "v2"} }},
{title: "from iface slice",
valueFn: func() interface{} { return []interface{}{"value", "v2"} }},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TArrOpen, Length: 2}, reflect.ValueOf("")}},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { return []interface{}{"value", "v2"} }},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
expectErr: skipMe},
{title: "into made map[str]iface",
slotFn: func() interface{} { v := make(map[string]interface{}); return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}{})}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
expectErr: skipMe},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
expectErr: skipMe},
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]interface{}{})}},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
valueFn: func() interface{} { return []interface{}{"value", "v2"} }},
{title: "into []str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[]str",
slotFn: func() interface{} { var v []string; return &v },
valueFn: func() interface{} { return []string{"value", "v2"} }},
{title: "into [0]str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[0]str",
slotFn: func() interface{} { var v [0]string; return &v },
expectErr: ErrMalformedTokenStream{TString, "end of array (out of space)"}},
{title: "into [2]str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[2]str",
slotFn: func() interface{} { var v [2]string; return &v },
valueFn: func() interface{} { return [2]string{"value", "v2"} }},
{title: "into []int",
slotFn: func() interface{} { var v []int; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]int{})}},
{title: "into *[]int",
slotFn: func() interface{} { var v []int; return &v },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TString, Str: "value"}, reflect.ValueOf(0)}},
},
},
{title: "maps in maps",
sequence: fixtures.SequenceMap["maps nested in maps"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjPtrObjStrp{}).StructMap().
AddField("P", atlas.StructMapEntry{SerialName: "k"}).
Complete(),
atlas.BuildEntry(tObjPtrObjStrp2{}).StructMap().
AddField("P1", atlas.StructMapEntry{SerialName: "k"}).
Complete(),
atlas.BuildEntry(tObjStrp{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "k2"}).
Complete(),
),
marshalResults: []marshalResults{
{title: "from map[str]iface with map[str]str",
valueFn: func() interface{} {
return map[string]interface{}{"k": map[string]string{"k2": "v2"}}
}},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *map[str]map[str]str",
slotFn: func() interface{} { var m map[string]map[string]string; return &m },
valueFn: func() interface{} {
return map[string]map[string]string{"k": {"k2": "v2"}}
}},
{title: "into *tObjPtrObjStrp{}",
slotFn: func() interface{} { return &tObjPtrObjStrp{} },
valueFn: func() interface{} {
str := "v2"
return tObjPtrObjStrp{&tObjStrp{&str}}
}},
{title: "into *tObjPtrObjStrp2{}, using the first field",
slotFn: func() interface{} { return &tObjPtrObjStrp2{} },
valueFn: func() interface{} {
str := "v2"
return tObjPtrObjStrp2{P1: &tObjStrp{&str}}
}},
},
},
{title: "maps in maps, using an atlas hitting different field orders",
sequence: fixtures.SequenceMap["maps nested in maps"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjPtrObjStrp2{}).StructMap().
AddField("P2", atlas.StructMapEntry{SerialName: "k"}).
Complete(),
atlas.BuildEntry(tObjStrp{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "k2"}).
Complete(),
),
unmarshalResults: []unmarshalResults{
{title: "into *tObjPtrObjStrp2{}, using the second field",
slotFn: func() interface{} { return &tObjPtrObjStrp2{} },
valueFn: func() interface{} {
str := "v2"
return tObjPtrObjStrp2{P2: &tObjStrp{&str}}
}},
},
},
{title: "maps in maps with mixed nulls",
sequence: fixtures.SequenceMap["maps nested in maps with mixed nulls"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjPtrObjStrp2{}).StructMap().
AddField("P1", atlas.StructMapEntry{SerialName: "k"}).
AddField("P2", atlas.StructMapEntry{SerialName: "k2"}).
Complete(),
atlas.BuildEntry(tObjStrp{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "k2"}).
Complete(),
),
unmarshalResults: []unmarshalResults{
{title: "into *tObjPtrObjStrp2{}, null going into the second field",
slotFn: func() interface{} { return &tObjPtrObjStrp2{} },
valueFn: func() interface{} {
str := "v2"
return tObjPtrObjStrp2{P1: &tObjStrp{&str}}
}},
{title: "into *tObjPtrObjStrp2{}, null going into the second field and overwriting an earlier value there",
slotFn: func() interface{} { return &tObjPtrObjStrp2{P2: &tObjStrp{}} },
valueFn: func() interface{} {
str := "v2"
return tObjPtrObjStrp2{P1: &tObjStrp{&str}}
}},
{title: "into **tObjPtrObjStrp2{}, which hits a ptrdefer machine multiple times",
slotFn: func() interface{} { v := &tObjPtrObjStrp2{}; return &v },
valueFn: func() interface{} {
str := "v2"
return &tObjPtrObjStrp2{P1: &tObjStrp{&str}}
}},
},
},
{title: "array nest in map pt1",
sequence: fixtures.SequenceMap["array nested in map as non-first and final entry"],
marshalResults: []marshalResults{
{title: "from map[str]iface with nested []iface",
valueFn: func() interface{} {
return map[string]interface{}{"k1": "v1", "ke": []interface{}{"oh", "whee", "wow"}}
}},
{title: "from map[str]iface with nested []str",
valueFn: func() interface{} {
return map[string]interface{}{"k1": "v1", "ke": []string{"oh", "whee", "wow"}}
}},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TMapOpen, Length: 2}, reflect.ValueOf("")}},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} {
return map[string]interface{}{"k1": "v1", "ke": []interface{}{"oh", "whee", "wow"}}
}},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}(nil))}},
{title: "into made map[str]iface",
slotFn: func() interface{} { v := make(map[string]interface{}); return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}{})}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
valueFn: func() interface{} {
return map[string]interface{}{"k1": "v1", "ke": []interface{}{"oh", "whee", "wow"}}
}},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
//expectErr: ErrUnmarshalTypeCantFit{Token{Type: TArrOpen, Length: 3}, reflect.ValueOf("")}},
expectErr: skipMe}, // big tricky todo: currently falls in the cracks where reflect core panics.
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]interface{}{})}},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
expectErr: skipMe}, // should certainly error, but not well spec'd yet
{title: "into []str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[]str",
slotFn: func() interface{} { var v []string; return &v },
expectErr: skipMe}, // should certainly error, but not well spec'd yet
{title: "into []int",
slotFn: func() interface{} { var v []int; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]int{})}},
{title: "into *[]int",
slotFn: func() interface{} { var v []int; return &v },
expectErr: skipMe}, // should certainly error, but not well spec'd yet
},
},
{title: "nested maps and arrays with no wildcards",
sequence: fixtures.SequenceMap["map[str][]map[str]int"],
marshalResults: []marshalResults{
{title: "from oh-so-much type info",
valueFn: func() interface{} {
return map[string][]map[string]int{"k": []map[string]int{
map[string]int{"k2": 1},
map[string]int{"k2": 2},
}}
}},
},
unmarshalResults: []unmarshalResults{
{title: "into oh-so-much type info",
slotFn: func() interface{} { var v map[string][]map[string]int; return &v },
valueFn: func() interface{} {
return map[string][]map[string]int{"k": []map[string]int{
map[string]int{"k2": 1},
map[string]int{"k2": 2},
}}
}},
},
},
{title: "nested maps and arrays as atlased structs",
sequence: fixtures.SequenceMap["map[str][]map[str]int"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjK{}).StructMap().
AddField("K", atlas.StructMapEntry{SerialName: "k"}).
Complete(),
atlas.BuildEntry(tObjK2{}).StructMap().
AddField("K2", atlas.StructMapEntry{SerialName: "k2"}).
Complete(),
),
marshalResults: []marshalResults{
{title: "from tObjK{[]tObjK2{}}",
valueFn: func() interface{} {
return tObjK{[]tObjK2{{1}, {2}}}
}},
},
unmarshalResults: []unmarshalResults{
{title: "into tObjK{[]tObjK2{}}",
slotFn: func() interface{} { return &tObjK{} },
valueFn: func() interface{} {
return tObjK{[]tObjK2{{1}, {2}}}
}},
},
},
{title: "transform funks (struct<->string)",
sequence: fixtures.SequenceMap["flat string"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjStr{}).Transform().
TransformMarshal(atlas.MakeMarshalTransformFunc(
func(x tObjStr) (string, error) {
return x.X, nil
})).
TransformUnmarshal(atlas.MakeUnmarshalTransformFunc(
func(x string) (tObjStr, error) {
return tObjStr{x}, nil
})).
Complete(),
),
marshalResults: []marshalResults{
{title: "from tObjStr",
valueFn: func() interface{} { return tObjStr{"value"} }},
{title: "from *tObjStr",
valueFn: func() interface{} { return &tObjStr{"value"} }},
},
unmarshalResults: []unmarshalResults{
{title: "into *tObjStr",
slotFn: func() interface{} { return &tObjStr{} },
valueFn: func() interface{} { return tObjStr{"value"} }},
// There are no tests here for "into interface{}" because by definition
// those situations wouldn't provide type info that would trigger these paths.
},
},
{title: "transform funks (struct<->string) in a slice",
sequence: fixtures.SequenceMap["duo entry array"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjStr{}).Transform().
TransformMarshal(atlas.MakeMarshalTransformFunc(
func(x tObjStr) (string, error) {
return x.X, nil
})).
TransformUnmarshal(atlas.MakeUnmarshalTransformFunc(
func(x string) (tObjStr, error) {
return tObjStr{x}, nil
})).
Complete(),
),
marshalResults: []marshalResults{
{title: "from []tObjStr",
valueFn: func() interface{} { return []tObjStr{{"value"}, {"v2"}} }},
{title: "from *[]tObjStr",
valueFn: func() interface{} { return &[]tObjStr{{"value"}, {"v2"}} }},
},
unmarshalResults: []unmarshalResults{
{title: "into *tObjStr",
slotFn: func() interface{} { return &tObjStr{} },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TArrOpen, Length: 2}, reflect.ValueOf("")}},
{title: "into []tObjStr",
slotFn: func() interface{} { return []tObjStr{} },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]tObjStr{})}},
{title: "into *[]tObjStr",
slotFn: func() interface{} { return &[]tObjStr{} },
valueFn: func() interface{} { return []tObjStr{{"value"}, {"v2"}} }},
},
},
{title: "typedef strings",
sequence: fixtures.SequenceMap["flat string"],
// no atlas necessary: the default behavior for a kind, even if typedef'd,
// is to simply to the natural thing for that kind.
marshalResults: []marshalResults{
{title: "from tDefStr literal",
valueFn: func() interface{} { str := tDefStr("value"); return str }},
{title: "from *tDefStr",
valueFn: func() interface{} { str := tDefStr("value"); return &str }},
{title: "from tDefStr in iface slot",
valueFn: func() interface{} { var iface interface{}; iface = tDefStr("value"); return iface }},
{title: "from tDefStr in *iface slot",
valueFn: func() interface{} { var iface interface{}; iface = tDefStr("value"); return &iface }},
{title: "from *tDefStr in iface slot",
valueFn: func() interface{} { str := tDefStr("value"); var iface interface{}; iface = &str; return iface }},
{title: "from *tDefStr in *iface slot",
valueFn: func() interface{} { str := tDefStr("value"); var iface interface{}; iface = &str; return &iface }},
},
unmarshalResults: []unmarshalResults{
{title: "into tDefStr",
slotFn: func() interface{} { var str tDefStr; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(tDefStr(""))}},
{title: "into *tDefStr",
slotFn: func() interface{} { var str tDefStr; return &str },
valueFn: func() interface{} { str := tDefStr("value"); return str }},
},
},
{title: "typedef ints",
sequence: fixtures.SequenceMap["integer one"],
// no atlas necessary: the default behavior for a kind, even if typedef'd,
// is to simply to the natural thing for that kind.
marshalResults: []marshalResults{
{title: "from tDefInt literal",
valueFn: func() interface{} { v := tDefInt(1); return v }},
{title: "from *tDefInt",
valueFn: func() interface{} { v := tDefInt(1); return &v }},
{title: "from tDefInt in iface slot",
valueFn: func() interface{} { var iface interface{}; iface = tDefInt(1); return iface }},
{title: "from tDefInt in *iface slot",
valueFn: func() interface{} { var iface interface{}; iface = tDefInt(1); return &iface }},
{title: "from *tDefInt in iface slot",
valueFn: func() interface{} { v := tDefInt(1); var iface interface{}; iface = &v; return iface }},
{title: "from *tDefInt in *iface slot",
valueFn: func() interface{} { v := tDefInt(1); var iface interface{}; iface = &v; return &iface }},
},
unmarshalResults: []unmarshalResults{
{title: "into tDefInt",
slotFn: func() interface{} { var v tDefInt; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(tDefInt(0))}},
{title: "into *tDefInt",
slotFn: func() interface{} { var v tDefInt; return &v },
valueFn: func() interface{} { v := tDefInt(1); return v }},
},
},
{title: "typedef bytes",
sequence: fixtures.SequenceMap["short byte array"],
// no atlas necessary: the default behavior for a kind, even if typedef'd,
// is to simply to the natural thing for that kind.
marshalResults: []marshalResults{
{title: "from tDefBytes literal",
valueFn: func() interface{} { v := tDefBytes(`value`); return v }},
{title: "from *tDefBytes",
valueFn: func() interface{} { v := tDefBytes(`value`); return &v }},
{title: "from tDefBytes in iface slot",
valueFn: func() interface{} { var iface interface{}; iface = tDefBytes(`value`); return iface }},
{title: "from tDefBytes in *iface slot",
valueFn: func() interface{} { var iface interface{}; iface = tDefBytes(`value`); return &iface }},
{title: "from *tDefBytes in iface slot",
valueFn: func() interface{} { v := tDefBytes(`value`); var iface interface{}; iface = &v; return iface }},
{title: "from *tDefBytes in *iface slot",
valueFn: func() interface{} { v := tDefBytes(`value`); var iface interface{}; iface = &v; return &iface }},
},
unmarshalResults: []unmarshalResults{
{title: "into tDefBytes",
slotFn: func() interface{} { var v tDefBytes; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(tDefBytes{})}},
{title: "into *tDefBytes",
slotFn: func() interface{} { var v tDefBytes; return &v },
valueFn: func() interface{} { v := tDefBytes(`value`); return v }},
},
},
{title: "maps with typedef keys (still of string kind)",
sequence: fixtures.SequenceMap["single row map"],
marshalResults: []marshalResults{
{title: "from map[tDefStr]iface with one entry",
valueFn: func() interface{} { return map[tDefStr]interface{}{"key": "value"} }},
{title: "from map[tDefStr]str with one entry",
valueFn: func() interface{} { return map[tDefStr]string{"key": "value"} }},
{title: "from *map[tDefStr]str",
valueFn: func() interface{} { m := map[tDefStr]string{"key": "value"}; return &m }},
},
unmarshalResults: []unmarshalResults{
{title: "into map[tDefStr]iface",
slotFn: func() interface{} { var v map[tDefStr]interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[tDefStr]interface{}(nil))}},
{title: "into *map[tDefStr]iface",
slotFn: func() interface{} { var v map[tDefStr]interface{}; return &v },
valueFn: func() interface{} { return map[tDefStr]interface{}{"key": "value"} }},
},
},
{title: "empty",
sequence: fixtures.SequenceMap["empty"],
marshalResults: []marshalResults{
// not much marshals to empty!
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
valueFn: func() interface{} { return "" }},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { return nil }},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
valueFn: func() interface{} { return map[string]interface{}(nil) }},
{title: "into made map[str]iface",
slotFn: func() interface{} { v := make(map[string]interface{}); return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}{})}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}(nil) }},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
valueFn: func() interface{} { return map[string]string(nil) }},
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]interface{}{})}},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
valueFn: func() interface{} { return []interface{}(nil) }},
{title: "into []str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[]str",
slotFn: func() interface{} { var v []string; return &v },
valueFn: func() interface{} { return []string(nil) }},
{title: "into []int",
slotFn: func() interface{} { var v []int; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]int{})}},
{title: "into *[]int",
slotFn: func() interface{} { var v []int; return &v },
valueFn: func() interface{} { return []int(nil) }},
},
},
{title: "null",
sequence: fixtures.SequenceMap["null"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjStr{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "key"}).
Complete(),
),
marshalResults: []marshalResults{
{title: "from *string",
valueFn: func() interface{} { var strp *string; return strp }},
{title: "from *string in iface slot",
valueFn: func() interface{} { var strp *string; var iface interface{}; iface = strp; return iface }},
{title: "from *string in *iface slot",
valueFn: func() interface{} { var strp *string; var iface interface{}; iface = strp; return &iface }},
{title: "from **string",
valueFn: func() interface{} { var strp *string; return &strp }},
{title: "from **string in iface slot",
valueFn: func() interface{} { var strp *string; var iface interface{}; iface = &strp; return iface }},
{title: "from nil return",
valueFn: func() interface{} { return nil }}, // this is the illusive "invalid" kind! even `reflect.ValueOf(nil).Type()` will panic!
{title: "from nil in iface slot",
valueFn: func() interface{} { var iface interface{}; iface = nil; return iface }}, // same as previous test row.
{title: "from nil in *iface slot",
valueFn: func() interface{} { var iface interface{}; iface = nil; return &iface }},
{title: "from map[str]iface",
valueFn: func() interface{} { return map[string]interface{}(nil) }},
{title: "from map[str]str",
valueFn: func() interface{} { return map[string]string(nil) }},
{title: "from *map[str]str (nil map, valid ptr)",
valueFn: func() interface{} { m := map[string]string(nil); return &m }},
{title: "from *map[str]str (nil ptr)",
valueFn: func() interface{} { var mp *map[string]string; return mp }},
//{title: "from int array", // Not Possible! Compiler says: "cannot convert nil to type [0]int"
// valueFn: func() interface{} { return [0]int(nil) }},
{title: "from int slice",
valueFn: func() interface{} { return []int(nil) }},
//{title: "from iface array", // Not Possible! Compiler says: "cannot convert nil to type [0]interface {}"
// valueFn: func() interface{} { return [0]interface{}(nil) }},
{title: "from iface slice",
valueFn: func() interface{} { return []interface{}(nil) }},
{title: "from *int array",
valueFn: func() interface{} { var v *[0]int; return v }},
{title: "from *int slice",
valueFn: func() interface{} { var v *[]int; return v }},
{title: "from *iface array",
valueFn: func() interface{} { var v *[0]interface{}; return v }},
{title: "from *iface slice",
valueFn: func() interface{} { var v *[]interface{}; return v }},
{title: "from *tObjStr",
valueFn: func() interface{} { var v *tObjStr; return v }},
},
unmarshalResults: []unmarshalResults{
{title: "into string",
slotFn: func() interface{} { var str string; return str },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf("")}},
{title: "into *string",
slotFn: func() interface{} { var str string; return &str },
expectErr: ErrUnmarshalTypeCantFit{Token{Type: TNull}, reflect.ValueOf("")}},
{title: "into **string",
slotFn: func() interface{} { var strp *string; return &strp },
valueFn: func() interface{} { return (*string)(nil) }},
{title: "into wildcard",
slotFn: func() interface{} { var v interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(interface{}(nil))}},
{title: "into *wildcard",
slotFn: func() interface{} { var v interface{}; return &v },
valueFn: func() interface{} { return nil }},
{title: "into map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}(nil))}},
{title: "into made map[str]iface",
slotFn: func() interface{} { v := make(map[string]interface{}); return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf(map[string]interface{}{})}},
{title: "into *map[str]iface",
slotFn: func() interface{} { var v map[string]interface{}; return &v },
valueFn: func() interface{} { return map[string]interface{}(nil) }},
{title: "into *map[str]str",
slotFn: func() interface{} { var v map[string]string; return &v },
valueFn: func() interface{} { return map[string]string(nil) }},
{title: "into []iface",
slotFn: func() interface{} { var v []interface{}; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]interface{}{})}},
{title: "into *[]iface",
slotFn: func() interface{} { var v []interface{}; return &v },
valueFn: func() interface{} { return []interface{}(nil) }},
{title: "into []str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[]str",
slotFn: func() interface{} { var v []string; return &v },
valueFn: func() interface{} { return []string(nil) }},
{title: "into [0]str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[0]str",
slotFn: func() interface{} { var v [0]string; return &v },
valueFn: func() interface{} { return [0]string{} }},
{title: "into [2]str",
slotFn: func() interface{} { var v []string; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]string{})}},
{title: "into *[2]str",
slotFn: func() interface{} { var v [2]string; return &v },
valueFn: func() interface{} { return [2]string{} }},
{title: "into []int",
slotFn: func() interface{} { var v []int; return v },
expectErr: ErrInvalidUnmarshalTarget{reflect.TypeOf([]int{})}},
{title: "into *[]int",
slotFn: func() interface{} { var v []int; return &v },
valueFn: func() interface{} { return []int(nil) }},
{title: "into *tObjStr",
slotFn: func() interface{} { var v tObjStr; return &v },
// no, the answer is *not* a nil a la `{ var v *tObjStr; return v }` -- because the way unmarshalling uses the first pointer, it can't really set it to nil.
// stdlib json behavior is the same for the same reasons: https://play.golang.org/p/kd8iqNPdlM
valueFn: func() interface{} { return tObjStr{""} }},
},
},
{title: "nulls in map values and struct fields",
sequence: fixtures.SequenceMap["null in map"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjStrp{}).StructMap().