diff options
Diffstat (limited to 'internal/game/map_test.go')
| -rw-r--r-- | internal/game/map_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/internal/game/map_test.go b/internal/game/map_test.go index 0d529cf..ebb2197 100644 --- a/internal/game/map_test.go +++ b/internal/game/map_test.go @@ -31,12 +31,15 @@ func writeTempRoom(t *testing.T, dir string, id int, body string) { func TestMapConnectorGlyphs(t *testing.T) { const condEast = "name: One\nexits:\n east:\n room: 2\n condition:\n flag: gate_open\n" const condSouth = "name: Three\nexits:\n south:\n room: 2\n condition:\n flag: gate_open\n" + const condNE = "name: One\nexits:\n northeast:\n room: 2\n condition:\n flag: gate_open\n" + const condSE = "name: One\nexits:\n southeast:\n room: 2\n condition:\n flag: gate_open\n" cases := []struct { name string room1 string room2 string room3 string + room4 string flagOpen bool wantPresent string wantAbsent []string @@ -91,6 +94,59 @@ func TestMapConnectorGlyphs(t *testing.T) { wantPresent: "^", wantAbsent: []string{"X", "v", "<", ">"}, }, + { + name: "bidirectional diagonal NE-SW", + room1: "name: One\nexits:\n northeast: 2\n", + room2: "name: Two\nexits:\n southwest: 1\n", + wantPresent: "/", + wantAbsent: []string{"X", "\\"}, + }, + { + name: "bidirectional diagonal NW-SE", + room1: "name: One\nexits:\n northwest: 2\n", + room2: "name: Two\nexits:\n southeast: 1\n", + wantPresent: "\\", + wantAbsent: []string{"X", "/"}, + }, + { + name: "one-way NE arrow", + room1: "name: One\nexits:\n northeast: 2\n", + room2: "name: Two\n", + wantPresent: "/", + wantAbsent: []string{"X", "\\"}, + }, + { + name: "diagonal NE blocked conditional -> X", + room1: condNE, + room2: "name: Two\n", + flagOpen: false, + wantPresent: "X", + wantAbsent: []string{"\\", "/"}, + }, + { + name: "diagonal SE blocked conditional -> X", + room1: condSE, + room2: "name: Two\n", + flagOpen: false, + wantPresent: "X", + wantAbsent: []string{"\\", "/"}, + }, + { + name: "diagonal conditional unblocked -> bar", + room1: condNE, + room2: "name: Two\nexits:\n southwest: 1\n", + flagOpen: true, + wantPresent: "/", + wantAbsent: []string{"X", "\\"}, + }, + { + name: "criss-crossed diagonal paths show X", + room1: "name: One\nexits:\n east: 2\n south: 3\n southeast: 4\n", + room2: "name: Two\nexits:\n southwest: 3\n", + room3: "name: Three\n", + room4: "name: Four\n", + wantPresent: "X", + }, } for _, tc := range cases { @@ -101,6 +157,9 @@ func TestMapConnectorGlyphs(t *testing.T) { if tc.room3 != "" { writeTempRoom(t, dir, 3, tc.room3) } + if tc.room4 != "" { + writeTempRoom(t, dir, 4, tc.room4) + } g := &Game{Deps: Deps{World: world.New(dir)}, Flags: NewFlagStore()} if tc.flagOpen { @@ -121,6 +180,27 @@ func TestMapConnectorGlyphs(t *testing.T) { } } +// TestMapDiagonalOneWayCrossing verifies that when a one-way diagonal arrow +// (↗) crosses a bidirectional diagonal bar (/) at the same grid cell, the +// cell renders as X rather than silently overwriting the arrow. This covers +// the unicode-mode criss-cross path where isDiagonalGlyph must recognize +// both bar glyphs and arrow glyphs. +func TestMapDiagonalOneWayCrossing(t *testing.T) { + dir := t.TempDir() + writeTempRoom(t, dir, 1, "name: One\nexits:\n north: 3\n northeast: 2\n") + writeTempRoom(t, dir, 2, "name: Two\n") + writeTempRoom(t, dir, 3, "name: Three\nexits:\n southeast: 4\n") + writeTempRoom(t, dir, 4, "name: Four\nexits:\n northwest: 3\n") + + g := &Game{Deps: Deps{World: world.New(dir)}} + sess := &net.Session{Player: &player.Player{Options: map[string]any{"unicode": true}}} + + out := strings.Join(buildTinyMap(g, sess, 1, mapGlyphsForPlayer(true)), "\n") + if !strings.Contains(out, "X") { + t.Errorf("expected X for crossed one-way NE arrow and SE bar:\n%s", out) + } +} + func TestBuildTinyMap(t *testing.T) { g := &Game{ Deps: Deps{World: world.New("../../data")}, |
