Skip to content

Commit

Permalink
chore: extend tests to cover HTML tags within comments
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Sep 29, 2023
1 parent 80ade14 commit efd3312
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 6 deletions.
1 change: 1 addition & 0 deletions generator/test-html-comment/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
<p>third paragraph</p>
<!-- commented out string expression: { content } -->
<span>sample content</span>
<!-- <div>comment with html</div> -->
2 changes: 2 additions & 0 deletions generator/test-html-comment/template.templ
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ templ render(content string) {
@paragraph("third paragraph")
<!-- commented out string expression: { content } -->
<span>{ content }</span>
<!-- <div>comment with html</div> -->
}

templ paragraph(content string) {
<p>{ content }</p>
}

21 changes: 15 additions & 6 deletions generator/test-html-comment/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions generator/test-method/expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>You can implement methods on a type.</div>
26 changes: 26 additions & 0 deletions generator/test-method/render_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package testmethod

import (
_ "embed"
"testing"

"github.com/a-h/templ/generator/htmldiff"
)

//go:embed expected.html
var expected string

func Test(t *testing.T) {
d := Data{
message: "You can implement methods on a type.",
}
component := d.Method()

diff, err := htmldiff.Diff(component, expected)
if err != nil {
t.Fatal(err)
}
if diff != "" {
t.Error(diff)
}
}
10 changes: 10 additions & 0 deletions generator/test-method/template.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package testmethod

type Data struct {
message string
}

templ (d Data) Method() {
<div>{ d.message }</div>
}

47 changes: 47 additions & 0 deletions generator/test-method/template_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efd3312

Please sign in to comment.