forked from GenieFramework/Genie.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_advanced_html_rendering.jl
94 lines (73 loc) · 2.18 KB
/
tests_advanced_html_rendering.jl
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
87
88
89
90
91
92
93
94
@safetestset "Advanced rendering" begin
@safetestset "for_each renders local variables" begin
using Genie
using Genie.Renderer.Html
import Genie.Util: fws
view = raw"""
<ol>
<% for_each(["a", "b", "c"]) do letter %>
<li>$(letter)</li>
<% end %>
</ol>"""
r = html(view)
@test String(r.body) |> fws ==
"<!DOCTYPE html><html><body><ol><li>a</li><li>b</li><li>c</li></ol></body></html>" |> fws
end;
# TODO: this test doesn't seem to check the right things - and most likely was passing by accident
# disabled for now -- to review
# @safetestset "for_each can not access module variables" begin
# using Genie
# using Genie.Renderer.Html
# x = 100
# view = raw"""
# <ol>
# <% for_each(["a", "b", "c"]) do letter %>
# <li>$(letter) = $x</li>
# <% end %>
# </ol>"""
# @test_throws UndefVarError html(view)
# end;
@safetestset "for_each can access view variables" begin
using Genie
using Genie.Renderer.Html
import Genie.Util: fws
view = raw"""
<ol>
<% for_each(["a", "b", "c"]) do letter %>
<li>$(letter) = $(vars(:x))</li>
<% end %>
</ol>"""
r = html(view, x = 100)
@test String(r.body) |> fws ==
"<!DOCTYPE html><html><body><ol><li>a = 100</li><li>b = 100</li><li>c = 100</li></ol></body></html>" |> fws
end;
@safetestset "for_each can access context variables" begin
using Genie
using Genie.Renderer.Html
import Genie.Util: fws
view = raw"""
<ol>
<% for_each(["a", "b", "c"]) do letter %>
<li>$(letter) = $x</li>
<% end %>
</ol>"""
r = html(view, context = @__MODULE__, x = 200)
@test String(r.body) |> fws ==
"<!DOCTYPE html><html><body><ol><li>a = 200</li><li>b = 200</li><li>c = 200</li></ol></body></html>" |> fws
end;
@safetestset "non registered tags are rendered" begin
using Genie
using Genie.Renderer.Html
import Genie.Util: fws
view = raw"""
<div>
<custom-tag>
<p>hello $name</p>
</custom-tag>
</div>
"""
r = html(view, name = "Adrian")
@test String(r.body) |> fws ==
"<!DOCTYPE html><html><body><div><custom-tag><p>hello Adrian</p></custom-tag></div></body></html>" |> fws
end;
end;