-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder_test.go
52 lines (47 loc) · 1.23 KB
/
builder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package smetana
import (
"log"
"strings"
"testing"
)
func TestWriteOpeningTag(t *testing.T) {
tag := "div"
attrs := Attrs{
"foo": "bar",
"hello": "world",
}
builder := Builder{strings.Builder{}, true, nil}
builder.writeOpeningTag(tag, attrs)
result := builder.Buf.String()
assertEqual(t, "<div foo=\"bar\" hello=\"world\">", result)
}
func TestWriteOpeningTagWithNonDeterministicAttributes(t *testing.T) {
tag := "div"
attrs := Attrs{
"foo": "bar",
"hello": "world",
}
builder := Builder{strings.Builder{}, false, nil}
builder.writeOpeningTag(tag, attrs)
result := builder.Buf.String()
if result[5] == 'f' {
assertEqual(t, "<div foo=\"bar\" hello=\"world\">", result)
} else {
assertEqual(t, "<div hello=\"world\" foo=\"bar\">", result)
}
}
func TestWriteClosingTag(t *testing.T) {
tag := "span"
builder := Builder{strings.Builder{}, true, nil}
builder.writeClosingTag(tag)
result := builder.Buf.String()
assertEqual(t, "</span>", result)
}
func TestCustomLogger(t *testing.T) {
var target strings.Builder
logger := log.New(&target, "", 0)
builder := Builder{strings.Builder{}, true, logger}
builder.Logger.Print("Hello world")
result := strings.TrimSpace(target.String())
assertEqual(t, "Hello world", result)
}