package main import ( "strings" "testing" "time" ) // "когда я это сделал?" answers off a fact's Ts, which the store hands back as // UTC, and the branch that names a wall clock printed it in whatever zone it // arrived in (V-614). The instant here is built three hours off this machine's // zone, so the assertion holds under TZ=UTC as well. func TestFormatTimeReadsHisClock(t *testing.T) { _, off := time.Now().Zone() away := time.FixedZone("away", off+3*60*60) stored := time.Now().Add(-72 * time.Hour).In(away) got := formatTime(stored) if want := stored.Local().Format("15:04"); !strings.Contains(got, want) { t.Errorf("formatTime = %q, want the hour on his clock (%s)", got, want) } if bad := stored.Format("15:04"); strings.Contains(got, bad) { t.Errorf("formatTime = %q reads the zone the fact arrived in (%s)", got, bad) } } // TestMentionsUnknownDayReadsWordsNotStems — the defect V-581 found. The // weekday half of this guard was a list of stems matched with strings.Contains, // so "среди", "средство" and "средний" all read as Wednesday and the question // was answered with onlyNearDaysReply instead of a date. // // The other half of the fix is coverage: a stem list stops at the forms whoever // wrote it thought of, and "воскресеньях" was not one of them. func TestMentionsUnknownDayReadsWordsNotStems(t *testing.T) { for _, u := range []string{ "какое число в понедельник", "какое число в среду", "какое число в среде", "что там по воскресеньям", "what is the date on friday", "какое число через неделю", } { if !mentionsUnknownDay(u) { t.Errorf("mentionsUnknownDay(%q) = false, want true", u) } } for _, u := range []string{ "какое число в среднем", "сколько это в среднем", "какое сегодня средство", "какое число", } { if mentionsUnknownDay(u) { t.Errorf("mentionsUnknownDay(%q) = true; it names no day", u) } } }