clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

main
atlas / internal / generate / curation / curation_test.go
curation_test.go 4.7K
1package curation23import (4 "strings"5 "testing"6)78// TestEmbeddedCorpus holds the shipped curation to what it is curating. Every9// row here is an editorial decision carried over from the tree these tables10// were extracted from, and a row that disappears is a volume quietly composed11// differently, so each is named rather than counted.12func TestEmbeddedCorpus(t *testing.T) {13 tables, err := Load()14 if err != nil {15 t.Fatalf("load: %v", err)16 }1718 t.Run("shared window", func(t *testing.T) {19 if tables.Window.SourceZoom != 13 || tables.Window.FirstTile != 4064 {20 t.Errorf("shared window is %+v, want zoom 13 from tile 4064", tables.Window)21 }22 })2324 t.Run("world order", func(t *testing.T) {25 preferred := tables.PreferredWorlds("fallout-new-vegas")26 if len(preferred) != 1 || preferred[0] != "mojave-wasteland" {27 t.Errorf("fallout-new-vegas prefers %v", preferred)28 }29 if tables.PreferredWorlds("tunic") != nil {30 t.Errorf("tunic is curated for order and should not be")31 }32 if !tables.NewestFirst("bend-or") {33 t.Errorf("bend-or is a version history and should read newest first")34 }35 if tables.NewestFirst("tunic") {36 t.Errorf("tunic is not a version history")37 }38 })3940 t.Run("icon outset", func(t *testing.T) {41 tests := []struct {42 volume, world, want string43 }{44 {"clair-obscur-expedition-33", "anything", "dark"},45 {"cyberpunk-2077", "night-city", "dark"},46 {"fallout-new-vegas", "mojave-wasteland", "dark"},47 {"fallout76", "appalachia", "dark"},48 {"la-noire", "los-angeles", "dark"},49 {"mars", "global", "dark"},50 {"sonic-frontiers", "anything", "dark"},51 {"skyrim", "skyrim", "dark"},52 {"skyrim", "solstheim", "dark"},53 {"skyrim", "somewhere-else", ""},54 {"tunic", "world", ""},55 }56 for _, tt := range tests {57 if got := tables.IconOutset(tt.volume, tt.world); got != tt.want {58 t.Errorf("IconOutset(%q, %q) = %q, want %q", tt.volume, tt.world, got, tt.want)59 }60 }61 })6263 t.Run("shard", func(t *testing.T) {64 tests := []struct {65 volume, world string66 want ShardMode67 }{68 {"fallout-new-vegas", "mojave-wasteland", ShardIntoWorlds},69 {"zelda-tears-of-the-kingdom", "hyrule", ShardIntoLenses},70 {"fallout-new-vegas", "sierra-madre", ShardNone},71 {"tunic", "world", ShardNone},72 }73 for _, tt := range tests {74 if got := tables.Shard(tt.volume, tt.world); got != tt.want {75 t.Errorf("Shard(%q, %q) = %q, want %q", tt.volume, tt.world, got, tt.want)76 }77 }78 })7980 t.Run("collection equivalents", func(t *testing.T) {81 want := map[string]string{82 "ripper-doc": "ripperdoc",83 "tarot-card": "tarot-graffiti",84 "gun-shop": "weapon-shop",85 "clothes-shop": "clothing-vendor",86 "medicine-shop": "medpoint",87 "melee-shop": "melee-vendor",88 "netrunner-shop": "netrunner",89 }90 for key, shared := range want {91 if got := tables.CollectionEquivalent("cyberpunk-2077", key); got != shared {92 t.Errorf("cyberpunk-2077 %q meets under %q, want %q", key, got, shared)93 }94 }95 if got := tables.CollectionEquivalent("tunic", "fox_shrine"); got != "" {96 t.Errorf("tunic curates an equivalence it should not: %q", got)97 }98 if got := tables.CollectionEquivalent("cyberpunk-2077", "what"); got != "" {99 t.Errorf("an uncurated key answered %q", got)100 }101 })102}103104func TestParseRefusals(t *testing.T) {105 tests := []struct {106 name string107 data string108 want string109 }{110 {"a schema from the future", `{"schema":99}`, "schema 99"},111 {"no shared window", `{"schema":1}`, "no shared tile window"},112 {113 "an unknown shard mode",114 `{"schema":1,"window":{"sourceZoom":13,"firstTile":4064},115 "shard":{"worlds":{"a/b":"halves"}}}`,116 "shard mode \"halves\"",117 },118 {119 "a shard key naming no world",120 `{"schema":1,"window":{"sourceZoom":13,"firstTile":4064},121 "shard":{"worlds":{"a":"worlds"}}}`,122 "names no world",123 },124 {125 "an outset key naming no world",126 `{"schema":1,"window":{"sourceZoom":13,"firstTile":4064},127 "iconOutset":{"byWorld":{"a":"dark"}}}`,128 "names no world",129 },130 {"not JSON at all", `{`, "decode curation"},131 }132 for _, tt := range tests {133 t.Run(tt.name, func(t *testing.T) {134 _, err := LoadFrom([]byte(tt.data))135 if err == nil {136 t.Fatalf("accepted, want a refusal naming %q", tt.want)137 }138 if !strings.Contains(err.Error(), tt.want) {139 t.Fatalf("refused with %q, want it to name %q", err, tt.want)140 }141 })142 }143}144145// TestProseKeysAreNotVolumes holds the file's one habit: every section carries146// its reasoning beside its data, and a prose key must never be read as an147// entry.148func TestProseKeysAreNotVolumes(t *testing.T) {149 tables, err := Load()150 if err != nil {151 t.Fatal(err)152 }153 if got := tables.CollectionEquivalent("what", "anything"); got != "" {154 t.Errorf("the equivalents table read its own prose as a volume: %q", got)155 }156}