package svg import ( "encoding/xml" "errors" "io" "math" "strings" "testing" "time" "b612.me/astro/internal/svgmap" ) func TestLunarEclipseMapSVGVisibilityRegions(t *testing.T) { diagram, ok := LunarEclipseMapSVG( time.Date(2026, 3, 3, 0, 0, 0, 0, time.UTC), LunarEclipseMapSVGOptions{Width: 900, Height: 620, Location: time.UTC}, ) if !ok { t.Fatal("expected lunar-eclipse visibility map") } for _, want := range []string{ "月全食全球可见图", "P1", "P4", "食甚", "全程可见", "带食月出", "带食月落", "不可见", `class="entire-eclipse-region"`, "moonrise-region", "moonset-region", `class="p1-horizon"`, `class="p4-horizon"`, `class="land"`, "不含行政边界", } { if !strings.Contains(diagram, want) { t.Fatalf("lunar-eclipse map missing %q", want) } } if err := validateEclipseMapXML(diagram); err != nil { t.Fatalf("lunar-eclipse map is not valid XML: %v", err) } } func TestLunarEclipseMapSVGUsesExclusiveVisibilityLayers(t *testing.T) { cst := time.FixedZone("CST", 8*60*60) diagram, ok := LunarEclipseMapSVG( time.Date(2029, 1, 1, 0, 0, 0, 0, cst), LunarEclipseMapSVGOptions{Width: 1200, Height: 800, Location: cst}, ) if !ok { t.Fatal("expected lunar-eclipse visibility map") } for _, want := range []string{ `mask id="lunar-not-visible-mask"`, `mask id="lunar-not-p4-mask"`, `mask id="lunar-not-p1-mask"`, `class="eclipse-unavailable-region" mask="url(#lunar-not-visible-mask)"`, `class="visible-at-p1 moonset-region" mask="url(#lunar-not-p4-mask)"`, `class="visible-at-p4 moonrise-region" mask="url(#lunar-not-p1-mask)"`, } { if !strings.Contains(diagram, want) { t.Fatalf("lunar-eclipse map does not render exclusive visibility regions: missing %q", want) } } if strings.Contains(diagram, `class="entire-eclipse-region"`) && strings.Contains(diagram, `fill-opacity="0.70"`) { t.Fatal("entire-eclipse region still uses the opaque stacked-overlay style") } } func TestLunarEclipseMapSVGSupportsForcedPolarProjection(t *testing.T) { diagram, ok := LunarEclipseMapSVG( time.Date(2026, 3, 3, 0, 0, 0, 0, time.UTC), LunarEclipseMapSVGOptions{Projection: EclipseMapProjectionSouthPolar}, ) if !ok { t.Fatal("expected forced south-polar lunar-eclipse map") } for _, want := range []string{`