package main import "testing" // TestExtractWeatherLocation — any place he names comes through, not just the // six that used to be in a table (Vikunja #421). func TestExtractWeatherLocation(t *testing.T) { cases := []struct { utterance string def string want string }{ // The cities the table had, and the ones it silently dropped. {"какая погода в Москве", "Berlin", "Москве"}, {"какая погода в Казани", "Berlin", "Казани"}, {"погода в Тбилиси?", "Berlin", "Тбилиси"}, {"what's the weather in New York", "Berlin", "New York"}, {"тепло в Нижнем Новгороде?", "Berlin", "Нижнем Новгороде"}, // He named nothing: the configured default, and nothing at all when // there is no default. {"какая сегодня погода", "Berlin", "Berlin"}, {"какая сегодня погода", "", ""}, // "в" followed by something that is not a place stays the default — // the house sensors and the day words answer elsewhere. {"тепло в комнате?", "Berlin", "Berlin"}, {"какая погода в выходные", "Berlin", "Berlin"}, } for _, c := range cases { if got := extractWeatherLocation(c.utterance, c.def); got != c.want { t.Errorf("extractWeatherLocation(%q, %q) = %q, want %q", c.utterance, c.def, got, c.want) } } }