Skip to content

Commit

Permalink
transform: Reduce allocation in the benchmark itself
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Aug 5, 2018
1 parent 2711013 commit a6b1eb1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions transform/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"
"testing"

bp "github.com/gohugoio/hugo/bufferpool"
"github.com/gohugoio/hugo/helpers"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -235,16 +236,24 @@ func TestNewEmptyTransforms(t *testing.T) {
type errorf func(string, ...interface{})

func applyWithPath(ef errorf, tr chain, tests []test, path string) {
out := bp.GetBuffer()
defer bp.PutBuffer(out)

in := bp.GetBuffer()
defer bp.PutBuffer(in)

for _, test := range tests {
out := new(bytes.Buffer)
var err error
err = tr.Apply(out, strings.NewReader(test.content), []byte(path))
in.WriteString(test.content)
err = tr.Apply(out, in, []byte(path))
if err != nil {
ef("Unexpected error: %s", err)
}
if test.expected != string(out.Bytes()) {
ef("Expected:\n%s\nGot:\n%s", test.expected, string(out.Bytes()))
if test.expected != out.String() {
ef("Expected:\n%s\nGot:\n%s", test.expected, out.String())
}
out.Reset()
in.Reset()
}
}

Expand Down

0 comments on commit a6b1eb1

Please sign in to comment.