Add coordinate axes to string rendering

This commit is contained in:
evilchili
2025-08-17 16:58:17 -07:00
parent cc35a60210
commit ee8c2af2d8
7 changed files with 102 additions and 28 deletions
+21 -1
View File
@@ -4,6 +4,7 @@ from textwrap import dedent
import pytest
from tilemapper import battlemap, tileset
from tilemapper.grid import X_COORDS
@pytest.fixture
@@ -43,4 +44,23 @@ def test_renderer(manager, sample_map):
assert test_map.width == 21
assert test_map.height == 12
assert test_map.source_data == sample_map.strip("\n")
assert str(test_map) == sample_map.strip("\n")
srclines = sample_map.splitlines()[1:]
strlines = str(test_map).splitlines()
for i in range(len(strlines)):
assert strlines[i] == srclines[i].ljust(21, " ")
def test_grid_coordiates(manager):
coord_length = len(X_COORDS)
map_size = 2 * coord_length + 1
bigmap = StringIO((("." * map_size) + "\n") * map_size)
test_map = battlemap.BattleMap("test map", source=bigmap, tileset=manager.load("ascii"))
test_map.load()
assert test_map.grid.data[-1][-1].coordinates == (f"{map_size - 1}", X_COORDS[0] * 3)
lines = test_map.top_coordinates.splitlines()
assert len(lines) == 3
assert lines[0] == (" " * (map_size - 1)) + X_COORDS[0]
assert lines[1][: (coord_length + 1)] == (" " * coord_length) + X_COORDS[0]
assert lines[2] == "".join(X_COORDS) + ((coord_length + 1) * X_COORDS[0])