-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhitespace_test.go
More file actions
72 lines (66 loc) · 1.73 KB
/
whitespace_test.go
File metadata and controls
72 lines (66 loc) · 1.73 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
package twig
import (
"testing"
)
// TestWhitespaceControl tests the whitespace control with dash modifiers
func TestWhitespaceControl(t *testing.T) {
engine := New()
tests := []struct {
name string
source string
context map[string]interface{}
expected string
}{
{
name: "Whitespace control with dash",
source: "Before{%- if true -%}content{% endif -%}After",
context: nil,
expected: "BeforecontentAfter",
},
{
name: "Whitespace control with left dash only",
source: "Before {%- if true %}content{% endif %} After",
context: nil,
expected: "Beforecontent After",
},
{
name: "Whitespace control with right dash only",
source: "Before {% if true -%}content{% endif -%} After",
context: nil,
expected: "Before contentAfter",
},
{
name: "Whitespace control with variable tags",
source: "Before {{- 'content' -}} After",
context: nil,
expected: "BeforecontentAfter",
},
{
name: "Mixed whitespace control",
source: "Line1\n {{- 'content' }} \n {% if true -%} more {% endif -%}\nLine2",
context: nil,
expected: "Line1content \n more Line2",
},
{
name: "Newline control with dash",
source: "Line1\n{{- 'content' -}}\nLine2",
context: nil,
expected: "Line1contentLine2",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := engine.RegisterString(tt.name, tt.source)
if err != nil {
t.Fatalf("Error registering template: %v", err)
}
result, err := engine.Render(tt.name, tt.context)
if err != nil {
t.Fatalf("Error rendering template: %v", err)
}
if result != tt.expected {
t.Errorf("Expected %q, got %q", tt.expected, result)
}
})
}
}