[READ-ONLY] Mirror of https://github.com/andrioid/humle. Write HTML with Go functions
0

Configure Feed

Select the types of activity you want to include in your feed.

humle / node_test.go
1.4 kB 59 lines
1package humle_test 2 3import ( 4 "fmt" 5 "html/template" 6 "testing" 7 8 . "github.com/andrioid/humle" 9) 10 11var testMatrix2 = TestCases{ 12 "with value": TestCase{ 13 Input: Div().Children(Text("test")), 14 Expected: `<div>test</div>`, 15 }, 16 "empty non-void": TestCase{ 17 Input: Div(), 18 Expected: `<div></div>`, 19 }, 20 "with class": TestCase{ 21 Input: Div(Class("bg-pink-500")), 22 Expected: `<div class="bg-pink-500"></div>`, 23 }, 24 "br": TestCase{ 25 Input: Br(), 26 Expected: `<br>`, 27 }, 28 "with text": TestCase{ 29 Input: Div().Children(Text("hello")), 30 Expected: `<div>hello</div>`, 31 }, 32 "with id and data": TestCase{ 33 Input: Div(ID("divid"), Data("show", `$tab === 'logs'`)), 34 Expected: fmt.Sprintf(`<div id="divid" data-show="%s"></div>`, template.HTMLEscapeString("$tab === 'logs'")), 35 }, 36 "raw": TestCase{ 37 Input: RawHTML("<div class=\"bg-blue-500\"></div>"), 38 Expected: `<div class="bg-blue-500"></div>`, 39 }, 40 "raw inside div": TestCase{ 41 Input: Div().Children(RawHTML("<div class=\"bg-blue-500\"></div>")), 42 Expected: `<div><div class="bg-blue-500"></div></div>`, 43 }, 44 "document empty": TestCase{ 45 Input: Document(), 46 Expected: `<!DOCTYPE html>`, 47 }, 48 "document with nodes": TestCase{ 49 Input: Document( 50 HTML().Children(Head(), 51 Body(), 52 )), 53 Expected: `<!DOCTYPE html><html><head></head><body></body></html>`, 54 }, 55} 56 57func TestRender(t *testing.T) { 58 testMatrix2.Test(t) 59}