-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor_test.go
75 lines (60 loc) · 1.89 KB
/
processor_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* snowmark - HTML templates for Go.
*
* MIT License.
* Copyright (c) 2022, Sandeep Gupta.
* https://github.com/sangupta/snowmark
*
* Use of this source code is governed by a MIT style license
* that can be found in LICENSE file in the code repository:
*/
package snowmark
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestProcessorEmptyTemplate(t *testing.T) {
processor := NewHtmlPageProcessor()
processor.AddCustomTag("if", IfElseTag)
processor.AddCustomTag("get", GetVariableTag)
processor.AddCustomTag("set", SetVariableTag)
processor.AddCustomTag("for", ForEachTag)
template := ""
model := NewModel()
html, err := processor.MergeHtml(template, model)
assert.NoError(t, err)
assert.Equal(t, "", html)
}
func TestProcessorNoTag(t *testing.T) {
processor := NewHtmlPageProcessor()
template := "<html></html>"
model := NewModel()
html, err := processor.MergeHtml(template, model)
assert.NoError(t, err)
assert.Equal(t, "<html />", html)
}
func TestProcessorGetTagNoValue(t *testing.T) {
processor := NewHtmlPageProcessor()
processor.AddCustomTag("if", IfElseTag)
processor.AddCustomTag("get", GetVariableTag)
processor.AddCustomTag("set", SetVariableTag)
processor.AddCustomTag("for", ForEachTag)
template := "<html><get var='hello' /></html>"
model := NewModel()
html, err := processor.MergeHtml(template, model)
assert.NoError(t, err)
assert.Equal(t, "<html></html>", html)
}
func TestProcessorGetTagWithValue(t *testing.T) {
processor := NewHtmlPageProcessor()
processor.AddCustomTag("if", IfElseTag)
processor.AddCustomTag("get", GetVariableTag)
processor.AddCustomTag("set", SetVariableTag)
processor.AddCustomTag("for", ForEachTag)
template := "<html><get var='hello' /></html>"
model := NewModel()
model.Put("hello", "world")
html, err := processor.MergeHtml(template, model)
assert.NoError(t, err)
assert.Equal(t, "<html>world</html>", html)
}