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"}, // "что нового?" is a greeting. Claiming it made the shipping daemon // answer hello with "я пока не читаю ленты — они не настроены". {"что нового?", false, ""}, {"ну что нового", false, ""}, // A stray "о" is not a topic marker. {"что нового в лентах, о боже", true, ""}, // 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") } // The tag, not the note. The link in a tech headline is not a weather report. if CategoryMatches("технологии", "погоду") { t.Error("a tech note matched a weather question") } if !CategoryMatches("anything", "") { t.Error("an empty category must match everything") } }