Files
Maven/internal/router/agendaq_test.go
T
claude 6e3bb3be97 each agenda grammar is tested against its own example (V-552)
Replaces a test whose name promised more than its body checked: it
looped the grammars asserting Pattern != nil, which regexp.MustCompile
already guarantees at init. Asserting the grammars pass IsAgendaQuestion
would be true by construction, since the first arm is that same loop.

A hand-written example per grammar name catches what neither does: a
grammar edited until it no longer matches the case its comment gives,
and a new grammar nobody wrote an example for.
2026-08-05 21:40:49 +04:00

67 lines
2.7 KiB
Go

package router
import "testing"
// The four utterances in Vikunja #552 plus the ones that must keep reaching
// the calendar. The list is the whole point of the predicate: every "want
// false" row was answered "на 05.08.2026 ничего нет" on the deployed daemon.
func TestIsAgendaQuestionSeparatesHisDayFromTheWorld(t *testing.T) {
tests := []struct {
utterance string
want bool
}{
// His day.
{"что у меня сегодня", true},
{"во сколько у меня встреча сегодня", true},
{"что в календаре на завтра", true},
{"какие планы на завтра", true},
{"какие встречи завтра", true},
{"когда планёрка", true},
{"покажи расписание на среду", true},
{"что дальше?", true},
// No subject of its own, so his day by default.
{"что сегодня?", true},
{"что на завтра", true},
{"что там в среду?", true},
// The world, naming a day. Every one of these is #552.
{"во сколько закат сегодня", false},
{"какой сегодня курс доллара", false},
{"какой сегодня праздник", false},
{"что интересного произошло сегодня в мире", false},
{"кто выиграл вчера матч", false},
// A day word plus a subject is never subjectless, however short.
{"что за праздник сегодня", false},
}
for _, tt := range tests {
if got := IsAgendaQuestion(tt.utterance); got != tt.want {
t.Errorf("IsAgendaQuestion(%q) = %v, want %v", tt.utterance, got, tt.want)
}
}
}
// One hand-written utterance per agenda grammar, keyed by name. Asserting that
// the grammars pass IsAgendaQuestion would be true by construction, since the
// first arm is the loop over them. This asserts something else: that each
// grammar still matches the case its own comment gives, and that the set of
// grammars has not grown a member nobody wrote an example for.
func TestEachAgendaGrammarStillMatchesItsOwnExample(t *testing.T) {
examples := map[string]string{
"calendar-query": "что в календаре на завтра",
"agenda-query": "что у меня сегодня",
"plan-day-query": "какие планы на завтра",
"rest-of-day-query": "что дальше?",
"event-time-query": "когда планёрка",
}
for _, g := range AgendaQueryGrammars() {
u, ok := examples[g.Name]
if !ok {
t.Errorf("agenda grammar %q has no example here — add one", g.Name)
continue
}
if !g.Pattern.MatchString(u) {
t.Errorf("grammar %q no longer matches %q", g.Name, u)
}
}
}