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
|
package spell
import "testing"
func loadT(t *testing.T) *Dict {
t.Helper()
d, err := Load()
if err != nil {
t.Fatalf("Load: %v", err)
}
return d
}
func TestKnownCommonWords(t *testing.T) {
d := loadT(t)
for _, w := range []string{"the", "receive", "separate", "believe", "government", "markdown", "editor"} {
if !d.Known(w) {
t.Errorf("Known(%q) = false, want true", w)
}
}
}
func TestUnknownTypos(t *testing.T) {
d := loadT(t)
for _, w := range []string{"recieve", "seperate", "definately", "teh", "qwertyx"} {
if d.Known(w) {
t.Errorf("Known(%q) = true, want false (typo)", w)
}
}
}
func TestKnownCaseInsensitive(t *testing.T) {
d := loadT(t)
for _, w := range []string{"The", "RECEIVE", "Government"} {
if !d.Known(w) {
t.Errorf("Known(%q) = false, want true (case-insensitive)", w)
}
}
}
func TestKnownPossessiveAndPlural(t *testing.T) {
d := loadT(t)
// Possessive of a known word is accepted leniently even if the exact
// possessive form isn't a dictionary entry.
for _, w := range []string{"government's", "editor's", "markdown's"} {
if !d.Known(w) {
t.Errorf("Known(%q) = false, want true (possessive of known word)", w)
}
}
}
func TestKnownContractions(t *testing.T) {
d := loadT(t)
// Common English contractions are known regardless of case or apostrophe
// style (straight or curly), and are not flagged as misspellings.
cases := []string{
"isn't", "won't", "don't", "can't", "didn't", "doesn't", "wouldn't",
"couldn't", "shouldn't", "aren't", "wasn't", "weren't", "hasn't", "haven't",
"I'd", "I'll", "I'm", "I've", "you're", "we're", "they're", "they've",
"it's", "that's", "there's", "who's", "let's", "he'll", "she'd",
"y'all", "o'clock",
"ISN'T", "Don't", // case-insensitive
"isn’t", "I’d", // curly apostrophe
}
for _, w := range cases {
if !d.Known(w) {
t.Errorf("Known(%q) = false, want true (contraction)", w)
}
}
}
func TestUnknownFakeContractions(t *testing.T) {
d := loadT(t)
// Apostrophe tokens that aren't real contractions still get flagged.
for _, w := range []string{"qwerty'll", "teh's", "xyzzy'd"} {
if d.Known(w) {
t.Errorf("Known(%q) = true, want false (not a real contraction)", w)
}
}
}
|