-
Notifications
You must be signed in to change notification settings - Fork 8
/
grouper_test.go
46 lines (37 loc) · 1.01 KB
/
grouper_test.go
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
package gogroup
import "strings"
// Group everything together.
type grouperCombined struct{}
func (grouperCombined) Group(pkgPath string) (group int) {
return 0
}
// Group like goimports: first standard packages, then 3rd party, then appengine,
// then local.
type grouperGoimports struct{}
func (grouperGoimports) Group(pkgPath string) (group int) {
if strings.HasPrefix(pkgPath, "local/") {
return 3
} else if strings.HasPrefix(pkgPath, "appengine") {
return 2
} else if strings.Contains(pkgPath, ".") {
return 1
} else {
return 0
}
}
// Group with another common pattern: std, local, 3rd party.
type grouperLocalMiddle struct{}
func (grouperLocalMiddle) Group(pkgPath string) (group int) {
if strings.HasPrefix(pkgPath, "local/") {
return 1
} else if strings.Contains(pkgPath, ".") {
return 2
} else {
return 0
}
}
// You could group in really strange ways. I guess it's supported?
type grouperWeird struct{}
func (grouperWeird) Group(pkgPath string) (group int) {
return strings.Count(pkgPath, "/")
}