mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-16 23:17:54 +00:00
transform: Reduce allocation in the benchmark itself
This commit is contained in:
parent
27110133ff
commit
a6b1eb1e91
1 changed files with 13 additions and 4 deletions
|
@ -19,6 +19,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
bp "github.com/gohugoio/hugo/bufferpool"
|
||||||
"github.com/gohugoio/hugo/helpers"
|
"github.com/gohugoio/hugo/helpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -235,16 +236,24 @@ func TestNewEmptyTransforms(t *testing.T) {
|
||||||
type errorf func(string, ...interface{})
|
type errorf func(string, ...interface{})
|
||||||
|
|
||||||
func applyWithPath(ef errorf, tr chain, tests []test, path string) {
|
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 {
|
for _, test := range tests {
|
||||||
out := new(bytes.Buffer)
|
|
||||||
var err error
|
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 {
|
if err != nil {
|
||||||
ef("Unexpected error: %s", err)
|
ef("Unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
if test.expected != string(out.Bytes()) {
|
if test.expected != out.String() {
|
||||||
ef("Expected:\n%s\nGot:\n%s", test.expected, string(out.Bytes()))
|
ef("Expected:\n%s\nGot:\n%s", test.expected, out.String())
|
||||||
}
|
}
|
||||||
|
out.Reset()
|
||||||
|
in.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue