1 |
indexing |
2 |
|
3 |
meaning: |
4 |
"$(OPEN) |
5 |
This verbatim string should never be reported |
6 |
in a warning, because it is written in indexing clause. |
7 |
$(CLOSE)" |
8 |
|
9 |
class TEST |
10 |
|
11 |
create |
12 |
|
13 |
make |
14 |
|
15 |
feature {NONE} -- Creation |
16 |
|
17 |
make is |
18 |
-- Execute test. |
19 |
do |
20 |
-- Empty verbatim strings |
21 |
test_equality ( |
22 |
"$(OPEN) |
23 |
$(CLOSE)", |
24 |
"" |
25 |
) |
26 |
test_equality ( |
27 |
"$(OPEN) |
28 |
$(CLOSE)", |
29 |
"" |
30 |
) |
31 |
test_equality ( |
32 |
"$(OPEN) |
33 |
$(CLOSE)", |
34 |
"" |
35 |
) |
36 |
-- Verbatim strings with data |
37 |
test_equality ( |
38 |
"$(OPEN) |
39 |
ABC |
40 |
$(CLOSE)", |
41 |
"$(INDENT)ABC" |
42 |
) |
43 |
test_equality ( |
44 |
"$(OPEN) |
45 |
ABC |
46 |
abc |
47 |
$(CLOSE)", |
48 |
"$(INDENT)ABC%N$(INDENT)abc" |
49 |
) |
50 |
test_equality ( |
51 |
"$(OPEN) |
52 |
ABC |
53 |
$(CLOSE)", |
54 |
"$(INDENT)ABC %T" |
55 |
) |
56 |
test_equality ( |
57 |
"$(OPEN) |
58 |
ABC |
59 |
abc |
60 |
$(CLOSE)", |
61 |
"$(INDENT)ABC%N$(INDENT) abc" |
62 |
) |
63 |
test_equality ( |
64 |
"$(OPEN) |
65 |
ABC |
66 |
abc |
67 |
$(CLOSE)", |
68 |
"$(INDENT) ABC%N$(INDENT)abc" |
69 |
) |
70 |
test_equality ( |
71 |
"$(OPEN) |
72 |
ABC |
73 |
abc |
74 |
$(CLOSE)", |
75 |
"$(INDENT)$(SPACE)ABC%N$(INDENT)$(SPACE)abc" |
76 |
) |
77 |
-- Verbatim strings with special data |
78 |
test_equality ( |
79 |
"$(OPEN) |
80 |
$(CLOSE) |
81 |
$(CLOSE)", |
82 |
"$(INDENT)%/$(CLOSE_CODE)/" |
83 |
) |
84 |
test_equality ( |
85 |
"$(OPEN) |
86 |
$(CLOSE) |
87 |
$(CLOSE) |
88 |
$(CLOSE)", |
89 |
"$(INDENT)%/$(CLOSE_CODE)/%N$(INDENT)%/$(CLOSE_CODE)/" |
90 |
) |
91 |
test_equality ( |
92 |
"$(OPEN) |
93 |
$(CLOSE) |
94 |
$(CLOSE)", |
95 |
"$(INDENT)%/$(CLOSE_CODE)/ %T" |
96 |
) |
97 |
test_equality ( |
98 |
"$(OPEN) |
99 |
$(CLOSE) |
100 |
$(CLOSE) |
101 |
$(CLOSE)", |
102 |
"$(INDENT)%/$(CLOSE_CODE)/%N$(INDENT) %/$(CLOSE_CODE)/" |
103 |
) |
104 |
test_equality ( |
105 |
"$(OPEN) |
106 |
$(CLOSE) |
107 |
$(CLOSE) |
108 |
$(CLOSE)", |
109 |
"$(INDENT) %/$(CLOSE_CODE)/%N$(INDENT)%/$(CLOSE_CODE)/" |
110 |
) |
111 |
test_equality ( |
112 |
"$(OPEN) |
113 |
$(CLOSE) |
114 |
$(CLOSE) |
115 |
$(CLOSE)", |
116 |
"$(INDENT)$(SPACE)%/$(CLOSE_CODE)/%N$(INDENT)$(SPACE)%/$(CLOSE_CODE)/" |
117 |
) |
118 |
test_equality ( |
119 |
"$(OPEN) |
120 |
ABC$(CLOSE)" |
121 |
$(CLOSE)", |
122 |
"$(INDENT)ABC%/$(CLOSE_CODE)/%"" |
123 |
) |
124 |
test_equality ( |
125 |
"$(OPEN) |
126 |
ABC$(CLOSE)" |
127 |
abc$(CLOSE)" |
128 |
$(CLOSE)", |
129 |
"$(INDENT)ABC%/$(CLOSE_CODE)/%"%N$(INDENT)abc%/$(CLOSE_CODE)/%"" |
130 |
) |
131 |
test_equality ( |
132 |
"$(OPEN) |
133 |
ABC$(CLOSE)" |
134 |
$(CLOSE)", |
135 |
"$(INDENT)ABC%/$(CLOSE_CODE)/%" %T" |
136 |
) |
137 |
test_equality ( |
138 |
"$(OPEN) |
139 |
ABC$(CLOSE)" |
140 |
abc$(CLOSE)" |
141 |
$(CLOSE)", |
142 |
"$(INDENT)ABC%/$(CLOSE_CODE)/%"%N$(INDENT) abc%/$(CLOSE_CODE)/%"" |
143 |
) |
144 |
test_equality ( |
145 |
"$(OPEN) |
146 |
ABC$(CLOSE)" |
147 |
abc$(CLOSE)" |
148 |
$(CLOSE)", |
149 |
"$(INDENT) ABC%/$(CLOSE_CODE)/%"%N$(INDENT)abc%/$(CLOSE_CODE)/%"" |
150 |
) |
151 |
test_equality ( |
152 |
"$(OPEN) |
153 |
ABC$(CLOSE)" |
154 |
abc$(CLOSE)" |
155 |
$(CLOSE)", |
156 |
"$(INDENT)$(SPACE)ABC%/$(CLOSE_CODE)/%"%N$(INDENT)$(SPACE)abc%/$(CLOSE_CODE)/%"" |
157 |
) |
158 |
test_equality ( |
159 |
"$(OPEN) |
160 |
ABC$(CLOSE) |
161 |
$(CLOSE)", |
162 |
"$(INDENT)ABC%/$(CLOSE_CODE)/" |
163 |
) |
164 |
test_equality ( |
165 |
"$(OPEN) |
166 |
ABC$(CLOSE) |
167 |
abc$(CLOSE) |
168 |
$(CLOSE)", |
169 |
"$(INDENT)ABC%/$(CLOSE_CODE)/%N$(INDENT)abc%/$(CLOSE_CODE)/" |
170 |
) |
171 |
test_equality ( |
172 |
"$(OPEN) |
173 |
ABC$(CLOSE) |
174 |
$(CLOSE)", |
175 |
"$(INDENT)ABC%/$(CLOSE_CODE)/ %T" |
176 |
) |
177 |
test_equality ( |
178 |
"$(OPEN) |
179 |
ABC$(CLOSE) |
180 |
abc$(CLOSE) |
181 |
$(CLOSE)", |
182 |
"$(INDENT)ABC%/$(CLOSE_CODE)/%N$(INDENT) abc%/$(CLOSE_CODE)/" |
183 |
) |
184 |
test_equality ( |
185 |
"$(OPEN) |
186 |
ABC$(CLOSE) |
187 |
abc$(CLOSE) |
188 |
$(CLOSE)", |
189 |
"$(INDENT) ABC%/$(CLOSE_CODE)/%N$(INDENT)abc%/$(CLOSE_CODE)/" |
190 |
) |
191 |
test_equality ( |
192 |
"$(OPEN) |
193 |
ABC$(CLOSE) |
194 |
abc$(CLOSE) |
195 |
$(CLOSE)", |
196 |
"$(INDENT)$(SPACE)ABC%/$(CLOSE_CODE)/%N$(INDENT)$(SPACE)abc%/$(CLOSE_CODE)/" |
197 |
) |
198 |
test_equality ( |
199 |
"$(OPEN) |
200 |
$(CLOSE_OTHER)" |
201 |
$(CLOSE)", |
202 |
"$(INDENT)%/$(CLOSE_OTHER_CODE)/%"" |
203 |
) |
204 |
-- Verbatim strings with non-empty opener and closer |
205 |
test_equality ( |
206 |
"++$(OPEN) |
207 |
]" |
208 |
$(CLOSE)++", |
209 |
"$(INDENT)%/93/%"" |
210 |
) |
211 |
test_equality ( |
212 |
"++$(OPEN) |
213 |
}" |
214 |
$(CLOSE)++", |
215 |
"$(INDENT)%/125/%"" |
216 |
) |
217 |
test_equality ( |
218 |
"%$(OPEN) |
219 |
$(CLOSE)%", |
220 |
"" |
221 |
) |
222 |
test_equality ( |
223 |
"$(OPEN)% |
224 |
%$(CLOSE)", |
225 |
"%/$(OPEN_CODE)/%/$(CLOSE_CODE)/" |
226 |
) |
227 |
test_equality ( |
228 |
"$(OPEN)$(CLOSE)", |
229 |
"%/$(OPEN_CODE)/%/$(CLOSE_CODE)/" |
230 |
) |
231 |
end |
232 |
|
233 |
feature {NONE} -- Tests |
234 |
|
235 |
test_number: INTEGER |
236 |
-- Last test number |
237 |
|
238 |
test_equality (s1, s2: STRING) is |
239 |
-- Check if `s1' and `s2' are not void and are equal. |
240 |
do |
241 |
test_number := test_number + 1 |
242 |
io.put_string ("Test " + test_number.out + ": ") |
243 |
if s1 /= Void and then s2 /= Void and then equal (s1, s2) then |
244 |
io.put_string ("OK%N") |
245 |
else |
246 |
io.put_string ("FAILED: ") |
247 |
print_string (s1) |
248 |
io.put_string (" instead of ") |
249 |
print_string (s2) |
250 |
io.put_character ('%N') |
251 |
end |
252 |
ensure |
253 |
test_number_increased: test_number = old test_number + 1 |
254 |
end |
255 |
|
256 |
feature {NONE} -- Output |
257 |
|
258 |
print_string (s: STRING) is |
259 |
-- Print string `s' escaping special characters. |
260 |
local |
261 |
i: INTEGER |
262 |
c: CHARACTER |
263 |
do |
264 |
io.put_character ('%"') |
265 |
from |
266 |
i := 1 |
267 |
until |
268 |
i > s.count |
269 |
loop |
270 |
c := s.item (i) |
271 |
inspect c |
272 |
when |
273 |
'%/0/' .. '%/8/', |
274 |
'%/10/' .. '%/31/', '%/127/' .. '%/255/' then |
275 |
io.put_string ("%%/") |
276 |
io.put_integer (c.code) |
277 |
io.put_character ('/') |
278 |
when '%"' then |
279 |
io.put_string ("%%%"") |
280 |
when '%%' then |
281 |
io.put_string ("%%%%") |
282 |
when '%'' then |
283 |
io.put_string ("%%%'") |
284 |
when '%T' then |
285 |
io.put_string ("%%T") |
286 |
else |
287 |
io.put_character (c) |
288 |
end |
289 |
i := i + 1 |
290 |
end |
291 |
io.put_character ('%"') |
292 |
end |
293 |
|
294 |
invariant |
295 |
|
296 |
non_negative_test_number: test_number >= 0 |
297 |
|
298 |
indexing |
299 |
|
300 |
meaning: |
301 |
"$(OPEN) |
302 |
This verbatim string should never be reported |
303 |
in a warning, because it is written in indexing clause. |
304 |
$(CLOSE)" |
305 |
|
306 |
end |