From 888cfc4061f36f6251ce70a74624d89b39c7e9bc Mon Sep 17 00:00:00 2001 From: Titus Date: Mon, 30 Nov 2026 14:44:55 +0100 Subject: [PATCH] Test: an id tail with a character above U+FFFF counts code points Folder spec 3.2 counts an id's last eight characters in code points. Two cases, the same as the npm SDK's test/id-tail.test.mjs: a character above U+FFFF at the end of the tail and one at the cut, each named and written to disk whole. Co-Authored-By: Claude Opus 5.5 --- tests/test_id_tail.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_id_tail.py diff --git a/tests/test_id_tail.py b/tests/test_id_tail.py new file mode 100644 index 0000000..a74196b --- /dev/null +++ b/tests/test_id_tail.py @@ -0,0 +1,28 @@ +"""An element file's id tail is the last 8 code points of its id (folder spec 3.2): an id with a character above +U+FFFF in its tail, or at the cut, names its file as the npm SDK names it (``test/id-tail.test.mjs`` there holds the +same two cases), and ``write_folder`` writes that name to disk.""" + +from __future__ import annotations + +from pathlib import Path + +import pytest + +from onlyworlds import write_folder +from onlyworlds.folder import element_filename + +E = chr(0x1F600) + + +@pytest.mark.parametrize( + ("element_id", "name"), + [ + (f"a1234567{E}", f"bob--1234567{E}.json"), + (f"a{E}1234567", f"bob--{E}1234567.json"), + ], +) +def test_a_character_above_the_bmp_counts_as_one(tmp_path: Path, element_id: str, name: str) -> None: + assert element_filename(element_id, "Bob") == name + out = tmp_path / "world" + write_folder(out, {"id": "w-1", "name": "W"}, {"character": [{"id": element_id, "name": "Bob"}]}) + assert [p.name for p in (out / "elements" / "character").iterdir()] == [name]