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) } } }