diff options
Diffstat (limited to 'internal/game/map_test.go')
| -rw-r--r-- | internal/game/map_test.go | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/internal/game/map_test.go b/internal/game/map_test.go index ebb2197..712202b 100644 --- a/internal/game/map_test.go +++ b/internal/game/map_test.go @@ -325,7 +325,23 @@ func TestBuildFullMap(t *testing.T) { func TestStripBlankRows(t *testing.T) { input := []string{" ", "hello", "", " world ", " "} - want := []string{"hello", " world "} + want := []string{"hello", "", " world "} + got := stripBlankRows(input) + if len(got) != len(want) { + t.Fatalf("expected %d lines, got %d", len(want), len(got)) + } + for i := range want { + if got[i] != want[i] { + t.Errorf("line %d: want %q, got %q", i, want[i], got[i]) + } + } +} + +func TestStripBlankRowsPreservesInternal(t *testing.T) { + // Internal blank rows (between non-blank content) should be preserved. + // They represent real vertical distance between disconnected components. + input := []string{" ", "hello", "", "", "world", " "} + want := []string{"hello", "", "", "world"} got := stripBlankRows(input) if len(got) != len(want) { t.Fatalf("expected %d lines, got %d", len(want), len(got)) @@ -374,3 +390,54 @@ func TestLeftTrimCommonZero(t *testing.T) { t.Errorf("line 1: want %q, got %q", "world", got[1]) } } + +func TestMap3DDisconnectedComponent(t *testing.T) { + // Tower 1 (0,0,0) has down→bridge (0,0,-1). bridge→east→tower2base (1,0,-1). + // tower2base→up→tower2 (1,0,0). Tower 2 is at the same z=0 as tower 1 but + // unreachable via horizontal exits. The 3D map should still show it. + dir := t.TempDir() + writeTempRoom(t, dir, 1, "name: Tower One\nexits:\n down: 2\n") + writeTempRoom(t, dir, 2, "name: Bridge\nexits:\n east: 3\n up: 1\n") + writeTempRoom(t, dir, 3, "name: Tower Two Base\nexits:\n up: 4\n west: 2\n") + writeTempRoom(t, dir, 4, "name: Tower Two\nexits:\n down: 3\n") + + g := &Game{Deps: Deps{World: world.New(dir)}, Flags: NewFlagStore()} + mg := mapGlyphsForPlayer(false) + + // Player has only visited tower 1. Tower 2 should appear but dimmed (unvisited). + sess := &net.Session{Player: &player.Player{ + Stats: player.PlayerStats{RoomsVisited: map[int]bool{1: true}}, + Flags: map[string]any{}, + }} + + out := strings.Join(buildTinyMap(g, sess, 1, mg), "\n") + + // Tower 2 at (1,0,0) should appear on the same z-level map. + // Unvisited rooms render as □ (unicode) or o (ASCII). + if !strings.Contains(out, "□") && !strings.Contains(out, "o") { + t.Errorf("expected tower 2 (unvisited) to appear on the map:\n%s", out) + } +} + +func TestMap3DDifferentZExcluded(t *testing.T) { + // Room 1 at (0,0,0) with up to room 2 at (0,0,1). Room 2 is at z=1, + // different from the player's z=0 level — should NOT show on the map. + dir := t.TempDir() + writeTempRoom(t, dir, 1, "name: Ground\nexits:\n up: 2\n") + writeTempRoom(t, dir, 2, "name: Upper\nexits:\n down: 1\n") + + g := &Game{Deps: Deps{World: world.New(dir)}, Flags: NewFlagStore()} + mg := mapGlyphsForPlayer(false) + sess := &net.Session{Player: &player.Player{ + Stats: player.PlayerStats{RoomsVisited: map[int]bool{1: true, 2: true}}, + Flags: map[string]any{}, + }} + + out := strings.Join(buildTinyMap(g, sess, 1, mg), "\n") + + // Room 2 is at a different z — it should NOT render as a room symbol. + // Unvisited rooms render as □ (unicode) or o (ASCII). + if strings.Contains(out, "□") || strings.Contains(out, " o ") { + t.Errorf("room at different z should not appear:\n%s", out) + } +} |
