oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import (
4 "amadan.net/oficina/mapa/internal/mapa/locale"
5
6 "strings"
7 "testing"
8 "time"
9)
10
11// Weeks start on Monday in en-IE (level-up §4.4), and on the reader's
12// locale's first day elsewhere (build note 85), whatever day they are
13// asked from.
14func TestWeeksStartOnTheLocalesFirstDay(t *testing.T) {
15 for date, want := range map[string]string{
16 "2026-11-14": "2026-11-09", "2026-11-09": "2026-11-09",
17 "2026-11-15": "2026-11-09", "2026-11-16": "2026-11-16",
18 } {
19 day, _ := time.Parse(time.DateOnly, date)
20 if got := iso(locale.Get("en-IE").WeekStart(day)); got != want {
21 t.Errorf("en-IE: the week of %s starts %s, want %s", date,
22 got, want)
23 }
24 }
25 for date, want := range map[string]string{
26 "2026-11-14": "2026-11-08", "2026-11-15": "2026-11-15",
27 } {
28 day, _ := time.Parse(time.DateOnly, date)
29 if got := iso(locale.Get("en-US").WeekStart(day)); got != want {
30 t.Errorf("en-US: the week of %s starts %s, want %s", date,
31 got, want)
32 }
33 }
34}
35
36// The map is the same drawing every time for the same ring, and says
37// itself in words for anyone who cannot see it (§4.3).
38func TestTheMapIsStableAndLabelled(t *testing.T) {
39 ring := []neighbour{{label: "Halden", href: "/p/a", kind: "linked"},
40 {label: "Pricing", href: "/new?title=Pricing", kind: "pending"},
41 {label: "Q4", href: "/p/b", kind: "mentioned"}}
42 here := &entry{kind: KindPage, rung: RungTeam,
43 record: Record{Title: "Acme"}}
44 view := (&Index{}).in(Scope{})
45 one, other := view.mapOf(here, ring), view.mapOf(here, ring)
46 if len(one.Nodes) != 3 || len(one.Edges) != 3 {
47 t.Fatalf("map: %d nodes, %d edges", len(one.Nodes), len(one.Edges))
48 }
49 for at := range one.Nodes {
50 if one.Nodes[at] != other.Nodes[at] {
51 t.Fatal("the same ring drew two maps")
52 }
53 node := one.Nodes[at]
54 if node.X < 0 || node.X > mapW || node.Y < 0 || node.Y > mapH {
55 t.Errorf("%s is off the map: %v,%v", node.Label, node.X, node.Y)
56 }
57 }
58 for _, words := range []string{"Acme", "Halden (linked)",
59 "Pricing (not written yet)", "Q4 (mentioned without a link)"} {
60 if !strings.Contains(one.Label, words) {
61 t.Errorf("the map's label lacks %q: %s", words, one.Label)
62 }
63 }
64}
65