Skip to content

Commit

Permalink
html/template: add tests from text/template
Browse files Browse the repository at this point in the history
Copy and adapt tests from text/template, to exercise more of html/template's copy.

Various differences in behavior are flagged with NOTE comments or t.Skip
and documented in #40075. Many of them are probably bugs.
One clarifying test case added to both text/template and html/template.

No changes to the package itself.

Change-Id: Ifefad83d647db846040d24c2741a0244b00ade82
Reviewed-on: https://go-review.googlesource.com/c/go/+/241084
Run-TryBot: Russ Cox <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Rob Pike <[email protected]>
  • Loading branch information
rsc committed Jul 14, 2020
1 parent e88ea87 commit efbe47b
Show file tree
Hide file tree
Showing 10 changed files with 1,970 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/html/template/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"text/template/parse"
)

func TestAddParseTree(t *testing.T) {
func TestAddParseTreeHTML(t *testing.T) {
root := Must(New("root").Parse(`{{define "a"}} {{.}} {{template "b"}} {{.}} "></a>{{end}}`))
tree, err := parse.Parse("t", `{{define "b"}}<a href="{{end}}`, "", "", nil, nil)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions src/html/template/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ func TestTypedContent(t *testing.T) {
}

// Test that we print using the String method. Was issue 3073.
type stringer struct {
type myStringer struct {
v int
}

func (s *stringer) String() string {
func (s *myStringer) String() string {
return fmt.Sprintf("string=%d", s.v)
}

Expand All @@ -418,7 +418,7 @@ func (s *errorer) Error() string {
}

func TestStringer(t *testing.T) {
s := &stringer{3}
s := &myStringer{3}
b := new(bytes.Buffer)
tmpl := Must(New("x").Parse("{{.}}"))
if err := tmpl.Execute(b, s); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/html/template/escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ func TestIndirectPrint(t *testing.T) {
}

// This is a test for issue 3272.
func TestEmptyTemplate(t *testing.T) {
func TestEmptyTemplateHTML(t *testing.T) {
page := Must(New("page").ParseFiles(os.DevNull))
if err := page.ExecuteTemplate(os.Stdout, "page", "nothing"); err == nil {
t.Fatal("expected error")
Expand Down
Loading

0 comments on commit efbe47b

Please sign in to comment.