forked from sirikothe/gotextfsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpytemplate_test.go
80 lines (76 loc) · 2.2 KB
/
pytemplate_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
76
77
78
79
80
package gotextfsm
import (
"testing"
)
type pyTemplateTestcase struct {
input string
vars map[string]interface{}
output string
err bool
}
func TestPyTemplate(t *testing.T) {
for _, tc := range pyTemplateTestcases {
output, err := ExecutePythonTemplate(tc.input, tc.vars)
if tc.err {
if err == nil {
t.Errorf("'%s' failed. Expected error, but none found", tc.input)
}
continue
}
if err != nil {
t.Errorf("'%s' failed. Expected no error. But found error %s", tc.input, err)
continue
}
if output != tc.output {
t.Errorf("'%s' failed. Expected outputs dont match (%s, %s)", tc.input, output, tc.output)
}
}
t.Logf("Executed %d test cases", len(pyTemplateTestcases))
}
var pyTemplateTestcases = []pyTemplateTestcase{
{
input: `Hello ${world}`,
vars: map[string]interface{}{"world": "Siri"},
output: `Hello Siri`,
},
{
input: `Hello $world`,
vars: map[string]interface{}{"world": "Siri"},
output: `Hello Siri`,
},
{
input: `Hello ${intVal} Hi ${floatVal} ${never ending`,
vars: map[string]interface{}{"intVal": 10, "floatVal": 5.2, "never ending": "Dummy"},
output: `Hello 10 Hi 5.2 ${never ending`,
},
{
input: `Hello ${top.bottom} Hi ${floatVal}`,
vars: map[string]interface{}{"top": map[string]interface{}{"bottom": "Structure"}, "floatVal": 5.2},
output: `Hello Structure Hi 5.2`,
},
{
input: `Hello ${top.bottom} Hi $no_variable`,
vars: map[string]interface{}{"top": map[string]interface{}{"bottom": "Structure"}},
output: `Hello Structure Hi $no_variable`,
},
{
input: `Escape $$ with $ $$$temp`,
vars: map[string]interface{}{"world": "Siri", "world123": "Bigger", "temp": "Dummy"},
output: `Escape $ with $ $Dummy`,
},
{
input: `Hello $world123 Hi ${world}`,
vars: map[string]interface{}{"world": "Siri", "world123": "Bigger"},
output: `Hello Bigger Hi Siri`,
},
{
input: `Escape {{ and }}`,
vars: map[string]interface{}{"world": "Siri", "world123": "Bigger"},
output: `Escape {{ and }}`,
},
{
input: `^\s+in\s+use\s+settings\s+=\{${INBOUND_SETTINGS_IN_USE},\s+\}\s*`,
vars: map[string]interface{}{"INBOUND_SETTINGS_IN_USE": "Hello"},
output: `^\s+in\s+use\s+settings\s+=\{Hello,\s+\}\s*`,
},
}