package router import "testing" func TestParseTaskStatus(t *testing.T) { cases := []struct { utterance string ok bool status string text string }{ // The shapes that reached nothing before this rule. {"закрой задачу купить молоко", true, "done", "купить молоко"}, {"задачу купить молоко сделал", true, "done", "купить молоко"}, {"убери из задач купить молоко", true, "dropped", "купить молоко"}, {"убери из моих задач купить молоко", true, "dropped", "купить молоко"}, {"отмени задачу оплатить интернет", true, "dropped", "оплатить интернет"}, {"task buy milk done", true, "done", "buy milk"}, // The referent may be missing. The turn is still his, and the daemon has // the list to ask about. {"закрой задачу", true, "done", ""}, {"убери задачу", true, "dropped", ""}, // No board noun: ordinary speech, and every one of these means something // else. "закрой" alone belongs to Praxis. {"готово", false, "", ""}, {"закрой", false, "", ""}, {"убери со стола", false, "", ""}, {"я всё сделал", false, "", ""}, {"закрой шторы в комнате", false, "", ""}, // The board noun with no status word is a list query, not a move. {"какие у меня задачи", false, "", ""}, {"добавь в задачи купить молоко", false, "", ""}, // Two transitions in one sentence. Asking beats picking. {"задачу купить молоко готово убери", false, "", ""}, {"", false, "", ""}, } for _, c := range cases { got, ok := ParseTaskStatus(c.utterance) if ok != c.ok { t.Errorf("ParseTaskStatus(%q) ok = %v, want %v", c.utterance, ok, c.ok) continue } if !ok { continue } if got.Status != c.status || got.Text != c.text { t.Errorf("ParseTaskStatus(%q) = %+v, want status %q text %q", c.utterance, got, c.status, c.text) } } } func TestTaskStatusGrammarFillsTheFnSlot(t *testing.T) { g := TaskStatusGrammar() m := g.Pattern.FindStringSubmatch("закрой задачу купить молоко") if m == nil { t.Fatal("pattern did not match") } dec, ok := g.Build(m) if !ok { t.Fatal("Build declined") } if dec.Intent != IntentAct || !dec.Slots.HasFn || dec.Slots.Fn != TaskStatusFn { t.Fatalf("decision = %+v, want act with fn %q", dec, TaskStatusFn) } if dec.Slots.Value != "done" || dec.Slots.Text != "купить молоко" { t.Fatalf("slots = %+v, want value done text \"купить молоко\"", dec.Slots) } }