package lang_test import ( "testing" "git.vakhrushev.me/av/convy/internal/lang" ) func TestLeadTakesLongestMatch(t *testing.T) { v, err := lang.Lookup(1, "ru") if err != nil { t.Fatal(err) } cases := []struct { text string want string }{ {"ДОЛЖЕН.", "ДОЛЖЕН"}, {"НЕ ДОЛЖЕН.", "НЕ ДОЛЖЕН"}, {"НЕ СЛЕДУЕТ.", "НЕ СЛЕДУЕТ"}, {"СЛЕДУЕТ.", "СЛЕДУЕТ"}, {"СНЯТО 2026-07-26.", "СНЯТО"}, {"ПОЧЕМУ.", "ПОЧЕМУ"}, {"", ""}, {"Заголовок правила", ""}, {"ДОЛЖЕНСТВОВАНИЕ", ""}, } for _, tc := range cases { got, ok := v.Lead(tc.text) if tc.want == "" { if ok { t.Errorf("Lead(%q) = %q, wanted no word to be found", tc.text, got) } continue } if !ok || got != tc.want { t.Errorf("Lead(%q) = %q, %v; wanted %q", tc.text, got, ok, tc.want) } } } func TestForeignExcludesOwnWords(t *testing.T) { foreign := lang.Foreign(1, "ru") if len(foreign) == 0 { t.Fatal("the Russian vocabulary yielded no foreign word at all") } if code, ok := foreign["MUST"]; !ok || code != "en" { t.Errorf("MUST should be recognized as a word of the en vocabulary, got %q, %v", code, ok) } v, err := lang.Lookup(1, "ru") if err != nil { t.Fatal(err) } for word := range foreign { if _, own := v.Modal(word); own { t.Errorf("the word %q is the suite's own, yet landed among the foreign ones", word) } if _, own := v.Mark(word); own { t.Errorf("the mark %q is the suite's own, yet landed among the foreign ones", word) } } } func TestUnknownVersionAndCode(t *testing.T) { if _, err := lang.Lookup(99, "ru"); err == nil { t.Error("an unknown language version was accepted without an error") } if _, err := lang.Lookup(1, "xx"); err == nil { t.Error("an unknown vocabulary was accepted without an error") } }