package router import ( "testing" "time" ) func TestParseHabitQuery(t *testing.T) { tests := []struct { in string ok bool wd time.Weekday hasWD bool }{ {"что я обычно делаю по вторникам?", true, time.Tuesday, true}, {"что я обычно делаю?", true, 0, false}, {"какие у меня привычки", true, 0, false}, {"что я каждую пятницу делаю", true, time.Friday, true}, {"what do i usually do on mondays?", true, time.Monday, true}, // No habit marker: this is a question about the coming Wednesday, and // the calendar owns it. Answering with an average answers the wrong // question. {"что я делаю в среду?", false, 0, false}, {"что у меня сегодня?", false, 0, false}, {"какие планы на сегодня?", false, 0, false}, {"", false, 0, false}, } for _, tt := range tests { q, ok := ParseHabitQuery(tt.in) if ok != tt.ok { t.Errorf("ParseHabitQuery(%q) ok = %v, want %v", tt.in, ok, tt.ok) continue } if !ok { continue } if q.HasWeekday != tt.hasWD { t.Errorf("ParseHabitQuery(%q) hasWeekday = %v, want %v", tt.in, q.HasWeekday, tt.hasWD) continue } if q.HasWeekday && q.Weekday != tt.wd { t.Errorf("ParseHabitQuery(%q) weekday = %v, want %v", tt.in, q.Weekday, tt.wd) } } } // TestHabitQueryBeatsDayPlan — "какие у меня обычно планы по вторникам?" is a // habit question that happens to carry a plan word. The day plan claimed it // first and answered today's calendar stamped with today's date, and the habit // source never ran. func TestHabitQueryBeatsDayPlan(t *testing.T) { for _, q := range []string{ "какие у меня обычно планы по вторникам?", "что обычно по плану в среду?", "какие планы обычно по выходным?", } { if IsDayPlanQuery(q) { t.Errorf("%q was claimed as a day plan", q) } if _, ok := ParseHabitQuery(q); !ok { t.Errorf("%q is not parsed as a habit question", q) } } // A plan question without a habit marker still belongs to the day plan. for _, q := range []string{"какие планы на сегодня?", "что у меня по плану?"} { if !IsDayPlanQuery(q) { t.Errorf("%q must still be a day plan", q) } } } // TestHabitQueryWeekendAndSundayForms — "по выходным" names days but no // weekday, so it used to be answered with the whole-week profile. Sunday had // only its dative plural listed. func TestHabitQueryWeekendAndSundayForms(t *testing.T) { q, ok := ParseHabitQuery("что я обычно делаю по выходным?") if !ok || !q.Weekend || q.HasWeekday { t.Errorf("weekend query parsed as %+v (ok=%v)", q, ok) } for _, s := range []string{ "что я обычно делаю в воскресенье?", "чем я обычно занят по воскресеньям?", "что обычно бывает в воскресенья?", } { q, ok := ParseHabitQuery(s) if !ok || !q.HasWeekday || q.Weekday != time.Sunday { t.Errorf("%q parsed as %+v (ok=%v)", s, q, ok) } } }