@@ -126,10 +126,6 @@ var sortTests = []sortTest{
126
126
map [[2 ]int ]string {{7 , 2 }: "72" , {7 , 1 }: "71" , {3 , 4 }: "34" },
127
127
"[3 4]:34 [7 1]:71 [7 2]:72" ,
128
128
},
129
- {
130
- map [interface {}]string {7 : "7" , 4 : "4" , 3 : "3" , nil : "nil" },
131
- "<nil>:nil 3:3 4:4 7:7" ,
132
- },
133
129
}
134
130
135
131
func sprint (data interface {}) string {
@@ -210,3 +206,41 @@ func TestOrder(t *testing.T) {
210
206
}
211
207
}
212
208
}
209
+
210
+ func TestInterface (t * testing.T ) {
211
+ // A map containing multiple concrete types should be sorted by type,
212
+ // then value. However, the relative ordering of types is unspecified,
213
+ // so test this by checking the presence of sorted subgroups.
214
+ m := map [interface {}]string {
215
+ [2 ]int {1 , 0 }: "" ,
216
+ [2 ]int {0 , 1 }: "" ,
217
+ true : "" ,
218
+ false : "" ,
219
+ 3.1 : "" ,
220
+ 2.1 : "" ,
221
+ 1.1 : "" ,
222
+ math .NaN (): "" ,
223
+ 3 : "" ,
224
+ 2 : "" ,
225
+ 1 : "" ,
226
+ "c" : "" ,
227
+ "b" : "" ,
228
+ "a" : "" ,
229
+ struct { x , y int }{1 , 0 }: "" ,
230
+ struct { x , y int }{0 , 1 }: "" ,
231
+ }
232
+ got := sprint (m )
233
+ typeGroups := []string {
234
+ "NaN: 1.1: 2.1: 3.1:" , // float64
235
+ "false: true:" , // bool
236
+ "1: 2: 3:" , // int
237
+ "a: b: c:" , // string
238
+ "[0 1]: [1 0]:" , // [2]int
239
+ "{0 1}: {1 0}:" , // struct{ x int; y int }
240
+ }
241
+ for _ , g := range typeGroups {
242
+ if ! strings .Contains (got , g ) {
243
+ t .Errorf ("sorted map should contain %q" , g )
244
+ }
245
+ }
246
+ }
0 commit comments