package router import "testing" func TestParseFeedQuery(t *testing.T) { cases := []struct { text string ok bool category string }{ {"что нового в лентах?", true, ""}, {"что нового?", true, ""}, {"какие новости?", true, ""}, {"что нового по технологиям?", true, "технологиям"}, {"расскажи новости про политику", true, "политику"}, {"что нового по новостям", true, ""}, {"what's new in the feeds?", true, ""}, {"any news about kubernetes", true, "kubernetes"}, // Statements, not requests. {"у меня новая лента в инстаграме", false, ""}, {"новости меня утомили", false, ""}, {"напомни полить цветы", false, ""}, {"", false, ""}, } for _, c := range cases { q, ok := ParseFeedQuery(c.text) if ok != c.ok { t.Errorf("ParseFeedQuery(%q) ok = %v, want %v", c.text, ok, c.ok) continue } if ok && q.Category != c.category { t.Errorf("ParseFeedQuery(%q) category = %q, want %q", c.text, q.Category, c.category) } } } func TestCategoryMatches(t *testing.T) { // The inflected form he says must match the form the config spells. if !CategoryMatches("Новый релиз [технологии]", "технологиям") { t.Error("inflected category did not match") } if CategoryMatches("Новый релиз [технологии]", "политику") { t.Error("unrelated category matched") } if !CategoryMatches("anything", "") { t.Error("an empty category must match everything") } }