1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 module test_macro
is test_suite
20 class TestTemplateString
23 fun test_tpl_parse_1
do
28 <title>Dave's Profile</title>
35 var subject
= new TemplateString(tpl
)
36 var res
= subject
.write_to_string
40 fun test_tpl_parse_2
do
45 <title>%TITLE%</title>
52 var subject
= new TemplateString(tpl
)
53 var res
= subject
.write_to_string
57 fun test_tpl_parse_3
do
65 var subject
= new TemplateString(tpl
)
66 var res
= subject
.write_to_string
70 fun test_tpl_parse_4
do
81 var subject
= new TemplateString(tpl
)
82 var res
= subject
.write_to_string
86 fun test_tpl_parse_5
do
98 var subject
= new TemplateString(tpl
)
99 var res
= subject
.write_to_string
103 fun test_tpl_parse_6
do
114 var subject
= new TemplateString(tpl
)
115 var res
= subject
.write_to_string
119 fun test_tpl_replace_1
do
124 <title>%TITLE%</title>
135 <title>Hello World!</title>
138 <h1>Hello World!</h1>
142 var subject
= new TemplateString(tpl
)
143 subject
.replace
("TITLE", "Hello World!")
144 var res
= subject
.write_to_string
148 fun test_tpl_replace_2
do
153 <title>%TITLE%</title>
164 <title>Hello World!</title>
167 <h1>Hello World!</h1>
168 <p>Some body you want to know...</p>
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
178 fun test_tpl_replace_3
do
183 <title>%TITLE%</title>
194 <title>Hello World!</title>
197 <h1>Hello World!</h1>
198 <p><a href="#">Click me!</a></p>
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=\"#\">"
208 var res
= subject
.write_to_string