9e1958e7b0
router.WeekdayIndex reads the lexicon and asks the dictionary about the case. Four private lists go away: the habit declension map, the weekday block of the day-plan refusal, the weekday and part-of-day entries of the weather guard, and the stem list in ruwords.go. The stem list was the real defect. mentionsUnknownDay matched sred, pyatnits and subbot with strings.Contains, so sredi, sredstvo and sredniy all read as Wednesday and a question carrying one was answered with onlyNearDaysReply instead of a date. It matches whole tokens now. The weather guard was a third copy of three closed sets that already exist. It kept the rooms of the house, which are its own, and asks the lexicon for the weekdays, the parts of the day and the words that follow v without naming a place. Questions phrased v srede, v utra and v obshchem reached the geocoder as cities before. Full suite green under -race.
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package router
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestWeekdayIndexReplacesFourLists — four files kept a weekday list of their
|
|
// own and each was short in a different direction (V-581). The forms below are
|
|
// the ones at least one of those lists missed, so they are the point of having
|
|
// one matcher: the lexicon names the day and the dictionary answers the case.
|
|
func TestWeekdayIndexReplacesFourLists(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
word string
|
|
want time.Weekday
|
|
}{
|
|
{"понедельник", time.Monday},
|
|
{"понедельникам", time.Monday},
|
|
{"понедельником", time.Monday},
|
|
{"вторник", time.Tuesday},
|
|
{"среда", time.Wednesday},
|
|
{"среду", time.Wednesday},
|
|
{"среде", time.Wednesday},
|
|
{"средам", time.Wednesday},
|
|
{"четверга", time.Thursday},
|
|
{"пятницу", time.Friday},
|
|
{"субботам", time.Saturday},
|
|
{"воскресеньях", time.Sunday},
|
|
{"Воскресенье", time.Sunday},
|
|
{"monday", time.Monday},
|
|
{"Fridays", time.Friday},
|
|
} {
|
|
got, ok := WeekdayIndex(tc.word)
|
|
if !ok || got != tc.want {
|
|
t.Errorf("WeekdayIndex(%q) = %v, %v; want %v, true", tc.word, got, ok, tc.want)
|
|
}
|
|
}
|
|
// A stem match said yes to all of these. A word match says no.
|
|
for _, w := range []string{"среди", "средство", "средний", "среднем", "субботник", "", "через"} {
|
|
if _, ok := WeekdayIndex(w); ok {
|
|
t.Errorf("WeekdayIndex(%q) claimed a weekday", w)
|
|
}
|
|
}
|
|
}
|