diff options
Diffstat (limited to 'internal/game/map_test.go')
| -rw-r--r-- | internal/game/map_test.go | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/internal/game/map_test.go b/internal/game/map_test.go index 9a85806..05e70d0 100644 --- a/internal/game/map_test.go +++ b/internal/game/map_test.go @@ -1,13 +1,112 @@ package game import ( + "os" + "path/filepath" + "strconv" "strings" "testing" "thehouseoficarus/internal/color" + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" "thehouseoficarus/internal/world" ) +func writeTempRoom(t *testing.T, dir string, id int, body string) { + t.Helper() + roomsDir := filepath.Join(dir, "rooms") + if err := os.MkdirAll(roomsDir, 0755); err != nil { + t.Fatal(err) + } + path := filepath.Join(roomsDir, strconv.Itoa(id)+".yaml") + if err := os.WriteFile(path, []byte(body), 0644); err != nil { + t.Fatal(err) + } +} + + +// TestMapConnectorGlyphs verifies the directional link rendering: bidirectional +// links draw a bar, one-way (or one-side-blocked) links draw a directional +// arrow, and links with no traversable direction draw a blocked 'X'. +func TestMapConnectorGlyphs(t *testing.T) { + const condEast = "name: One\nexits:\n east:\n room: 2\n condition:\n flag: gate_open\n" + + cases := []struct { + name string + room1 string + room2 string + flagOpen bool + wantPresent string + wantAbsent []string + }{ + { + name: "bidirectional bar", + room1: "name: One\nexits:\n east: 2\n", + room2: "name: Two\nexits:\n west: 1\n", + wantPresent: "-", + wantAbsent: []string{"X", "<", ">"}, + }, + { + name: "one-way east arrow", + room1: "name: One\nexits:\n east: 2\n", + room2: "name: Two\n", + wantPresent: ">", + wantAbsent: []string{"X", "-", "<"}, + }, + { + name: "forward blocked, reverse open -> arrow not X", + room1: condEast, + room2: "name: Two\nexits:\n west: 1\n", + flagOpen: false, + wantPresent: "<", + wantAbsent: []string{"X", "-", ">"}, + }, + { + name: "forward blocked, reverse absent -> X", + room1: condEast, + room2: "name: Two\n", + flagOpen: false, + wantPresent: "X", + wantAbsent: []string{"-", "<", ">"}, + }, + { + name: "conditional unblocked -> bar", + room1: condEast, + room2: "name: Two\nexits:\n west: 1\n", + flagOpen: true, + wantPresent: "-", + wantAbsent: []string{"X", "<", ">"}, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + dir := t.TempDir() + writeTempRoom(t, dir, 1, tc.room1) + writeTempRoom(t, dir, 2, tc.room2) + + g := &Game{Deps: Deps{World: world.New(dir)}, Flags: NewFlagStore()} + if tc.flagOpen { + g.Flags.Set("gate_open", true) + } + sess := &net.Session{Player: &player.Player{Flags: map[string]any{}}} + + out := strings.Join(buildTinyMap(g, sess, 1, mapGlyphsForPlayer(false)), "\n") + if !strings.Contains(out, tc.wantPresent) { + t.Errorf("want %q present:\n%s", tc.wantPresent, out) + } + for _, a := range tc.wantAbsent { + if strings.Contains(out, a) { + t.Errorf("want %q absent:\n%s", a, out) + } + } + }) + } +} + + + func TestBuildTinyMap(t *testing.T) { g := &Game{ Deps: Deps{World: world.New("../../data")}, |
