1
2
3
4
5 package types_test
6
7 import (
8 "cmd/compile/internal/types"
9 "reflect"
10 "sort"
11 "testing"
12 )
13
14 func TestSymLess(t *testing.T) {
15 var (
16 local = types.NewPkg("", "")
17 abc = types.NewPkg("abc", "")
18 uvw = types.NewPkg("uvw", "")
19 xyz = types.NewPkg("xyz", "")
20 gr = types.NewPkg("gr", "")
21 )
22
23 data := []*types.Sym{
24 abc.Lookup("b"),
25 local.Lookup("B"),
26 local.Lookup("C"),
27 uvw.Lookup("c"),
28 local.Lookup("C"),
29 gr.Lookup("φ"),
30 local.Lookup("Φ"),
31 xyz.Lookup("b"),
32 abc.Lookup("a"),
33 local.Lookup("B"),
34 }
35 want := []*types.Sym{
36 local.Lookup("B"),
37 local.Lookup("B"),
38 local.Lookup("C"),
39 local.Lookup("C"),
40 local.Lookup("Φ"),
41 abc.Lookup("a"),
42 abc.Lookup("b"),
43 xyz.Lookup("b"),
44 uvw.Lookup("c"),
45 gr.Lookup("φ"),
46 }
47 if len(data) != len(want) {
48 t.Fatal("want and data must match")
49 }
50 if reflect.DeepEqual(data, want) {
51 t.Fatal("data must be shuffled")
52 }
53 sort.Slice(data, func(i, j int) bool { return data[i].Less(data[j]) })
54 if !reflect.DeepEqual(data, want) {
55 t.Logf("want: %#v", want)
56 t.Logf("data: %#v", data)
57 t.Errorf("sorting failed")
58 }
59 }
60
View as plain text