-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
92 lines (73 loc) · 1.85 KB
/
main_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
package main
import (
"go/ast"
"go/token"
"testing"
"github.com/trustmaster/go-aspell"
)
var (
speller aspell.Speller
)
func TestCheckString(t *testing.T) {
speller, err := aspell.NewSpeller(map[string]string{
"lang": "en_US",
})
if err != nil {
panic(err)
}
defer speller.Delete()
cases := map[string][]result{
"asdfasdf ": {{0, 8, "asdfasdf"}},
"asdfasdf": {{0, 8, "asdfasdf"}},
"hello asdfasdf": {{6, 14, "asdfasdf"}},
" asdfasdf ": {{1, 9, "asdfasdf"}},
"AsdfasdfHello": {{0, 8, "Asdfasdf"}},
}
splitCamelCase = true
for input, output := range cases {
realOutput := checkString(speller, input)
if len(realOutput) != len(output) {
t.Errorf("Poop %v %v %v", input, output, realOutput)
} else {
for i := 0; i < len(output); i++ {
if !realOutput[i].SameAs(output[i]) {
t.Errorf("Poop %v %v %v", input, output, realOutput)
}
}
}
}
}
func ExampleCheckComment() {
splitCamelCase = false
speller, err := aspell.NewSpeller(map[string]string{
"lang": "en_US",
})
if err != nil {
panic(err)
}
comment := &ast.Comment{Slash: 1, Text: "// Spellign Msitake spellingMistake SpellingMistake"}
fs := token.NewFileSet()
fs.AddFile("/foo/bar/baz.go", 1, 2048)
checkComment(speller, fs, comment)
// Output:
///foo/bar/baz.go:1:4: Spellign
///foo/bar/baz.go:1:13: Msitake
///foo/bar/baz.go:1:21: spellingMistake
///foo/bar/baz.go:1:37: SpellingMistake
}
func ExampleCheckComment_camel() {
splitCamelCase = true
speller, err := aspell.NewSpeller(map[string]string{
"lang": "en_US",
})
if err != nil {
panic(err)
}
comment := &ast.Comment{Slash: 1, Text: "// Spellign Msitake spellingMistake SpellingMistake"}
fs := token.NewFileSet()
fs.AddFile("/foo/bar/baz.go", 1, 2048)
checkComment(speller, fs, comment)
// Output:
///foo/bar/baz.go:1:4: Spellign
///foo/bar/baz.go:1:13: Msitake
}