Files
lyxy-document/tests/test_core/test_markdown.py
lanyuanxiaoyao 9daff73589 refactor: 调整模块导入路径,简化引用结构
- 更新 openspec/config.yaml 中 git 任务相关说明
- 将 scripts.core.* 改为 core.*,scripts.readers.* 改为 readers.*
- 优化 lyxy_document_reader.py 中 sys.path 设置方式
- 同步更新所有测试文件的导入路径
2026-03-09 15:44:51 +08:00

57 lines
1.5 KiB
Python

"""测试 Markdown 工具函数。"""
from core import (
get_heading_level,
extract_titles,
normalize_markdown_whitespace,
remove_markdown_images,
)
class TestGetHeadingLevel:
"""测试 get_heading_level 函数。"""
def test_h1(self):
assert get_heading_level("# 标题") == 1
def test_h2(self):
assert get_heading_level("## 子标题") == 2
def test_h6(self):
assert get_heading_level("###### 六级标题") == 6
def test_no_heading(self):
assert get_heading_level("普通文本") == 0
def test_no_space(self):
assert get_heading_level("#标题") == 0
class TestExtractTitles:
"""测试 extract_titles 函数。"""
def test_extract_multiple_titles(self, sample_markdown):
titles = extract_titles(sample_markdown)
assert len(titles) == 3
assert "# 标题" in titles
assert "## 子标题" in titles
assert "### 另一个标题" in titles
class TestNormalizeMarkdownWhitespace:
"""测试 normalize_markdown_whitespace 函数。"""
def test_multiple_blank_lines(self):
content = "line1\n\n\n\nline2"
result = normalize_markdown_whitespace(content)
assert result == "line1\n\nline2"
class TestRemoveMarkdownImages:
"""测试 remove_markdown_images 函数。"""
def test_remove_image(self):
content = "Text ![alt](image.png) more text"
result = remove_markdown_images(content)
assert "![alt](image.png)" not in result