-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgroup_test.go
109 lines (92 loc) · 2.58 KB
/
group_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2011 The GoGL Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.mkd file.
package main
import (
"testing"
)
func checkEnumCats(paks Packages, t *testing.T, pak string, cats ...string) {
if p, ok := paks[pak]; ok {
if len(cats) != len(p.Enums) {
t.Errorf("len(cats) != len(p.Enums)")
return
}
for _, c := range cats {
if _, ok := p.Enums[c]; !ok {
t.Errorf("Enum not found: %v::%v", pak, c)
return
}
}
return
}
t.Errorf("Package not found: %v", pak)
}
func checkFuncCats(paks Packages, t *testing.T, pak string, cats ...string) {
if p, ok := paks[pak]; ok {
if len(cats) != len(p.Functions) {
t.Errorf("len(cats) != len(p.Functions)")
return
}
for _, c := range cats {
if _, ok := p.Functions[c]; !ok {
t.Errorf("Function not found: %v::%v", pak, c)
return
}
}
return
}
t.Errorf("Package not found: %v", pak)
}
func TestPackageGrouping(t *testing.T) {
e := make(EnumCategories)
f := make(FunctionCategories)
e["VERSION_1_3"] = Enums{}
e["VERSION_1_3_DEPRECATED"] = Enums{}
e["VERSION_2_1"] = Enums{}
e["VERSION_2_1_DEPRECATED"] = Enums{}
e["VERSION_2_3"] = Enums{}
e["VERSION_2_3_DEPRECATED"] = Enums{}
e["VERSION_3_1"] = Enums{}
e["EXT_1"] = Enums{}
e["NV_1"] = Enums{}
e["ATI_1"] = Enums{}
f["EXT_1"] = []*Function{}
f["NV_1"] = []*Function{}
f["ATI_1"] = []*Function{}
suppV := []Version{{1, 3}, {2, 1}, {2, 3}, {3, 1}}
deprV := []Version{{3, 1}}
p := GroupEnumsAndFunctions(e, f,
func(category string) (packageNames []string) {
return GroupPackagesByVendorFunc(category, suppV, deprV)
})
for n, pa := range p {
t.Logf("%s:\n %s\n", n, pa)
}
if len(p) != 8 {
t.Errorf("Wrong number of categories.")
}
checkEnumCats(p, t, "nv", "NV_1")
checkEnumCats(p, t, "ati", "ATI_1")
checkEnumCats(p, t, "ext", "EXT_1")
checkEnumCats(p, t, "gl13", "VERSION_1_3", "VERSION_1_3_DEPRECATED")
checkEnumCats(p, t, "gl21",
"VERSION_1_3", "VERSION_1_3_DEPRECATED",
"VERSION_2_1", "VERSION_2_1_DEPRECATED")
checkEnumCats(p, t, "gl23",
"VERSION_1_3", "VERSION_1_3_DEPRECATED",
"VERSION_2_1", "VERSION_2_1_DEPRECATED",
"VERSION_2_3", "VERSION_2_3_DEPRECATED")
checkEnumCats(p, t, "gl31",
"VERSION_1_3",
"VERSION_2_1",
"VERSION_2_3",
"VERSION_3_1")
checkEnumCats(p, t, "gl31c",
"VERSION_1_3", "VERSION_1_3_DEPRECATED",
"VERSION_2_1", "VERSION_2_1_DEPRECATED",
"VERSION_2_3", "VERSION_2_3_DEPRECATED",
"VERSION_3_1")
checkFuncCats(p, t, "nv", "NV_1")
checkFuncCats(p, t, "ati", "ATI_1")
checkFuncCats(p, t, "ext", "EXT_1")
}