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
19 class TestTemplateString
22 fun test_tpl_parse_1
is test
do
27 <title>Dave's Profile</title>
34 var subject
= new TemplateString(tpl
)
35 var res
= subject
.write_to_string
39 fun test_tpl_parse_2
is test
do
44 <title>%TITLE%</title>
51 var subject
= new TemplateString(tpl
)
52 var res
= subject
.write_to_string
56 fun test_tpl_parse_3
is test
do
64 var subject
= new TemplateString(tpl
)
65 var res
= subject
.write_to_string
69 fun test_tpl_parse_4
is test
do
80 var subject
= new TemplateString(tpl
)
81 var res
= subject
.write_to_string
85 fun test_tpl_parse_5
is test
do
97 var subject
= new TemplateString(tpl
)
98 var res
= subject
.write_to_string
102 fun test_tpl_parse_6
is test
do
113 var subject
= new TemplateString(tpl
)
114 var res
= subject
.write_to_string
118 fun test_tpl_replace_1
is test
do
123 <title>%TITLE%</title>
134 <title>Hello World!</title>
137 <h1>Hello World!</h1>
141 var subject
= new TemplateString(tpl
)
142 subject
.replace
("TITLE", "Hello World!")
143 var res
= subject
.write_to_string
147 fun test_tpl_replace_2
is test
do
152 <title>%TITLE%</title>
163 <title>Hello World!</title>
166 <h1>Hello World!</h1>
167 <p>Some body you want to know...</p>
170 var subject
= new TemplateString(tpl
)
171 subject
.replace
("TITLE", "Hello World!")
172 subject
.replace
("BODY", "Some body you want to know...")
173 var res
= subject
.write_to_string
177 fun test_tpl_replace_3
is test
do
182 <title>%TITLE%</title>
193 <title>Hello World!</title>
196 <h1>Hello World!</h1>
197 <p><a href="#">Click me!</a></p>
200 var link
= new Template
201 var subject
= new TemplateString(tpl
)
202 subject
.replace
("TITLE", "Hello World!")
203 subject
.replace
("BODY", link
)
204 link
.add
"<a href=\"#\">"
207 var res
= subject
.write_to_string