Fixes #24791
Change-Id: I62ac17313e6e09796586911d88191a36d67f9aa1
Reviewed-on: https://go-review.googlesource.com/106115
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
"errors"
"fmt"
"io/ioutil"
+ "strings"
"sync"
"testing"
"text/template/parse"
}
}
}
+
+// Issue 24791.
+func TestClonePipe(t *testing.T) {
+ a := Must(New("a").Parse(`{{define "a"}}{{range $v := .A}}{{$v}}{{end}}{{end}}`))
+ data := struct{ A []string }{A: []string{"hi"}}
+ b := Must(a.Clone())
+ var buf strings.Builder
+ if err := b.Execute(&buf, &data); err != nil {
+ t.Fatal(err)
+ }
+ if got, want := buf.String(), "hi"; got != want {
+ t.Errorf("got %q want %q", got, want)
+ }
+}
vars = append(vars, d.Copy().(*AssignNode))
}
n := p.tr.newPipeline(p.Pos, p.Line, vars)
+ n.Decl = p.Decl
for _, c := range p.Cmds {
n.append(c.Copy().(*CommandNode))
}