Files
2026Technology-Competition/tests/test_rule_doc_parser.py
T

83 lines
2.8 KiB
Python

from genesis.data_models import RuleDocument
from genesis.parsers.rule_doc_parser import RuleDocParser
from tests.docx_helpers import make_rule_doc, new_document, save_document
def test_parse_heading_and_bullet(tmp_path):
path = make_rule_doc(tmp_path, [
("H1", "1. 機能一覧の書き方"),
("list", "・機能ID は F001 から連番で付与する。"),
("list", "・省略記号(~、…)は禁止し、正式名称を記載する。"),
])
result = RuleDocParser().parse(path, category="write")
assert isinstance(result, RuleDocument)
assert result.category == "write"
assert result.file_type == "word"
assert result.file_name == "source.docx"
assert "# 1. 機能一覧の書き方" in result.markdown_content
assert "- 機能ID は F001 から連番で付与する。" in result.markdown_content
assert "- 省略記号(~、…)は禁止し、正式名称を記載する。" in result.markdown_content
def test_parse_prefix_bullet_without_list_style(tmp_path):
# 真实样本的「・」前缀在 Normal 样式段落(非 List Bullet)——双通道检测
doc = new_document()
doc.add_paragraph("・表ヘッダーは太字とし、下線を付ける。")
path = save_document(tmp_path, doc)
result = RuleDocParser().parse(path)
assert "- 表ヘッダーは太字とし、下線を付ける。" in result.markdown_content
def test_parse_table_to_markdown(tmp_path):
doc = new_document()
table = doc.add_table(rows=3, cols=2)
headers = ["項目", "規則"]
for c, h in enumerate(headers):
table.cell(0, c).text = h
table.cell(1, 0).text = "表ヘッダー"
table.cell(1, 1).text = "太字のみ"
table.cell(2, 0).text = "枠線"
table.cell(2, 1).text = "付ける"
path = save_document(tmp_path, doc)
result = RuleDocParser().parse(path)
lines = result.markdown_content.splitlines()
assert "| 項目 | 規則 |" in lines
assert "| --- | --- |" in lines
assert "| 表ヘッダー | 太字のみ |" in lines
assert "| 枠線 | 付ける |" in lines
def test_parse_empty_document(tmp_path):
doc = new_document()
doc.add_paragraph("")
path = save_document(tmp_path, doc)
result = RuleDocParser().parse(path)
assert result.markdown_content == ""
def test_parse_hash_stable_and_sha256(tmp_path):
path = make_rule_doc(tmp_path, [("H1", "章"), ("", "本文")])
r1 = RuleDocParser().parse(path)
r2 = RuleDocParser().parse(path)
assert r1.hash == r2.hash
assert len(r1.hash) == 64 # sha256 hex
def test_parse_design_category(tmp_path):
path = make_rule_doc(tmp_path, [("H1", "アーキテクチャ制約")])
result = RuleDocParser().parse(path, category="design")
assert result.category == "design"