Add page identity and frontmatter domain types
PageId (UUIDv7) and PageTitle validate on construction; frontmatter is split losslessly, read as text-only YAML without anchors or duplicate keys, and written canonically. All page errors live in domain/errors. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cce8afada5
commit
6ecdbe856a
5 files changed
+462
No files matched your search
@@ -0,0 +1,103 @@
|
||||
import pytest
|
||||
|
||||
from chemenu.domain.errors import InvalidPageIdError, InvalidTitleError
|
||||
from chemenu.domain.identity import PageId, PageTitle
|
||||
|
||||
VALID_ID = "01a238ea-2e6d-7157-ba55-5da7405095ff"
|
||||
|
||||
|
||||
def test_valid_id() -> None:
|
||||
assert PageId(VALID_ID).value == VALID_ID
|
||||
assert PageId(VALID_ID.replace("ba55", "8a55")).value.startswith("01a2")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value",
|
||||
[
|
||||
"",
|
||||
VALID_ID + "\n",
|
||||
VALID_ID.upper(),
|
||||
VALID_ID.replace("-7157", "-4157"),
|
||||
VALID_ID.replace("ba55", "ca55"),
|
||||
VALID_ID.replace("-", ""),
|
||||
VALID_ID[:-1],
|
||||
VALID_ID[:-1] + "g",
|
||||
VALID_ID[:-1] + chr(0xFF10),
|
||||
" " + VALID_ID,
|
||||
],
|
||||
)
|
||||
def test_invalid_id_raises(value: str) -> None:
|
||||
with pytest.raises(InvalidPageIdError):
|
||||
PageId(value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value",
|
||||
[
|
||||
"Ordnungs-, Wisch- und Sanitätsdienst",
|
||||
"Äpfel 🍎",
|
||||
"a" * 252,
|
||||
"CONSOLE",
|
||||
"Aux-Plan",
|
||||
"a.b",
|
||||
"x%y",
|
||||
],
|
||||
)
|
||||
def test_title_with_comma(value: str) -> None:
|
||||
assert PageTitle(value).value == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value",
|
||||
[
|
||||
"",
|
||||
" ",
|
||||
"a<b",
|
||||
"a>b",
|
||||
"a:b",
|
||||
'a"b',
|
||||
"a/b",
|
||||
"a\\b",
|
||||
"a|b",
|
||||
"a?b",
|
||||
"a*b",
|
||||
"a[b",
|
||||
"a]b",
|
||||
"a#b",
|
||||
"a^b",
|
||||
"a%%b",
|
||||
"a\tb",
|
||||
"a\nb",
|
||||
"a\x7fb",
|
||||
"a\x85b",
|
||||
f"a{chr(0x2028)}b",
|
||||
f"a{chr(0x2029)}b",
|
||||
".a",
|
||||
"a.",
|
||||
" a",
|
||||
"a ",
|
||||
f"a{chr(0xA0)}",
|
||||
f"{chr(0x3000)}a",
|
||||
"con",
|
||||
"CON",
|
||||
"Con.txt",
|
||||
"con .txt",
|
||||
"NUL",
|
||||
"prn",
|
||||
"conin$",
|
||||
"CONOUT$",
|
||||
"aux",
|
||||
"COM1",
|
||||
"lpt9.x",
|
||||
"COM¹",
|
||||
"LPT²",
|
||||
"COM³.a",
|
||||
"e\u0301",
|
||||
"a" * 253,
|
||||
"ä" * 127,
|
||||
"a\ud800b",
|
||||
],
|
||||
)
|
||||
def test_invalid_title_raises(value: str) -> None:
|
||||
with pytest.raises(InvalidTitleError):
|
||||
PageTitle(value)
|
||||
Reference in new issue
Block a user