File: parse_test.go

package info (click to toggle)
packer 0.10.2%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,728 kB
  • ctags: 4,626
  • sloc: sh: 321; makefile: 73
file content (39 lines) | stat: -rw-r--r-- 656 bytes parent folder | download
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
package interpolate

import (
	"reflect"
	"testing"
	"text/template"
)

func TestFunctionsCalled(t *testing.T) {
	cases := []struct {
		Input  string
		Result map[string]struct{}
	}{
		{
			"foo",
			map[string]struct{}{},
		},

		{
			"foo {{user `bar`}}",
			map[string]struct{}{
				"user": struct{}{},
			},
		},
	}

	funcs := Funcs(&Context{})
	for _, tc := range cases {
		tpl, err := template.New("root").Funcs(funcs).Parse(tc.Input)
		if err != nil {
			t.Fatalf("err parsing: %v\n\n%s", tc.Input, err)
		}

		actual := functionsCalled(tpl)
		if !reflect.DeepEqual(actual, tc.Result) {
			t.Fatalf("bad: %v\n\ngot: %#v", tc.Input, actual)
		}
	}
}