d00929ac0b
replySystem had two arms that PR 30 made reachable, and both answered confidently wrong: the date arm keyword-matched "числ" and always answered today, so "какое число завтра" answered today; the clock arm ignored a named city and answered local time. The date arm now reads the day word through router.ParseCalendarDate (which grew послезавтра/вчера and now cuts the day boundary in the local zone instead of UTC). The clock arm answers the named zone when it resolves offline from the tz database embedded in the binary, and otherwise says plainly that she only knows local time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CGeSZxh1DCtRxmFVSYVGvJ
62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package router
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Russian capture must produce the same keys the loop's care rules read, or a
|
|
// ru voice test silently writes nothing and the nudges look broken.
|
|
func TestDefaultFactParserRU(t *testing.T) {
|
|
p := DefaultFactParser{}
|
|
cases := []struct {
|
|
utterance string
|
|
key string
|
|
ok bool
|
|
}{
|
|
{"выпил воды", "water", true},
|
|
{"попил воду", "water", true},
|
|
{"я поел", "meal", true},
|
|
{"пообедал", "meal", true},
|
|
{"принял душ", "shower", true},
|
|
{"сделал перерыв", "break", true},
|
|
{"немного отдохнул", "break", true},
|
|
{"поспал шесть часов", "sleep", true},
|
|
{"перезапусти nginx", "", false}, // an act, not a fact
|
|
}
|
|
for _, c := range cases {
|
|
k, _, ok := p.Parse(c.utterance)
|
|
if ok != c.ok || k != c.key {
|
|
t.Errorf("Parse(%q) = (%q, %v), want (%q, %v)", c.utterance, k, ok, c.key, c.ok)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseCalendarDate(t *testing.T) {
|
|
now := time.Date(2026, 7, 6, 14, 30, 0, 0, time.UTC)
|
|
cases := []struct {
|
|
text string
|
|
want time.Time
|
|
ok bool
|
|
}{
|
|
{"что у меня сегодня по плану", time.Date(2026, 7, 6, 0, 0, 0, 0, time.UTC), true},
|
|
{"что завтра", time.Date(2026, 7, 7, 0, 0, 0, 0, time.UTC), true},
|
|
{"планы на сегодня", time.Date(2026, 7, 6, 0, 0, 0, 0, time.UTC), true},
|
|
{"расписание на завтра", time.Date(2026, 7, 7, 0, 0, 0, 0, time.UTC), true},
|
|
{"what's today", time.Date(2026, 7, 6, 0, 0, 0, 0, time.UTC), true},
|
|
{"tomorrow plans", time.Date(2026, 7, 7, 0, 0, 0, 0, time.UTC), true},
|
|
{"какое число послезавтра", time.Date(2026, 7, 8, 0, 0, 0, 0, time.UTC), true},
|
|
{"что было вчера", time.Date(2026, 7, 5, 0, 0, 0, 0, time.UTC), true},
|
|
{"yesterday plans", time.Date(2026, 7, 5, 0, 0, 0, 0, time.UTC), true},
|
|
{"какая погода", time.Time{}, false},
|
|
{"сколько времени", time.Time{}, false},
|
|
{"", time.Time{}, false},
|
|
}
|
|
for _, c := range cases {
|
|
got, ok := ParseCalendarDate(c.text, now)
|
|
if ok != c.ok || !got.Equal(c.want) {
|
|
t.Errorf("ParseCalendarDate(%q) = %v, %v; want %v, %v", c.text, got, ok, c.want, c.ok)
|
|
}
|
|
}
|
|
}
|