ea9c746852
The hand-written table understood "какая погода в X" for six values of X. Ask about Kazan or Tbilisi and the city was dropped silently and answered for the default location — a correct-sounding answer about the wrong place. The table is gone. internal/weather already calls Open-Meteo's geocoding endpoint on every lookup, so the place he named goes straight there and any place it knows is a place he can ask about. He speaks the prepositional case, so locationCandidates reverses the two endings that cover most of it: a final "е" is a nominative "а" or nothing, a final "и" is a soft sign. A wrong candidate finds no city; it never invents one. A place the geocoder does not have now reads as "не знаю такого города" rather than as a provider outage or, worse, as the default city's weather. ErrLocationUnknown is what carries that apart. "в" followed by a room or a day word is still the default location. Those questions are answered by the house sensors and the calendar, not by Open-Meteo, and they must not be read as a city.
34 lines
1.4 KiB
Go
34 lines
1.4 KiB
Go
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)
|
|
}
|
|
}
|
|
}
|