fix/various fixes
This commit is contained in:
58
api/tests/test_chapter_markdown_compose.py
Normal file
58
api/tests/test_chapter_markdown_compose.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import unittest
|
||||
|
||||
from app.features.memoir.chapter_markdown_compose import (
|
||||
compose_ordered_stories_to_markdown,
|
||||
materialize_chapter_markdown_from_loaded_chapter,
|
||||
)
|
||||
|
||||
|
||||
class ChapterMarkdownComposeTest(unittest.TestCase):
|
||||
def test_orders_and_separates_with_headings(self):
|
||||
md = compose_ordered_stories_to_markdown(
|
||||
[("第一章", "正文A"), ("第二章", "正文B")]
|
||||
)
|
||||
self.assertIn("## 第一章", md)
|
||||
self.assertIn("正文A", md)
|
||||
self.assertIn("## 第二章", md)
|
||||
self.assertIn("正文B", md)
|
||||
self.assertIn("\n\n---\n\n", md)
|
||||
self.assertTrue(md.index("正文A") < md.index("---"))
|
||||
self.assertTrue(md.index("---") < md.index("第二章"))
|
||||
self.assertTrue(md.index("第一章") < md.index("第二章"))
|
||||
|
||||
def test_preserves_asset_refs(self):
|
||||
body = ""
|
||||
md = compose_ordered_stories_to_markdown([("S", body)])
|
||||
self.assertIn("asset://abc-123", md)
|
||||
|
||||
def test_empty_title_uses_fallback(self):
|
||||
md = compose_ordered_stories_to_markdown([("", "仅正文")])
|
||||
self.assertIn("## 故事", md)
|
||||
|
||||
def test_empty_body_keeps_heading_only(self):
|
||||
md = compose_ordered_stories_to_markdown([("仅标题", "")])
|
||||
self.assertEqual(md, "## 仅标题")
|
||||
|
||||
def test_materialize_respects_order_index(self):
|
||||
class _S:
|
||||
def __init__(self, title: str, body: str):
|
||||
self.title = title
|
||||
self.canonical_markdown = body
|
||||
|
||||
class _L:
|
||||
def __init__(self, o: int, story: _S):
|
||||
self.order_index = o
|
||||
self.story = story
|
||||
|
||||
ch = type(
|
||||
"Ch",
|
||||
(),
|
||||
{
|
||||
"story_links": [
|
||||
_L(1, _S("B", "后")),
|
||||
_L(0, _S("A", "先")),
|
||||
]
|
||||
},
|
||||
)()
|
||||
md = materialize_chapter_markdown_from_loaded_chapter(ch)
|
||||
self.assertLess(md.index("先"), md.index("后"))
|
||||
Reference in New Issue
Block a user