@@ -248,6 +248,49 @@ func TestRegisterEncoder(t *testing.T) {
248
248
valExists (t , "oneSliceAsWord" , "one" , v1 )
249
249
}
250
250
251
+ func TestEncoderOrder (t * testing.T ) {
252
+ type builtinEncoderSimple int
253
+ type builtinEncoderSimpleOverridden int
254
+ type builtinEncoderSlice []int
255
+ type builtinEncoderSliceOverridden []int
256
+ type builtinEncoderStruct struct { nr int }
257
+ type builtinEncoderStructOverridden struct { nr int }
258
+
259
+ s1 := & struct {
260
+ builtinEncoderSimple `schema:"simple"`
261
+ builtinEncoderSimpleOverridden `schema:"simple_overridden"`
262
+ builtinEncoderSlice `schema:"slice"`
263
+ builtinEncoderSliceOverridden `schema:"slice_overridden"`
264
+ builtinEncoderStruct `schema:"struct"`
265
+ builtinEncoderStructOverridden `schema:"struct_overridden"`
266
+ }{
267
+ 1 ,
268
+ 1 ,
269
+ []int {2 },
270
+ []int {2 },
271
+ builtinEncoderStruct {3 },
272
+ builtinEncoderStructOverridden {3 },
273
+ }
274
+ v1 := make (map [string ][]string )
275
+
276
+ encoder := NewEncoder ()
277
+ encoder .RegisterEncoder (s1 .builtinEncoderSimpleOverridden , func (v reflect.Value ) string { return "one" })
278
+ encoder .RegisterEncoder (s1 .builtinEncoderSliceOverridden , func (v reflect.Value ) string { return "two" })
279
+ encoder .RegisterEncoder (s1 .builtinEncoderStructOverridden , func (v reflect.Value ) string { return "three" })
280
+
281
+ err := encoder .Encode (s1 , v1 )
282
+ if err != nil {
283
+ t .Errorf ("Encoder has non-nil error: %v" , err )
284
+ }
285
+
286
+ valExists (t , "simple" , "1" , v1 )
287
+ valExists (t , "simple_overridden" , "one" , v1 )
288
+ valExists (t , "slice" , "2" , v1 )
289
+ valExists (t , "slice_overridden" , "two" , v1 )
290
+ valExists (t , "nr" , "3" , v1 )
291
+ valExists (t , "struct_overridden" , "three" , v1 )
292
+ }
293
+
251
294
func valExists (t * testing.T , key string , expect string , result map [string ][]string ) {
252
295
valsExist (t , key , []string {expect }, result )
253
296
}
0 commit comments