-
Notifications
You must be signed in to change notification settings - Fork 47
/
placeholder_test.go
59 lines (50 loc) · 1.47 KB
/
placeholder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package docx
import "testing"
var (
textMapping = PlaceholderMap{
"single": "Replaced text",
"fragmented_placeholder": "Replaced text",
"yet-another-placeholder": "Replaced text",
"some_placeholder": "Replaced text",
"foo_bar": "BAR BAZ",
}
)
func TestParsePlaceholders(t *testing.T) {
docBytes := readFile(t, "./test/placeholder.xml")
expectedPlaceholderCount := 6
parser := NewRunParser(docBytes)
err := parser.Execute()
if err != nil {
t.Errorf("parser.Execute failed: %s", err)
}
placeholders, err := ParsePlaceholders(parser.Runs().WithText(), docBytes)
if err != nil {
t.Error(err)
return
}
if len(placeholders) != expectedPlaceholderCount {
t.Errorf("did not parse all placeholders, want=%d, have=%d", expectedPlaceholderCount, len(placeholders))
}
for key := range textMapping {
expectedKey := AddPlaceholderDelimiter(key)
valid := false
for _, placeholder := range placeholders {
if expectedKey == placeholder.Text(docBytes) {
valid = true
continue
}
}
if !valid {
t.Errorf("did not find expected placeholder %s", expectedKey)
}
}
}
func TestPlaceholder_AssembleFullPlaceholders(t *testing.T) {
expectedCount := 2
openPos := []int{10, 18}
closePos := []int{17, 25}
placeholders := assembleFullPlaceholders(&Run{}, openPos, closePos)
if len(placeholders) != expectedCount {
t.Errorf("not all full placeholders were parsed, want=%d, have=%d", expectedCount, len(placeholders))
}
}