forked from slime-lang/slime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedded_engine_test.exs
127 lines (112 loc) · 3.29 KB
/
embedded_engine_test.exs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
defmodule RenderEmbeddedEngineTest do
use ExUnit.Case, async: true
import Slime, only: [render: 1]
test "render embedded javascript" do
slime = """
javascript:
alert('Slime supports embedded javascript!')
"""
assert render(slime) == ~s[<script>alert('Slime supports embedded javascript!')</script>]
end
test "render embedded javascript with blank lines" do
slime = """
javascript:
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
"""
assert render(slime) == ~s"""
<script>alert('Slime supports embedded javascript!')
\nalert('Slime supports embedded javascript!')</script>
""" |> String.strip(?\n)
end
test "render embedded multi-line nested javascript" do
slime = """
javascript:
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
"""
assert render(slime) == ~s"""
<script>alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')</script>
""" |> String.strip(?\n)
end
test "render embedded multi-line allow indent less than indent of first line" do
slime = """
javascript:
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
"""
assert render(slime) == ~s"""
<script>alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')
alert('Slime supports embedded javascript!')</script>
""" |> String.strip(?\n)
end
test "render embedded empty javascript" do
slime = """
javascript:
"""
assert render(slime) == ~s(<script></script>)
end
test "render embedded javascript with interpolation" do
slime = """
- a = "test"
javascript:
alert("Test \#{a}")
"""
assert render(slime) == ~s[<script>alert("Test test")</script>]
end
test "render embedded css" do
slime = """
css:
body {
color: black;
}
"""
assert render(slime) == ~s(<style type="text/css">body {\n color: black;\n}</style>)
end
test "render embedded css with interpolation" do
slime = ~S"""
- a = "white"
css:
#body {color: #{a};}
"""
assert render(slime) == ~s[<style type="text/css">#body {color: white;}</style>]
end
test "render embedded elixir" do
slime = """
elixir:
a =
[1, 2, 3]
|> Enum.map(&(&1 * &1))
= Enum.join(a, ",")
"""
assert render(slime) == ~s(1,4,9)
end
test "render embedded eex" do
slime = """
eex:
Test: <%= "test" %>
"""
assert render(slime) == ~s(Test: test)
end
defmodule TestEngine do
@moduledoc false
@behaviour Slime.Parser.EmbeddedEngine
def render(text, _options) do
{"div", attributes: [class: "test engine"], children: [text]}
end
end
test "render markdown with custom embedded engine" do
slime = """
test_engine:
Hello world!
"""
assert render(slime) == ~s(<div class="test engine">Hello world!</div>)
end
end