-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package template_test | ||
|
||
import ( | ||
"embed" | ||
"html/template" | ||
"strings" | ||
"testing" | ||
|
||
"go.adoublef.dev/is" | ||
. "go.adoublef.dev/sdk/html/template" | ||
) | ||
|
||
//go:embed all:testdata/*.html | ||
var fsys embed.FS | ||
|
||
func TestFS_Parse(t *testing.T) { | ||
t.Run("OK", func(t *testing.T) { | ||
var ( | ||
is = is.NewRelaxed(t) | ||
) | ||
|
||
tt, err := template.ParseFS(fsys, "testdata/base.html", "testdata/home.html") | ||
is.NoErr(err) // template.ParseFS | ||
|
||
var sb strings.Builder | ||
err = tt.Execute(&sb, nil) | ||
is.NoErr(err) // Template.Execute | ||
|
||
html := `<a>A</a><b>2</b> | ||
<c>C</c>` | ||
is.Equal(strings.TrimSpace(sb.String()), html) | ||
}) | ||
|
||
t.Run("OK", func(t *testing.T) { | ||
var ( | ||
is = is.NewRelaxed(t) | ||
) | ||
|
||
fs := NewFS(fsys) | ||
|
||
tt, err := fs.Parse("testdata/base.html", "testdata/home.html") | ||
is.NoErr(err) // FS.Parse | ||
|
||
var sb strings.Builder | ||
err = tt.Execute(&sb, nil) | ||
is.NoErr(err) // Template.Execute | ||
|
||
html := `<a>A</a><b>2</b> | ||
<c>C</c>` | ||
is.Equal(strings.TrimSpace(sb.String()), html) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<a>{{template "a" .}}</a><b>{{block "b" .}}B{{end}}</b> | ||
<c>{{block "c" .}}C{{end}}</c> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{define "a"}}A{{end}}{{define "b"}}2{{end}} |
This file was deleted.
Oops, something went wrong.