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
|
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package types_test
import (
"cmd/compile/internal/types"
"reflect"
"sort"
"testing"
)
func TestSymLess(t *testing.T) {
var (
local = types.NewPkg("", "")
abc = types.NewPkg("abc", "")
uvw = types.NewPkg("uvw", "")
xyz = types.NewPkg("xyz", "")
gr = types.NewPkg("gr", "")
)
data := []*types.Sym{
abc.Lookup("b"),
local.Lookup("B"),
local.Lookup("C"),
uvw.Lookup("c"),
local.Lookup("C"),
gr.Lookup("φ"),
local.Lookup("Φ"),
xyz.Lookup("b"),
abc.Lookup("a"),
local.Lookup("B"),
}
want := []*types.Sym{
local.Lookup("B"),
local.Lookup("B"),
local.Lookup("C"),
local.Lookup("C"),
local.Lookup("Φ"),
abc.Lookup("a"),
abc.Lookup("b"),
xyz.Lookup("b"),
uvw.Lookup("c"),
gr.Lookup("φ"),
}
if len(data) != len(want) {
t.Fatal("want and data must match")
}
if reflect.DeepEqual(data, want) {
t.Fatal("data must be shuffled")
}
sort.Slice(data, func(i, j int) bool { return data[i].Less(data[j]) })
if !reflect.DeepEqual(data, want) {
t.Logf("want: %#v", want)
t.Logf("data: %#v", data)
t.Errorf("sorting failed")
}
}
|