Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test noallocs
  • Loading branch information
nicksnyder committed Jun 5, 2019
commit def97809867de3ea46b268bb7fde24039f0747af
13 changes: 11 additions & 2 deletions internal/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ func TestExecute(t *testing.T) {
data interface{}
result string
err string
noallocs bool
}{
{
template: &Template{
Src: "hello",
},
result: "hello",
result: "hello",
noallocs: true,
},
{
template: &Template{
Expand All @@ -43,7 +45,8 @@ func TestExecute(t *testing.T) {
template: &Template{
Src: "hello {{",
},
err: "template: :1: unexpected unclosed action in command",
err: "template: :1: unexpected unclosed action in command",
noallocs: true,
},
}

Expand All @@ -56,6 +59,12 @@ func TestExecute(t *testing.T) {
if result != test.result {
t.Errorf("expected result %q; got %q", test.result, result)
}
allocs := testing.AllocsPerRun(10, func() {
_, _ = test.template.Execute(test.funcs, test.data)
})
if test.noallocs && allocs > 0 {
t.Errorf("expected no allocations; got %f", allocs)
}
})
}
}
Expand Down