chore: prepare docfill project for gitea

This commit is contained in:
赵义仑
2026-06-24 09:45:35 +08:00
parent ca444bd5d0
commit 32e74d0f43
38 changed files with 2915 additions and 162 deletions

View File

@@ -153,6 +153,30 @@ func TestRenderDOCXReplacesPlaceholderSplitAcrossTextNodes(t *testing.T) {
}
}
func TestRenderDOCXReplacesMultipleSplitPlaceholdersInSameParagraph(t *testing.T) {
dir := t.TempDir()
templatePath := filepath.Join(dir, "template.docx")
outputPath := filepath.Join(dir, "out.docx")
writeMinimalDocx(t, templatePath, `<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>员工:{{na</w:t></w:r><w:r><w:t>me}}</w:t></w:r><w:r><w:t>,完成:{{do</w:t></w:r><w:r><w:t>ne}}</w:t></w:r><w:r><w:t>,备注:{{note}}</w:t></w:r></w:p></w:body></w:document>`)
err := renderTemplate(templatePath, outputPath, map[string]string{
"name": "Alice",
"done": "接口数据整理",
"note": "保持同段落",
})
if err != nil {
t.Fatalf("renderTemplate returned error: %v", err)
}
got := readZipEntry(t, outputPath, "word/document.xml")
if !strings.Contains(got, "员工Alice完成接口数据整理备注保持同段落") {
t.Fatalf("document.xml = %q, want rendered split placeholders", got)
}
if strings.Contains(got, "{{") || strings.Contains(got, "}}") {
t.Fatalf("document.xml still has placeholder markers: %q", got)
}
}
func TestRunGeneratesOneOutputPerInputRow(t *testing.T) {
dir := t.TempDir()
dataPath := filepath.Join(dir, "data.xlsx")