fix(writer): 防静默丢章告警 + 占位符正则宽容化(大小写/全角冒号)
This commit is contained in:
@@ -104,3 +104,29 @@ def test_parse_styles_collected(tmp_path):
|
||||
assert "Heading 1" in result.styles["used"]
|
||||
assert "Normal" in result.styles["used"]
|
||||
assert "Heading 1" in result.styles["defined"]
|
||||
|
||||
|
||||
def test_parse_extracts_placeholder_case_insensitive(tmp_path):
|
||||
# 宽容:键名大小写不敏感 → 归一为小写 section:id
|
||||
doc = new_document()
|
||||
doc.add_paragraph("{{Section:2}}")
|
||||
path = save_document(tmp_path, doc)
|
||||
|
||||
result = WordTemplateParser().parse(path)
|
||||
|
||||
assert result.placeholders == {"section:2": "{{Section:2}}"}
|
||||
ph = [s for s in result.sections if s.type == "placeholder"]
|
||||
assert [s.name for s in ph] == ["section:2"]
|
||||
|
||||
|
||||
def test_parse_extracts_placeholder_fullwidth_colon(tmp_path):
|
||||
# 宽容:全角冒号(:)也视为分隔符 → 归一为半角 section:id
|
||||
doc = new_document()
|
||||
doc.add_paragraph("{{section:2}}")
|
||||
path = save_document(tmp_path, doc)
|
||||
|
||||
result = WordTemplateParser().parse(path)
|
||||
|
||||
assert result.placeholders == {"section:2": "{{section:2}}"}
|
||||
ph = [s for s in result.sections if s.type == "placeholder"]
|
||||
assert [s.name for s in ph] == ["section:2"]
|
||||
|
||||
Reference in New Issue
Block a user