github.com/aspring/packer@v0.8.1-0.20150629211158-9db281ac0f89/template/interpolate/parse_test.go (about)

     1  package interpolate
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  	"text/template"
     7  )
     8  
     9  func TestFunctionsCalled(t *testing.T) {
    10  	cases := []struct {
    11  		Input  string
    12  		Result map[string]struct{}
    13  	}{
    14  		{
    15  			"foo",
    16  			map[string]struct{}{},
    17  		},
    18  
    19  		{
    20  			"foo {{user `bar`}}",
    21  			map[string]struct{}{
    22  				"user": struct{}{},
    23  			},
    24  		},
    25  	}
    26  
    27  	funcs := Funcs(&Context{})
    28  	for _, tc := range cases {
    29  		tpl, err := template.New("root").Funcs(funcs).Parse(tc.Input)
    30  		if err != nil {
    31  			t.Fatalf("err parsing: %v\n\n%s", tc.Input, err)
    32  		}
    33  
    34  		actual := functionsCalled(tpl)
    35  		if !reflect.DeepEqual(actual, tc.Result) {
    36  			t.Fatalf("bad: %v\n\ngot: %#v", tc.Input, actual)
    37  		}
    38  	}
    39  }