From: Andrew Gerrand Date: Thu, 16 Feb 2012 02:08:35 +0000 (+1100) Subject: go/ast: return Examples in name order X-Git-Tag: weekly.2012-02-22~208 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e9016bb8a7e5cf173556c51a173ae04f91da168a;p=gostls13.git go/ast: return Examples in name order R=bradfitz CC=golang-dev https://golang.org/cl/5673061 --- diff --git a/src/pkg/go/ast/example.go b/src/pkg/go/ast/example.go index 33a836894a..dec496b6f4 100644 --- a/src/pkg/go/ast/example.go +++ b/src/pkg/go/ast/example.go @@ -9,6 +9,7 @@ package ast import ( "go/token" "regexp" + "sort" "strings" "unicode" "unicode/utf8" @@ -66,6 +67,7 @@ func Examples(files ...*File) []*Example { } list = append(list, flist...) } + sort.Sort(exampleByName(list)) return list } @@ -106,3 +108,9 @@ func isTest(name, prefix string) bool { rune, _ := utf8.DecodeRuneInString(name[len(prefix):]) return !unicode.IsLower(rune) } + +type exampleByName []*Example + +func (s exampleByName) Len() int { return len(s) } +func (s exampleByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s exampleByName) Less(i, j int) bool { return s[i].Name < s[j].Name }