nitc: fix calling extern constructors from extern code in separate compiler
[nit.git] / lib / template / test_macro.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 module test_macro is test_suite
16
17 import test_suite
18 import macro
19
20 class TestTemplateString
21 super TestSuite
22
23 fun test_tpl_parse_1 do
24 var tpl = """
25 <!DOCTYPE html>
26 <html lang="en">
27 <head>
28 <title>Dave's Profile</title>
29 </head>
30 <body>
31 <h1>Dave</h1>
32 <p>Profile</p>
33 </body>
34 </html>"""
35 var subject = new TemplateString(tpl)
36 var res = subject.write_to_string
37 assert res == tpl
38 end
39
40 fun test_tpl_parse_2 do
41 var tpl = """
42 <!DOCTYPE html>
43 <html lang="en">
44 <head>
45 <title>%TITLE%</title>
46 </head>
47 <body>
48 <h1>%TITLE%</h1>
49 <p>%ARTICLE%</p>
50 </body>
51 </html>"""
52 var subject = new TemplateString(tpl)
53 var res = subject.write_to_string
54 assert res == tpl
55 end
56
57 fun test_tpl_parse_3 do
58 var tpl = """
59 <!DOCTYPE html>
60 <html lang="en">
61 <head>
62 <title>%</title>
63 </head>
64 </html>"""
65 var subject = new TemplateString(tpl)
66 var res = subject.write_to_string
67 assert res == tpl
68 end
69
70 fun test_tpl_parse_4 do
71 var tpl = """
72 <!DOCTYPE html>
73 <html lang="en">
74 <head>
75 <title>%</title>
76 </head>
77 <body>
78 <h1>%</h1>
79 </body>
80 </html>"""
81 var subject = new TemplateString(tpl)
82 var res = subject.write_to_string
83 assert res == tpl
84 end
85
86 fun test_tpl_parse_5 do
87 var tpl = """
88 <!DOCTYPE html>
89 <html lang="en">
90 <head>
91 <title>%</title>
92 </head>
93 <body>
94 <h1>%TITLE%</h1>
95 <p>%ARTICLE%</p>
96 </body>
97 </html>"""
98 var subject = new TemplateString(tpl)
99 var res = subject.write_to_string
100 assert res == tpl
101 end
102
103 fun test_tpl_parse_6 do
104 var tpl = """
105 <!DOCTYPE html>
106 <html lang="en">
107 <head>
108 <title>%</title>
109 </head>
110 <body>
111 <h1>%%</h1>
112 </body>
113 </html>"""
114 var subject = new TemplateString(tpl)
115 var res = subject.write_to_string
116 assert res == tpl
117 end
118
119 fun test_tpl_replace_1 do
120 var tpl = """
121 <!DOCTYPE html>
122 <html lang="en">
123 <head>
124 <title>%TITLE%</title>
125 </head>
126 <body>
127 <h1>%TITLE%</h1>
128 <p>%ARTICLE%</p>
129 </body>
130 </html>"""
131 var exp = """
132 <!DOCTYPE html>
133 <html lang="en">
134 <head>
135 <title>Hello World!</title>
136 </head>
137 <body>
138 <h1>Hello World!</h1>
139 <p>%ARTICLE%</p>
140 </body>
141 </html>"""
142 var subject = new TemplateString(tpl)
143 subject.replace("TITLE", "Hello World!")
144 var res = subject.write_to_string
145 assert res == exp
146 end
147
148 fun test_tpl_replace_2 do
149 var tpl = """
150 <!DOCTYPE html>
151 <html lang="en">
152 <head>
153 <title>%TITLE%</title>
154 </head>
155 <body>
156 <h1>%TITLE%</h1>
157 <p>%BODY%</p>
158 </body>
159 </html>"""
160 var exp = """
161 <!DOCTYPE html>
162 <html lang="en">
163 <head>
164 <title>Hello World!</title>
165 </head>
166 <body>
167 <h1>Hello World!</h1>
168 <p>Some body you want to know...</p>
169 </body>
170 </html>"""
171 var subject = new TemplateString(tpl)
172 subject.replace("TITLE", "Hello World!")
173 subject.replace("BODY", "Some body you want to know...")
174 var res = subject.write_to_string
175 assert res == exp
176 end
177
178 fun test_tpl_replace_3 do
179 var tpl = """
180 <!DOCTYPE html>
181 <html lang="en">
182 <head>
183 <title>%TITLE%</title>
184 </head>
185 <body>
186 <h1>%TITLE%</h1>
187 <p>%BODY%</p>
188 </body>
189 </html>"""
190 var exp = """
191 <!DOCTYPE html>
192 <html lang="en">
193 <head>
194 <title>Hello World!</title>
195 </head>
196 <body>
197 <h1>Hello World!</h1>
198 <p><a href="#">Click me!</a></p>
199 </body>
200 </html>"""
201 var link = new Template
202 var subject = new TemplateString(tpl)
203 subject.replace("TITLE", "Hello World!")
204 subject.replace("BODY", link)
205 link.add "<a href=\"#\">"
206 link.add "Click me!"
207 link.add "</a>"
208 var res = subject.write_to_string
209 assert res == exp
210 end
211 end