slim 0.6.1 → 0.7.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,458 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSlimEngine < MiniTest::Unit::TestCase
4
-
5
- def setup
6
- @env = Env.new
7
- end
8
-
9
- def test_simple_render
10
- string = <<HTML
11
- html
12
- head
13
- title Simple Test Title
14
- body
15
- p Hello World, meet Slim.
16
- HTML
17
-
18
- expected = "<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>"
19
-
20
- assert_equal expected, Slim::Engine.new(string).render
21
- end
22
-
23
- def test_render_with_conditional
24
- string = <<HTML
25
- div
26
- - if show_first?
27
- p The first paragraph
28
- - else
29
- p The second paragraph
30
- HTML
31
-
32
- expected = "<div><p>The second paragraph</p></div>"
33
-
34
- assert_equal expected, Slim::Engine.new(string).render(@env)
35
- end
36
-
37
- def test_render_with_consecutive_conditionals
38
- string = <<HTML
39
- div
40
- - if show_first? true
41
- p The first paragraph
42
- - if show_first? true
43
- p The second paragraph
44
- HTML
45
-
46
- expected = "<div><p>The first paragraph</p><p>The second paragraph</p></div>"
47
-
48
- assert_equal expected, Slim::Engine.new(string).render(@env)
49
- end
50
-
51
- def test_render_with_parameterized_conditional
52
- string = <<HTML
53
- div
54
- - if show_first? false
55
- p The first paragraph
56
- - else
57
- p The second paragraph
58
- HTML
59
-
60
- expected = "<div><p>The second paragraph</p></div>"
61
-
62
- assert_equal expected, Slim::Engine.new(string).render(@env)
63
- end
64
-
65
- def test_render_with_call
66
- string = <<HTML
67
- p
68
- = hello_world
69
- HTML
70
-
71
- expected = "<p>Hello World from @env</p>"
72
-
73
- assert_equal expected, Slim::Engine.new(string).render(@env)
74
- end
75
-
76
- def test_render_with_conditional_call
77
- string = <<HTML
78
- p
79
- = hello_world if true
80
- HTML
81
-
82
- expected = "<p>Hello World from @env</p>"
83
-
84
- assert_equal expected, Slim::Engine.new(string).render(@env)
85
- end
86
-
87
- def test_render_with_parameterized_call
88
- string = <<HTML
89
- p
90
- = hello_world("Hello Ruby!")
91
- HTML
92
-
93
- expected = "<p>Hello Ruby!</p>"
94
-
95
- assert_equal expected, Slim::Engine.new(string).render(@env)
96
- end
97
-
98
- def test_render_with_spaced_parameterized_call
99
- string = <<HTML
100
- p
101
- = hello_world "Hello Ruby!"
102
- HTML
103
-
104
- expected = "<p>Hello Ruby!</p>"
105
-
106
- assert_equal expected, Slim::Engine.new(string).render(@env)
107
- end
108
-
109
- def test_render_with_spaced_parameterized_call_2
110
- string = <<HTML
111
- p
112
- = hello_world "Hello Ruby!", :dummy => "value"
113
- HTML
114
-
115
- expected = "<p>Hello Ruby!dummy value</p>"
116
-
117
- assert_equal expected, Slim::Engine.new(string).render(@env)
118
- end
119
-
120
- def test_render_with_call_and_inline_text
121
- string = <<HTML
122
- h1 This is my title
123
- p
124
- = hello_world
125
- HTML
126
-
127
- expected = "<h1>This is my title</h1><p>Hello World from @env</p>"
128
-
129
- assert_equal expected, Slim::Engine.new(string).render(@env)
130
- end
131
-
132
- def test_render_with_call_to_set_attributes
133
- string = <<HTML
134
- p id="#\{id_helper}" class="hello world" = hello_world
135
- HTML
136
-
137
- expected = "<p id=\"notice\" class=\"hello world\">Hello World from @env</p>"
138
-
139
- assert_equal expected, Slim::Engine.new(string).render(@env)
140
- end
141
-
142
- def test_render_with_call_to_set_custom_attributes
143
- string = <<HTML
144
- p data-id="#\{id_helper}" data-class="hello world"
145
- = hello_world
146
- HTML
147
-
148
- expected = "<p data-id=\"notice\" data-class=\"hello world\">Hello World from @env</p>"
149
-
150
- assert_equal expected, Slim::Engine.new(string).render(@env)
151
- end
152
-
153
- def test_render_with_shortcut_attributes
154
- string = <<HTML
155
- h1#title This is my title
156
- #notice.hello.world
157
- = hello_world
158
- HTML
159
-
160
- expected = "<h1 id=\"title\">This is my title</h1><div id=\"notice\" class=\"hello world\">Hello World from @env</div>"
161
-
162
- assert_equal expected, Slim::Engine.new(string).render(@env)
163
- end
164
-
165
- def test_render_with_call_to_set_attributes_and_call_to_set_content
166
- string = <<HTML
167
- p id="#\{id_helper}" class="hello world" = hello_world
168
- HTML
169
-
170
- expected = "<p id=\"notice\" class=\"hello world\">Hello World from @env</p>"
171
-
172
- assert_equal expected, Slim::Engine.new(string).render(@env)
173
- end
174
-
175
- def test_render_with_parameterized_call_to_set_attributes_and_call_to_set_content
176
- string = <<HTML
177
- p id="#\{id_helper}" class="hello world" = hello_world("Hello Ruby!")
178
- HTML
179
-
180
- expected = "<p id=\"notice\" class=\"hello world\">Hello Ruby!</p>"
181
-
182
- assert_equal expected, Slim::Engine.new(string).render(@env)
183
- end
184
-
185
- def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content
186
- string = <<HTML
187
- p id="#\{id_helper}" class="hello world" = hello_world "Hello Ruby!"
188
- HTML
189
-
190
- expected = "<p id=\"notice\" class=\"hello world\">Hello Ruby!</p>"
191
-
192
- assert_equal expected, Slim::Engine.new(string).render(@env)
193
- end
194
-
195
- def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content_2
196
- string = <<HTML
197
- p id="#\{id_helper}" class="hello world" = hello_world "Hello Ruby!", :dummy => "value"
198
- HTML
199
-
200
- expected = "<p id=\"notice\" class=\"hello world\">Hello Ruby!dummy value</p>"
201
-
202
- assert_equal expected, Slim::Engine.new(string).render(@env)
203
- end
204
-
205
- def test_render_with_text_block
206
- string = <<HTML
207
- p
208
- `
209
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
210
- HTML
211
-
212
- expected = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>"
213
-
214
- assert_equal expected, Slim::Engine.new(string).render(@env)
215
- end
216
-
217
- def test_render_with_text_block_with_subsequent_markup
218
- string = <<HTML
219
- p
220
- `
221
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
222
- p Some more markup
223
- HTML
224
-
225
- expected = "<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><p>Some more markup</p>"
226
-
227
- assert_equal expected, Slim::Engine.new(string).render(@env)
228
- end
229
-
230
- def test_render_with_output_code_block
231
- string = <<HTML
232
- p
233
- = hello_world "Hello Ruby!" do
234
- | Hello from within a block!
235
- HTML
236
-
237
- expected = "<p>Hello from within a block!Hello Ruby!</p>"
238
-
239
- assert_equal expected, Slim::Engine.new(string).render(@env)
240
- end
241
-
242
- def test_render_with_output_code_within_block
243
- string = <<HTML
244
- p
245
- = hello_world "Hello Ruby!" do
246
- = hello_world "Hello from within a block! "
247
- HTML
248
-
249
- expected = "<p>Hello from within a block! Hello Ruby!</p>"
250
-
251
- assert_equal expected, Slim::Engine.new(string).render(@env)
252
- end
253
-
254
- def test_render_with_control_code_loop
255
- string = <<HTML
256
- p
257
- - 3.times do
258
- | Hey!
259
- HTML
260
-
261
- expected = "<p>Hey!Hey!Hey!</p>"
262
-
263
- assert_equal expected, Slim::Engine.new(string).render(@env)
264
- end
265
-
266
- def test_render_with_inline_condition
267
- string = <<HTML
268
- p = hello_world if true
269
- HTML
270
-
271
- expected = "<p>Hello World from @env</p>"
272
-
273
- assert_equal expected, Slim::Engine.new(string).render(@env)
274
- end
275
-
276
- def test_render_with_attribute_starts_with_keyword
277
- string = <<HTML
278
- p = hello_world in_keyword
279
- HTML
280
-
281
- expected = "<p>starts with keyword</p>"
282
-
283
- assert_equal expected, Slim::Engine.new(string).render(@env)
284
- end
285
-
286
- def test_hash_call
287
- string = <<HTML
288
- p = hash[:a]
289
- HTML
290
-
291
- expected = "<p>The letter a</p>"
292
-
293
- assert_equal expected, Slim::Engine.new(string).render(@env)
294
- end
295
-
296
- def test_hash_call_in_attribute
297
- string = <<HTML
298
- p id="#\{hash[:a]}" Test it
299
- HTML
300
-
301
- expected = "<p id=\"The letter a\">Test it</p>"
302
-
303
- assert_equal expected, Slim::Engine.new(string).render(@env)
304
- end
305
-
306
-
307
- def test_escaping_evil_method
308
- string = <<HTML
309
- p = evil_method
310
- HTML
311
-
312
- expected = "<p>&lt;script&gt;do_something_evil();&lt;&#47;script&gt;</p>"
313
-
314
- assert_equal expected, Slim::Engine.new(string).render(@env)
315
- end
316
-
317
-
318
- def test_nested_text
319
- string = <<HTML
320
- p
321
- |
322
- This is line one.
323
- This is line two.
324
- This is line three.
325
- This is line four.
326
- p This is a new paragraph.
327
- HTML
328
-
329
- expected = "<p>This is line one. This is line two. This is line three. This is line four.</p><p>This is a new paragraph.</p>"
330
-
331
- assert_equal expected, Slim::Engine.new(string).render(@env)
332
- end
333
-
334
- def test_nested_text_with_nested_html
335
- string = <<HTML
336
- p
337
- |
338
- This is line one.
339
- This is line two.
340
- This is line three.
341
- This is line four.
342
- span.bold This is a bold line in the paragraph.
343
- | This is more content.
344
- HTML
345
-
346
- expected = "<p>This is line one. This is line two. This is line three. This is line four.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>"
347
-
348
- assert_equal expected, Slim::Engine.new(string).render(@env)
349
-
350
- end
351
-
352
-
353
- def test_simple_paragraph_with_padding
354
- string = <<HTML
355
- p There will be 3 spaces in front of this line.
356
- HTML
357
-
358
- expected = "<p> There will be 3 spaces in front of this line.</p>"
359
-
360
- assert_equal expected, Slim::Engine.new(string).render(@env)
361
- end
362
-
363
- def test_output_code_with_leading_spaces
364
- string = <<HTML
365
- p= hello_world
366
- p = hello_world
367
- p = hello_world
368
- HTML
369
-
370
- expected = "<p>Hello World from @env</p><p>Hello World from @env</p><p>Hello World from @env</p>"
371
-
372
- assert_equal expected, Slim::Engine.new(string).render(@env)
373
- end
374
-
375
- def test_interpolation_in_text
376
- string = <<HTML
377
- p
378
- | \#{hello_world}
379
- p
380
- |
381
- A message from the compiler: \#{hello_world}
382
- HTML
383
-
384
- expected = "<p>Hello World from @env</p><p>A message from the compiler: Hello World from @env</p>"
385
-
386
- assert_equal expected, Slim::Engine.new(string).render(@env)
387
- end
388
-
389
- def test_interpolation_in_tag
390
- string = <<HTML
391
- p \#{hello_world}
392
- HTML
393
-
394
- expected = "<p>Hello World from @env</p>"
395
-
396
- assert_equal expected, Slim::Engine.new(string).render(@env)
397
- end
398
-
399
- def test_escape_interpolation
400
- string = <<HTML
401
- p \\\#{hello_world}
402
- HTML
403
-
404
- expected = "<p>\#{hello_world}</p>"
405
-
406
- assert_equal expected, Slim::Engine.new(string).render(@env)
407
- end
408
-
409
- def test_number_type_interpolation
410
- string = <<HTML
411
- p = output_number
412
- HTML
413
-
414
- expected = "<p>1337</p>"
415
-
416
- assert_equal expected, Slim::Engine.new(string).render(@env)
417
- end
418
-
419
- def test_dashed_attributes
420
- string = <<HTML
421
- p data-info="Illudium Q-36" = output_number
422
- HTML
423
-
424
- expected = %(<p data-info="Illudium Q-36">1337</p>)
425
-
426
- assert_equal expected, Slim::Engine.new(string).render(@env)
427
- end
428
-
429
- def test_dashed_attributes_with_shortcuts
430
- string = <<HTML
431
- p#marvin.martian data-info="Illudium Q-36" = output_number
432
- HTML
433
-
434
- expected = %(<p id="marvin" class="martian" data-info="Illudium Q-36">1337</p>)
435
-
436
- assert_equal expected, Slim::Engine.new(string).render(@env)
437
- end
438
-
439
- def test_parens_around_attributes
440
- string = <<HTML
441
- p(id="marvin" class="martian" data-info="Illudium Q-36") = output_number
442
- HTML
443
-
444
- expected = %(<p id="marvin" class="martian" data-info="Illudium Q-36">1337</p>)
445
-
446
- assert_equal expected, Slim::Engine.new(string).render(@env)
447
- end
448
-
449
- def test_parens_around_attributes_with_equal_sign_snug_to_right_paren
450
- string = <<HTML
451
- p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number
452
- HTML
453
-
454
- expected = %(<p id="marvin" class="martian" data-info="Illudium Q-36">1337</p>)
455
-
456
- assert_equal expected, Slim::Engine.new(string).render(@env)
457
- end
458
- end