Пример #1
0
func BenchmarkElementPrinter(t *testing.B) {
	div := elems.Div()

	for i := 0; i < 10000; i++ {
		trees.NewText(fmt.Sprintf("%d", i)).Apply(div)
	}

	for i := 0; i < t.N; i++ {
		trees.SimpleElementWriter.Print(div)
	}
}
Пример #2
0
func TestElementPrinter(t *testing.T) {
	elem := trees.NewElement("bench", false)
	attrs.ClassName("grid col1").Apply(elem)
	elems.Div(trees.NewText("thunder")).Apply(elem)

	classes := &trees.ClassList{}
	classes.Add("x-icon")
	classes.Add("x-lock")

	classes.Apply(elem)

	res := trees.SimpleElementWriter.Print(elem)

	tests.Truthy(t, "Contains '<bench'", strings.Contains(res, "<bench"))
	tests.Truthy(t, "contains '</bench>'", strings.Contains(res, "</bench>"))
	tests.Truthy(t, "contains 'hash='", strings.Contains(res, "hash="))
	tests.Truthy(t, "contains 'uid='", strings.Contains(res, "uid="))
}