Files
code-utils/holidays_test.go

63 lines
1.7 KiB
Go
Raw Permalink Normal View History

package main
import (
"strings"
"testing"
"time"
)
func TestUpcomingHolidaysNationalDay2026(t *testing.T) {
now := time.Date(2026, 8, 17, 12, 0, 0, 0, time.Local)
list := upcomingHolidays(now, 6)
var nd *holidayItem
for i := range list {
if list[i].zh == "国庆节" {
nd = &list[i]
break
}
}
if nd == nil {
t.Fatal("2026-08 起 6 个月内应包含国庆节")
}
if nd.day.Format("2006-01-02") != "2026-10-01" {
t.Fatalf("国庆正日 got %s", nd.day.Format("2006-01-02"))
}
if nd.offStart.Format("2006-01-02") != "2026-10-01" || nd.offEnd.Format("2006-01-02") != "2026-10-07" {
t.Fatalf("国庆放假区间 got %s%s", nd.offStart.Format("2006-01-02"), nd.offEnd.Format("2006-01-02"))
}
}
func TestUpcomingHolidaysMidAutumnQixi2026(t *testing.T) {
now := time.Date(2026, 8, 17, 12, 0, 0, 0, time.Local)
got := map[string]string{}
for _, h := range upcomingHolidays(now, 6) {
got[h.zh] = h.day.Format("2006-01-02")
}
want := map[string]string{
"七夕": "2026-08-19",
"中秋节": "2026-09-25",
"重阳节": "2026-10-18",
"元旦": "2027-01-01",
"春节": "2027-02-06",
}
for name, day := range want {
if got[name] != day {
t.Errorf("%s: got %q want %s", name, got[name], day)
}
}
}
func TestFormatHolidayBlockUsesTableDates(t *testing.T) {
now := time.Date(2026, 8, 17, 12, 0, 0, 0, time.Local)
zh := formatHolidayBlock(now, false)
for _, s := range []string{"国庆节", "2026-10-01", "2026-10-07", "中秋节", "2026-09-25", "七夕", "2026-08-19"} {
if !strings.Contains(zh, s) {
t.Errorf("中文节日块缺少 %q\n%s", s, zh)
}
}
en := formatHolidayBlock(now, true)
if !strings.Contains(en, "National Day") || !strings.Contains(en, "2026-10-01") {
t.Errorf("英文节日块缺少国庆\n%s", en)
}
}