-
Notifications
You must be signed in to change notification settings - Fork 0
/
structinit_test.go
71 lines (63 loc) · 1.4 KB
/
structinit_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
package structinit
import (
"os"
"path/filepath"
"testing"
"github.com/matryer/is"
"golang.org/x/tools/go/analysis/analysistest"
)
func TestIntegration(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Could not get wd: %s", err)
}
testDir := filepath.Join(wd, "testdata")
analysistest.Run(t, testDir, Analyzer, "test")
}
func TestParseTag(t *testing.T) {
tt := []struct {
name string
text string
isExhaustive bool
omitMap Set
}{
{
name: "unrelated_comment",
text: "// documentation related to definition",
isExhaustive: false,
omitMap: nil,
},
{
name: "basic_tag",
text: "//structinit:exhaustive",
isExhaustive: true,
omitMap: nil,
},
{
name: "basic_tag_with_single_omit",
text: "//structinit:exhaustive,omit=ID",
isExhaustive: true,
omitMap: Set{
"ID": struct{}{},
},
},
{
name: "basic_tag_with_multiple_omit",
text: "//structinit:exhaustive,omit=ID,FirstName,LastName",
isExhaustive: true,
omitMap: Set{
"ID": struct{}{},
"FirstName": struct{}{},
"LastName": struct{}{},
},
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
is := is.New(t)
isExhaustive, omitMap := parseTag(tc.text)
is.Equal(isExhaustive, tc.isExhaustive)
is.Equal(omitMap, tc.omitMap)
})
}
}