-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsistent_test.go
51 lines (43 loc) · 888 Bytes
/
consistent_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
package consistent
import (
"os"
"testing"
"github.com/go-toolsmith/strparse"
"github.com/matryer/is"
"golang.org/x/tools/go/analysis/analysistest"
)
func TestLitInt(t *testing.T) {
tests := []struct {
given string
want int
}{
{"0", 0},
{"123", 123},
{"1_2_3", 123},
{"0x123", 0x123},
{"0X123", 0x123},
{"0b11011", 0b11011},
{"0B11011", 0b11011},
{"0644", 0644},
{"0o644", 0644},
{"0O644", 0644},
{"000644", 0644},
}
for _, test := range tests {
t.Run(test.given, func(t *testing.T) {
is := is.New(t)
i, ok := litInt(strparse.Expr(test.given))
is.Equal(i, test.want)
is.True(ok)
})
}
}
func runTest(t *testing.T, pkg string, flags map[string]string) {
t.Helper()
analyzer := NewAnalyzer()
for k, v := range flags {
_ = analyzer.Flags.Set(k, v)
}
wd, _ := os.Getwd()
analysistest.Run(t, wd+"/testdata", analyzer, pkg)
}