-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditional_test.go
42 lines (37 loc) · 1.05 KB
/
conditional_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
package hagl_test
import (
assert "github.com/stretchr/testify/require"
"testing"
. "github.com/gschier/hagl"
)
func TestSwitch(t *testing.T) {
t.Run("matches default case", func(t *testing.T) {
r := Div().Children(
Switch("foo").
Case("bar", func() Node { return Text("bar") }).
Case("baz", func() Node { return Text("baz") }).
Default(func() Node { return Text("default") }).
GetNode(),
)
assert.Equal(t, "<div>default</div>", r.ToHTML())
})
t.Run("matches case", func(t *testing.T) {
r := Div().Children(
Switch("baz").
Case("bar", func() Node { return Text("bar") }).
Case("baz", func() Node { return Text("baz") }).
Default(func() Node { return Text("default") }).
GetNode(),
)
assert.Equal(t, "<div>baz</div>", r.ToHTML())
})
t.Run("matches default but no default set", func(t *testing.T) {
r := Div().Children(
Switch("foo").
Case("bar", func() Node { return Text("bar") }).
Case("baz", func() Node { return Text("baz") }).
GetNode(),
)
assert.Equal(t, "<div></div>", r.ToHTML())
})
}