mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Generate slices of method *Sig(nature)s instead of linked lists. Remove custom lsort function in favor of sort.Interface. Eliminates another use of stringsCompare. Passes go build -a -toolexec 'toolstash -cmp' std cmd. Change-Id: I9ed1664b7f55be9e967dd7196e396a76f6ea3422 Reviewed-on: https://go-review.googlesource.com/14559 Reviewed-by: Dave Cheney <dave@cheney.net>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
// 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 gc
|
|
|
|
import (
|
|
"reflect"
|
|
"sort"
|
|
"testing"
|
|
)
|
|
|
|
func TestSortingByMethodNameAndPackagePath(t *testing.T) {
|
|
data := []*Sig{
|
|
&Sig{name: "b", pkg: &Pkg{Path: "abc"}},
|
|
&Sig{name: "b", pkg: nil},
|
|
&Sig{name: "c", pkg: nil},
|
|
&Sig{name: "c", pkg: &Pkg{Path: "uvw"}},
|
|
&Sig{name: "c", pkg: nil},
|
|
&Sig{name: "b", pkg: &Pkg{Path: "xyz"}},
|
|
&Sig{name: "a", pkg: &Pkg{Path: "abc"}},
|
|
&Sig{name: "b", pkg: nil},
|
|
}
|
|
want := []*Sig{
|
|
&Sig{name: "a", pkg: &Pkg{Path: "abc"}},
|
|
&Sig{name: "b", pkg: nil},
|
|
&Sig{name: "b", pkg: nil},
|
|
&Sig{name: "b", pkg: &Pkg{Path: "abc"}},
|
|
&Sig{name: "b", pkg: &Pkg{Path: "xyz"}},
|
|
&Sig{name: "c", pkg: nil},
|
|
&Sig{name: "c", pkg: nil},
|
|
&Sig{name: "c", pkg: &Pkg{Path: "uvw"}},
|
|
}
|
|
if len(data) != len(want) {
|
|
t.Fatal("want and data must match")
|
|
}
|
|
if reflect.DeepEqual(data, want) {
|
|
t.Fatal("data must be shuffled")
|
|
}
|
|
sort.Sort(byMethodNameAndPackagePath(data))
|
|
if !reflect.DeepEqual(data, want) {
|
|
t.Logf("want: %#v", want)
|
|
t.Logf("data: %#v", data)
|
|
t.Errorf("sorting failed")
|
|
}
|
|
|
|
}
|