forked from hairyhenderson/gomplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tpl_func_test.go
68 lines (56 loc) · 1.5 KB
/
tpl_func_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
package gomplate
import (
"testing"
"text/template"
"github.com/stretchr/testify/assert"
)
func TestTplFunc(t *testing.T) {
g := &gomplate{
leftDelim: "{{",
rightDelim: "}}",
funcMap: template.FuncMap{},
}
tmpl := &tplate{name: "root", contents: "foo"}
tmpl.toGoTemplate(g)
testdata := []string{
"{{ print `hello world`}}",
"{{ tpl \"{{ print `hello world`}}\"}}",
"{{ tpl \"{{ tpl \\\"{{ print `hello world`}}\\\"}}\"}}",
}
for _, d := range testdata {
out, err := g.tpl(d)
assert.NoError(t, err, d)
assert.Equal(t, "hello world", out)
}
}
func TestParseArgs(t *testing.T) {
name, in, ctx, err := parseArgs("foo")
assert.NoError(t, err)
assert.Equal(t, "<inline>", name)
assert.Equal(t, "foo", in)
assert.EqualValues(t, &context{}, ctx)
_, _, _, err = parseArgs(42)
assert.Error(t, err)
_, _, _, err = parseArgs()
assert.Error(t, err)
_, _, _, err = parseArgs("", "", 42, "")
assert.Error(t, err)
_, _, _, err = parseArgs("", 42, 42)
assert.Error(t, err)
name, in, ctx, err = parseArgs("foo", "bar")
assert.NoError(t, err)
assert.Equal(t, "foo", name)
assert.Equal(t, "bar", in)
assert.EqualValues(t, &context{}, ctx)
c := map[string]string{"one": "two"}
name, in, ctx, err = parseArgs("foo", c)
assert.NoError(t, err)
assert.Equal(t, "<inline>", name)
assert.Equal(t, "foo", in)
assert.Equal(t, c, ctx)
name, in, ctx, err = parseArgs("foo", "bar", c)
assert.NoError(t, err)
assert.Equal(t, "foo", name)
assert.Equal(t, "bar", in)
assert.Equal(t, c, ctx)
}