fix(map): fail on blank rows inside a layer, keep trailing-space cells verbatim

This commit is contained in:
2026-09-20 17:48:47 +02:00
parent 205ddece0b
commit bce0a59e60
2 changed files with 46 additions and 4 deletions
+29
View File
@@ -73,6 +73,35 @@ def test_rejects_ragged_rows(tmp_path: Path) -> None:
load_map(_write(tmp_path, body))
def test_rejects_blank_row_inside_layer(tmp_path: Path) -> None:
"""A truly blank line inside a layer is a missing row -- an error, never
silently dropped (the old filter shrank the row count unnoticed)."""
body = _minimal_map().replace(" ###\n #.#\n", " ###\n\n #.#\n")
with pytest.raises(MapValidationError, match="blank row"):
load_map(_write(tmp_path, body))
def test_trailing_space_cells_are_kept(tmp_path: Path) -> None:
"""With " " in the legend, trailing spaces are real cells: rstrip() must
not delete them (the layer keeps its full width)."""
body = (
'\nname: "Test"\nterrain: |\n ...\n .. \n'
'legend:\n'
' ".": { type: floor, move_cost: 1 }\n'
' " ": { type: floor, move_cost: 1 }\n'
)
spec = load_map(_write(tmp_path, body))
assert spec.terrain == ("...", ".. ")
def test_rejects_trailing_space_without_legend_entry(tmp_path: Path) -> None:
"""Without " " in the legend a padded row is ragged/unknown-char data,
reported as an error instead of silently stripped."""
body = _minimal_map().replace(" ###\n #.#\n ###\n", " ### \n #.# \n ### \n")
with pytest.raises(MapValidationError):
load_map(_write(tmp_path, body))
def test_rejects_non_five_foot_square_size(tmp_path: Path) -> None:
"""SRD Measuring Distance: one grid square is 5 ft; the engine geometry
is hard-coded to that scale, so any other declared size is a load error