-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.nim
87 lines (74 loc) · 2.08 KB
/
test.nim
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import karax / [karaxdsl, vdom]
import unittest, os, strutils
import ../src/kview
const places = @["boston", "cleveland", "los angeles", "new orleans"]
proc login*(name: string): string {.writeExample.} =
let vnode = buildHtml(tdiv(class = "mt-3")):
h1: text "My Web Page"
p: text "Hello " & name
ul:
for place in places:
li: text place
dl:
dt: text "Can I use Karax for client side single page apps?"
dd: text "Yes"
dt: text "Can I use Karax for server side HTML rendering?"
dd: text "Yes"
result = $vnode
proc loginNoExport(name: string): string {.writeExample.} =
let vnode = buildHtml(tdiv(class = "mt-3")):
h1: text "My Web Page"
p: text "Hello " & name
ul:
for place in places:
li: text place
dl:
dt: text "Can I use Karax for client side single page apps?"
dd: text "Yes"
dt: text "Can I use Karax for server side HTML rendering?"
dd: text "Yes"
result = $vnode
suite "Test Karax View":
const
first = "first"
second = "second"
test "can generate test_login.html":
discard login(first)
discard login(second)
check readFile("tests/test_login.html").strip() == """<div class="mt-3">
<h1>My Web Page</h1>
<p>Hello first</p>
<ul>
<li>boston</li>
<li>cleveland</li>
<li>los angeles</li>
<li>new orleans</li>
</ul>
<dl>
<dt>Can I use Karax for client side single page apps?</dt>
<dd>Yes</dd>
<dt>Can I use Karax for server side HTML rendering?</dt>
<dd>Yes</dd>
</dl>
</div>
""".strip()
test "can generate test_loginNoExport.html":
discard loginNoExport(first)
discard loginNoExport(second)
check readFile("tests/test_loginNoExport.html").strip() == """<div class="mt-3">
<h1>My Web Page</h1>
<p>Hello first</p>
<ul>
<li>boston</li>
<li>cleveland</li>
<li>los angeles</li>
<li>new orleans</li>
</ul>
<dl>
<dt>Can I use Karax for client side single page apps?</dt>
<dd>Yes</dd>
<dt>Can I use Karax for server side HTML rendering?</dt>
<dd>Yes</dd>
</dl>
</div>
""".strip()