@@ -18,6 +18,8 @@ type IntAlias int
18
18
19
19
type rudeBool bool
20
20
21
+ type sliceID [2 ]byte
22
+
21
23
func (id * rudeBool ) UnmarshalText (text []byte ) error {
22
24
value := string (text )
23
25
switch {
@@ -31,6 +33,14 @@ func (id *rudeBool) UnmarshalText(text []byte) error {
31
33
return nil
32
34
}
33
35
36
+ func (id * sliceID ) UnmarshalText (text []byte ) error {
37
+ if len (text ) != 2 {
38
+ return errors .New ("value must 2 bytes length" )
39
+ }
40
+ copy (id [:], text )
41
+ return nil
42
+ }
43
+
34
44
// All cases we want to cover, in a nutshell.
35
45
type S1 struct {
36
46
F01 int `schema:"f1"`
@@ -54,6 +64,10 @@ type S1 struct {
54
64
F19 * rudeBool `schema:"f19"`
55
65
F20 []rudeBool `schema:"f20"`
56
66
F21 []* rudeBool `schema:"f21"`
67
+ F22 sliceID `schema:"f22"`
68
+ F23 * sliceID `schema:"f23"`
69
+ F24 []sliceID `schema:"f24"`
70
+ F25 []* sliceID `schema:"f25"`
57
71
}
58
72
59
73
type S2 struct {
@@ -101,6 +115,10 @@ func TestAll(t *testing.T) {
101
115
"f19" : {"nope" },
102
116
"f20" : {"nope" , "yup" },
103
117
"f21" : {"yup" , "nope" },
118
+ "f22" : {"A1" },
119
+ "f23" : {"A2" },
120
+ "f24" : {"A3" , "A4" },
121
+ "f25" : {"A5" , "A6" },
104
122
}
105
123
f2 := 2
106
124
f41 , f42 := 41 , 42
@@ -172,6 +190,10 @@ func TestAll(t *testing.T) {
172
190
F19 : & f153 ,
173
191
F20 : []rudeBool {f153 , f152 },
174
192
F21 : []* rudeBool {& f152 , & f153 },
193
+ F22 : sliceID {'A' , '1' },
194
+ F23 : & sliceID {'A' , '2' },
195
+ F24 : []sliceID {{'A' , '3' }, {'A' , '4' }},
196
+ F25 : []* sliceID {{'A' , '5' }, {'A' , '6' }},
175
197
}
176
198
177
199
s := & S1 {}
@@ -386,6 +408,26 @@ func TestAll(t *testing.T) {
386
408
} else if ! reflect .DeepEqual (s .F21 , e .F21 ) {
387
409
t .Errorf ("f21: expected %v, got %v" , e .F21 , s .F21 )
388
410
}
411
+ if s .F22 != e .F22 {
412
+ t .Errorf ("f22: expected %v, got %v" , e .F22 , s .F22 )
413
+ }
414
+ if * s .F23 != * e .F23 {
415
+ t .Errorf ("f23: expected %v, got %v" , * e .F23 , * s .F23 )
416
+ }
417
+ if s .F24 == nil {
418
+ t .Errorf ("f24: nil" )
419
+ } else if len (s .F24 ) != len (e .F24 ) {
420
+ t .Errorf ("f24: expected %v, got %v" , e .F24 , s .F24 )
421
+ } else if ! reflect .DeepEqual (s .F24 , e .F24 ) {
422
+ t .Errorf ("f24: expected %v, got %v" , e .F24 , s .F24 )
423
+ }
424
+ if s .F25 == nil {
425
+ t .Errorf ("f25: nil" )
426
+ } else if len (s .F25 ) != len (e .F25 ) {
427
+ t .Errorf ("f25: expected length %d, got %d" , len (e .F25 ), len (s .F25 ))
428
+ } else if ! reflect .DeepEqual (s .F25 , e .F25 ) {
429
+ t .Errorf ("f25: expected %v, got %v" , e .F25 , s .F25 )
430
+ }
389
431
}
390
432
391
433
func BenchmarkAll (b * testing.B ) {
0 commit comments