package router import "testing" func TestParseMoneyQuery(t *testing.T) { cases := []struct { in string window MoneyWindow ok bool }{ {"сколько я потратил сегодня?", MoneyToday, true}, {"сколько я потратил в этом месяце?", MoneyMonth, true}, {"сколько я потратил?", MoneyMonth, true}, // month-to-date by default {"покажи мои траты", MoneyMonth, true}, {"какие у меня расходы за месяц", MoneyMonth, true}, {"how much did I spend today", MoneyToday, true}, {"сколько я заработал в этом месяце", MoneyMonth, true}, // Windows nothing is stored for are claimed and refused, never answered // with the month-to-date figure. {"сколько я потратил вчера?", MoneyUnsupported, true}, {"сколько я потратил на прошлой неделе?", MoneyUnsupported, true}, {"how much did I spend yesterday", MoneyUnsupported, true}, // Not about money. {"я потратил весь день на это", MoneyNone, false}, // A statement, not a question: the noun and the ask must be independent // evidence, and "траты" used to satisfy both halves on its own. {"у меня в этом месяце большие траты", MoneyNone, false}, {"потратил много сил", MoneyNone, false}, {"какая погода?", MoneyNone, false}, {"я купил молоко", MoneyNone, false}, {"", MoneyNone, false}, } for _, c := range cases { q, ok := ParseMoneyQuery(c.in) if ok != c.ok || q.Window != c.window { t.Errorf("ParseMoneyQuery(%q) = (%v, %v), want (%v, %v)", c.in, q.Window, ok, c.window, c.ok) } } } // TestMoneyFormsTheOldListMissed — the point of matching through the dictionary // (Vikunja #529). Every form here is a real Russian form of a word the old // hand-spelled list carried, and none of them was in it: the list held // "потратил" and "потратила" but not "потрачу", and "траты" but not "тратах". func TestMoneyFormsTheOldListMissed(t *testing.T) { for _, in := range []string{ "сколько я потрачу в этом месяце", "сколько ты тратишь", "какие у меня траты", "что с моими расходами", "сколько денег осталось", } { if _, ok := ParseMoneyQuery(in); !ok { t.Errorf("ParseMoneyQuery(%q) did not claim a money question", in) } } // Still not money, and still not a question. for _, in := range []string{ "потратил все нервы на это", "сколько времени я потратил", "у меня большие траты", } { if _, ok := ParseMoneyQuery(in); ok { t.Errorf("ParseMoneyQuery(%q) claimed a money question", in) } } }