static / dynamic test
This commit is contained in:
parent
688d2e5090
commit
1208857c5f
1 changed files with 17 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ package h
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/html"
|
"golang.org/x/net/html"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -104,13 +105,25 @@ func TestConditional(t *testing.T) {
|
||||||
assert.Equal(t, "<div ></div>", result)
|
assert.Equal(t, "<div ></div>", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkMailTo(b *testing.B) {
|
func BenchmarkMailToStatic(b *testing.B) {
|
||||||
|
b.ReportAllocs()
|
||||||
|
ctx := RenderContext{
|
||||||
|
builder: &strings.Builder{},
|
||||||
|
}
|
||||||
|
page := MailTo("myemail")
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
page.Render(&ctx)
|
||||||
|
ctx.builder.Reset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkMailToDynamic(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
ctx := RenderContext{
|
ctx := RenderContext{
|
||||||
builder: &strings.Builder{},
|
builder: &strings.Builder{},
|
||||||
}
|
}
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
MailTo().Render(&ctx)
|
MailTo(uuid.NewString()).Render(&ctx)
|
||||||
ctx.builder.Reset()
|
ctx.builder.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -252,7 +265,7 @@ func ComplexPage() *Element {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MailTo() *Element {
|
func MailTo(email string) *Element {
|
||||||
return Div(
|
return Div(
|
||||||
H1(
|
H1(
|
||||||
Text("Contact Us"),
|
Text("Contact Us"),
|
||||||
|
|
@ -264,7 +277,7 @@ func MailTo() *Element {
|
||||||
Div(
|
Div(
|
||||||
Text("email:"),
|
Text("email:"),
|
||||||
A(
|
A(
|
||||||
Href("mailto:"+"test@htmgo.dev"),
|
Href(email),
|
||||||
Text("Email me"),
|
Text("Email me"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue