Creating a tpl/templates test case that uses $variables

I want to test a new function using a template like:

{{ $foo := "foo := text" }}
<p>typeOf $foo {{ typeOf $foo }}</p>

I’ve looked at the test cases in tpl/template_test.go. I didn’t find any that set up a variable for the test.

How would I do this? Create a new htmlTemplate and parse it and examine the results? Is there something in the ACE test cases that I could use as a starting point?

Not sure what typeOf is supposed to do, but I guess this will do the same:

{{ printf "%T" $foo }}

As to testing it, I would just test the func on it’s own, many examples in templates_test.go.

It is supposed to return a string with the type of the variable. I’m using something similar to this:

func TestInspectTypeOf(t *testing.T) {
 for i, this := range []struct {
  v interface{}
  expect interface{}
  {0, "int"},
  {0.0, "float64"},
  {"Hello, World!", "string"},
  {"$foo", "string"},
  {".", "*hugolib.Node"},
 } {
  result := InspectTypeOf(this.v)
  if !reflect.DeepEqual(result, this.expect) {
   t.Errorf("[%d] typeOf got %v but expected %v", i, result, this.expect)

The issue is that $foo and . isn’t being tested correctly because in this context they are Go strings, not Hugo variables. I looked in templates_test.go but didn’t see any functions that were setting Hugo variables.

expect := template.HTML("$foo := \"Hello, World!\"") seems to be what I’m after.