summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-01 12:51:54 +0200
committerDanilo M. <danix@danix.xyz>2026-05-01 12:51:54 +0200
commitb4d3b526e232804e06b84d93628244cecd035df5 (patch)
tree9725d93a5818630afd4bbfeed9845518bfb012c1 /tests
parentba5438abaa430358eeb69b1376737ce61a3d68dc (diff)
downloadpublisher-b4d3b526e232804e06b84d93628244cecd035df5.tar.gz
publisher-b4d3b526e232804e06b84d93628244cecd035df5.zip
feat: TOML frontmatter parse/write with tomlkit
Diffstat (limited to 'tests')
-rw-r--r--tests/test_frontmatter.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_frontmatter.py b/tests/test_frontmatter.py
new file mode 100644
index 0000000..2257a8a
--- /dev/null
+++ b/tests/test_frontmatter.py
@@ -0,0 +1,49 @@
+import pytest
+from pathlib import Path
+import tempfile
+from core.frontmatter import parse_frontmatter, write_frontmatter
+
+SAMPLE_MD = """\
++++
+title = "Test Article"
+type = "Tech"
+draft = false
+tags = ["linux", "python"]
++++
+
+# Body
+
+Some content here.
+"""
+
+def test_parse_returns_frontmatter_dict(tmp_path):
+ f = tmp_path / "index.md"
+ f.write_text(SAMPLE_MD)
+ fm, body = parse_frontmatter(f)
+ assert fm["title"] == "Test Article"
+ assert fm["type"] == "Tech"
+ assert fm["draft"] is False
+ assert "linux" in fm["tags"]
+
+def test_parse_returns_body(tmp_path):
+ f = tmp_path / "index.md"
+ f.write_text(SAMPLE_MD)
+ fm, body = parse_frontmatter(f)
+ assert "# Body" in body
+ assert "Some content here." in body
+
+def test_write_preserves_format(tmp_path):
+ f = tmp_path / "index.md"
+ f.write_text(SAMPLE_MD)
+ fm, body = parse_frontmatter(f)
+ fm["title"] = "Updated Title"
+ write_frontmatter(f, fm, body)
+ fm2, _ = parse_frontmatter(f)
+ assert fm2["title"] == "Updated Title"
+ assert fm2["type"] == "Tech"
+
+def test_parse_raises_on_missing_delimiters(tmp_path):
+ f = tmp_path / "index.md"
+ f.write_text("# No frontmatter\n\nJust body.")
+ with pytest.raises(ValueError, match="frontmatter"):
+ parse_frontmatter(f)