Debian Codegraph @

t/test-spec.lisp

raw
1 ;;;; Auto-generated from mustache spec
2 (in-package :cl-user)
3 (defpackage #:mustache-test-spec
4 (:use #:cl #:prove))
5 (in-package :mustache-test-spec)
6
7 (plan 124)
8 (is
9 (mustache:render* "12345 {{! Comment Block! }} 67890"
10 (mustache:make-context :data 'nil :partials 'nil))
11 "12345 67890"
12 (format nil "~A :: ~A" "Surrounding Whitespace"
13 "Comment removal should preserve surrounding whitespace."))
14 (is
15 (mustache:render* " 12 {{! 34 }}
16 "
17 (mustache:make-context :data 'nil :partials 'nil))
18 " 12
19 "
20 (format nil "~A :: ~A" "Indented Inline"
21 "Inline comments should not strip whitespace"))
22 (is
23 (mustache:render* "Begin.
24 {{!
25 Something's going on here...
26 }}
27 End.
28 "
29 (mustache:make-context :data 'nil :partials 'nil))
30 "Begin.
31 End.
32 "
33 (format nil "~A :: ~A" "Indented Multiline Standalone"
34 "All standalone comment lines should be removed."))
35 (is
36 (mustache:render* "Begin.
37 {{!
38 Something's going on here...
39 }}
40 End.
41 "
42 (mustache:make-context :data 'nil :partials 'nil))
43 "Begin.
44 End.
45 "
46 (format nil "~A :: ~A" "Multiline Standalone"
47 "All standalone comment lines should be removed."))
48 (is
49 (mustache:render* "!
50 {{! I'm Still Standalone }}"
51 (mustache:make-context :data 'nil :partials 'nil))
52 "!
53 "
54 (format nil "~A :: ~A" "Standalone Without Newline"
55 "Standalone tags should not require a newline to follow them."))
56 (is
57 (mustache:render* " {{! I'm Still Standalone }}
58 !"
59 (mustache:make-context :data 'nil :partials 'nil))
60 "!"
61 (format nil "~A :: ~A" "Standalone Without Previous Line"
62 "Standalone tags should not require a newline to precede them."))
63 (is
64 (mustache:render* "|
65 {{! Standalone Comment }}
66 |"
67 (mustache:make-context :data 'nil :partials 'nil))
68 "|
69 |"
70 (format nil "~A :: ~A" "Standalone Line Endings"
71 "\"\\r\\n\" should be considered a newline for standalone tags."))
72 (is
73 (mustache:render* "Begin.
74 {{! Indented Comment Block! }}
75 End.
76 "
77 (mustache:make-context :data 'nil :partials 'nil))
78 "Begin.
79 End.
80 "
81 (format nil "~A :: ~A" "Indented Standalone"
82 "All standalone comment lines should be removed."))
83 (is
84 (mustache:render* "Begin.
85 {{! Comment Block! }}
86 End.
87 "
88 (mustache:make-context :data 'nil :partials 'nil))
89 "Begin.
90 End.
91 "
92 (format nil "~A :: ~A" "Standalone"
93 "All standalone comment lines should be removed."))
94 (is
95 (mustache:render* "12345{{!
96 This is a
97 multi-line comment...
98 }}67890
99 "
100 (mustache:make-context :data 'nil :partials 'nil))
101 "1234567890
102 "
103 (format nil "~A :: ~A" "Multiline"
104 "Multiline comments should be permitted."))
105 (is
106 (mustache:render* "12345{{! Comment Block! }}67890"
107 (mustache:make-context :data 'nil :partials 'nil))
108 "1234567890"
109 (format nil "~A :: ~A" "Inline"
110 "Comment blocks should be removed from the template."))
111 (is
112 (mustache:render* "|{{= @ @ =}}|"
113 (mustache:make-context :data 'nil :partials 'nil))
114 "||"
115 (format nil "~A :: ~A" "Pair with Padding"
116 "Superfluous in-tag whitespace should be ignored."))
117 (is
118 (mustache:render* "=
119 {{=@ @=}}"
120 (mustache:make-context :data 'nil :partials 'nil))
121 "=
122 "
123 (format nil "~A :: ~A" "Standalone Without Newline"
124 "Standalone tags should not require a newline to follow them."))
125 (is
126 (mustache:render* " {{=@ @=}}
127 ="
128 (mustache:make-context :data 'nil :partials 'nil))
129 "="
130 (format nil "~A :: ~A" "Standalone Without Previous Line"
131 "Standalone tags should not require a newline to precede them."))
132 (is
133 (mustache:render* "|
134 {{= @ @ =}}
135 |"
136 (mustache:make-context :data 'nil :partials 'nil))
137 "|
138 |"
139 (format nil "~A :: ~A" "Standalone Line Endings"
140 "\"\\r\\n\" should be considered a newline for standalone tags."))
141 (is
142 (mustache:render* "Begin.
143 {{=@ @=}}
144 End.
145 "
146 (mustache:make-context :data 'nil :partials 'nil))
147 "Begin.
148 End.
149 "
150 (format nil "~A :: ~A" "Indented Standalone Tag"
151 "Indented standalone lines should be removed from the template."))
152 (is
153 (mustache:render* "Begin.
154 {{=@ @=}}
155 End.
156 "
157 (mustache:make-context :data 'nil :partials 'nil))
158 "Begin.
159 End.
160 "
161 (format nil "~A :: ~A" "Standalone Tag"
162 "Standalone lines should be removed from the template."))
163 (is
164 (mustache:render* " | {{=@ @=}}
165 "
166 (mustache:make-context :data 'nil :partials 'nil))
167 " |
168 "
169 (format nil "~A :: ~A" "Outlying Whitespace (Inline)"
170 "Whitespace should be left untouched."))
171 (is
172 (mustache:render* "| {{=@ @=}} |"
173 (mustache:make-context :data 'nil :partials 'nil))
174 "| |"
175 (format nil "~A :: ~A" "Surrounding Whitespace"
176 "Surrounding whitespace should be left untouched."))
177 (is
178 (mustache:render* "[ {{>include}} ]
179 [ .{{value}}. .|value|. ]
180 "
181 (mustache:make-context :data '((:value . "yes")) :partials
182 '((:include . ".{{value}}. {{= | | =}} .|value|."))))
183 "[ .yes. .yes. ]
184 [ .yes. .|value|. ]
185 "
186 (format nil "~A :: ~A" "Post-Partial Behavior"
187 "Delimiters set in a partial should not affect the parent template."))
188 (is
189 (mustache:render* "[ {{>include}} ]
190 {{= | | =}}
191 [ |>include| ]
192 "
193 (mustache:make-context :data '((:value . "yes")) :partials
194 '((:include . ".{{value}}."))))
195 "[ .yes. ]
196 [ .yes. ]
197 "
198 (format nil "~A :: ~A" "Partial Inheritence"
199 "Delimiters set in a parent template should not affect a partial."))
200 (is
201 (mustache:render* "[
202 {{^section}}
203 {{data}}
204 |data|
205 {{/section}}
206
207 {{= | | =}}
208 |^section|
209 {{data}}
210 |data|
211 |/section|
212 ]
213 "
214 (mustache:make-context :data '((:section) (:data . "I got interpolated."))
215 :partials 'nil))
216 "[
217 I got interpolated.
218 |data|
219
220 {{data}}
221 I got interpolated.
222 ]
223 "
224 (format nil "~A :: ~A" "Inverted Sections"
225 "Delimiters set outside inverted sections should persist."))
226 (is
227 (mustache:render* "[
228 {{#section}}
229 {{data}}
230 |data|
231 {{/section}}
232
233 {{= | | =}}
234 |#section|
235 {{data}}
236 |data|
237 |/section|
238 ]
239 "
240 (mustache:make-context :data '((:section . t) (:data . "I got interpolated."))
241 :partials 'nil))
242 "[
243 I got interpolated.
244 |data|
245
246 {{data}}
247 I got interpolated.
248 ]
249 "
250 (format nil "~A :: ~A" "Sections"
251 "Delimiters set outside sections should persist."))
252 (is
253 (mustache:render* "({{=[ ]=}}[text])"
254 (mustache:make-context :data '((:text . "It worked!")) :partials 'nil))
255 "(It worked!)"
256 (format nil "~A :: ~A" "Special Characters"
257 "Characters with special meaning regexen should be valid delimiters."))
258 (is
259 (mustache:render* "{{=<% %>=}}(<%text%>)"
260 (mustache:make-context :data '((:text . "Hey!")) :partials 'nil))
261 "(Hey!)"
262 (format nil "~A :: ~A" "Pair Behavior"
263 "The equals sign (used on both sides) should permit delimiter changes."))
264 (is
265 (mustache:render* "|{{& string }}|"
266 (mustache:make-context :data '((:string . "---")) :partials 'nil))
267 "|---|"
268 (format nil "~A :: ~A" "Ampersand With Padding"
269 "Superfluous in-tag whitespace should be ignored."))
270 (is
271 (mustache:render* "|{{{ string }}}|"
272 (mustache:make-context :data '((:string . "---")) :partials 'nil))
273 "|---|"
274 (format nil "~A :: ~A" "Triple Mustache With Padding"
275 "Superfluous in-tag whitespace should be ignored."))
276 (is
277 (mustache:render* "|{{ string }}|"
278 (mustache:make-context :data '((:string . "---")) :partials 'nil))
279 "|---|"
280 (format nil "~A :: ~A" "Interpolation With Padding"
281 "Superfluous in-tag whitespace should be ignored."))
282 (is
283 (mustache:render* " {{&string}}
284 "
285 (mustache:make-context :data '((:string . "---")) :partials 'nil))
286 " ---
287 "
288 (format nil "~A :: ~A" "Ampersand - Standalone"
289 "Standalone interpolation should not alter surrounding whitespace."))
290 (is
291 (mustache:render* " {{{string}}}
292 "
293 (mustache:make-context :data '((:string . "---")) :partials 'nil))
294 " ---
295 "
296 (format nil "~A :: ~A" "Triple Mustache - Standalone"
297 "Standalone interpolation should not alter surrounding whitespace."))
298 (is
299 (mustache:render* " {{string}}
300 "
301 (mustache:make-context :data '((:string . "---")) :partials 'nil))
302 " ---
303 "
304 (format nil "~A :: ~A" "Interpolation - Standalone"
305 "Standalone interpolation should not alter surrounding whitespace."))
306 (is
307 (mustache:render* "| {{&string}} |"
308 (mustache:make-context :data '((:string . "---")) :partials 'nil))
309 "| --- |"
310 (format nil "~A :: ~A" "Ampersand - Surrounding Whitespace"
311 "Interpolation should not alter surrounding whitespace."))
312 (is
313 (mustache:render* "| {{{string}}} |"
314 (mustache:make-context :data '((:string . "---")) :partials 'nil))
315 "| --- |"
316 (format nil "~A :: ~A" "Triple Mustache - Surrounding Whitespace"
317 "Interpolation should not alter surrounding whitespace."))
318 (is
319 (mustache:render* "| {{string}} |"
320 (mustache:make-context :data '((:string . "---")) :partials 'nil))
321 "| --- |"
322 (format nil "~A :: ~A" "Interpolation - Surrounding Whitespace"
323 "Interpolation should not alter surrounding whitespace."))
324 (is
325 (mustache:render* "\"{{#a}}{{b.c.d.e.name}}{{/a}}\" == \"Phil\""
326 (mustache:make-context :data
327 '((:a (:b (:c (:d (:e (:name . "Phil"))))))
328 (:b (:c (:d (:e (:name . "Wrong"))))))
329 :partials 'nil))
330 "\"Phil\" == \"Phil\""
331 (format nil "~A :: ~A" "Dotted Names - Initial Resolution"
332 "The first part of a dotted name should resolve as any other name."))
333 (is
334 (mustache:render* "\"{{a.b.c.name}}\" == \"\""
335 (mustache:make-context :data '((:a (:b)) (:c (:name . "Jim"))) :partials 'nil))
336 "\"\" == \"\""
337 (format nil "~A :: ~A" "Dotted Names - Broken Chain Resolution"
338 "Each part of a dotted name should resolve only against its parent."))
339 (is
340 (mustache:render* "\"{{a.b.c}}\" == \"\""
341 (mustache:make-context :data '((:a)) :partials 'nil))
342 "\"\" == \"\""
343 (format nil "~A :: ~A" "Dotted Names - Broken Chains"
344 "Any falsey value prior to the last part of the name should yield ''."))
345 (is
346 (mustache:render* "\"{{a.b.c.d.e.name}}\" == \"Phil\""
347 (mustache:make-context :data '((:a (:b (:c (:d (:e (:name . "Phil")))))))
348 :partials 'nil))
349 "\"Phil\" == \"Phil\""
350 (format nil "~A :: ~A" "Dotted Names - Arbitrary Depth"
351 "Dotted names should be functional to any level of nesting."))
352 (is
353 (mustache:render*
354 "\"{{&person.name}}\" == \"{{#person}}{{&name}}{{/person}}\""
355 (mustache:make-context :data '((:person (:name . "Joe"))) :partials 'nil))
356 "\"Joe\" == \"Joe\""
357 (format nil "~A :: ~A" "Dotted Names - Ampersand Interpolation"
358 "Dotted names should be considered a form of shorthand for sections."))
359 (is
360 (mustache:render*
361 "\"{{{person.name}}}\" == \"{{#person}}{{{name}}}{{/person}}\""
362 (mustache:make-context :data '((:person (:name . "Joe"))) :partials 'nil))
363 "\"Joe\" == \"Joe\""
364 (format nil "~A :: ~A" "Dotted Names - Triple Mustache Interpolation"
365 "Dotted names should be considered a form of shorthand for sections."))
366 (is
367 (mustache:render*
368 "\"{{person.name}}\" == \"{{#person}}{{name}}{{/person}}\""
369 (mustache:make-context :data '((:person (:name . "Joe"))) :partials 'nil))
370 "\"Joe\" == \"Joe\""
371 (format nil "~A :: ~A" "Dotted Names - Basic Interpolation"
372 "Dotted names should be considered a form of shorthand for sections."))
373 (is
374 (mustache:render* "I ({{&cannot}}) be seen!"
375 (mustache:make-context :data 'nil :partials 'nil))
376 "I () be seen!"
377 (format nil "~A :: ~A" "Ampersand Context Miss Interpolation"
378 "Failed context lookups should default to empty strings."))
379 (is
380 (mustache:render* "I ({{{cannot}}}) be seen!"
381 (mustache:make-context :data 'nil :partials 'nil))
382 "I () be seen!"
383 (format nil "~A :: ~A" "Triple Mustache Context Miss Interpolation"
384 "Failed context lookups should default to empty strings."))
385 (is
386 (mustache:render* "I ({{cannot}}) be seen!"
387 (mustache:make-context :data 'nil :partials 'nil))
388 "I () be seen!"
389 (format nil "~A :: ~A" "Basic Context Miss Interpolation"
390 "Failed context lookups should default to empty strings."))
391 (is
392 (with-standard-io-syntax
393 (mustache:render* "\"{{&power}} jiggawatts!\""
394 (mustache:make-context :data '((:power . 1.21f0))
395 :partials 'nil)))
396 "\"1.21 jiggawatts!\""
397 (format nil "~A :: ~A" "Ampersand Decimal Interpolation"
398 "Decimals should interpolate seamlessly with proper significance."))
399 (is
400 (with-standard-io-syntax
401 (mustache:render* "\"{{{power}}} jiggawatts!\""
402 (mustache:make-context :data '((:power . 1.21f0))
403 :partials 'nil)))
404 "\"1.21 jiggawatts!\""
405 (format nil "~A :: ~A" "Triple Mustache Decimal Interpolation"
406 "Decimals should interpolate seamlessly with proper significance."))
407 (is
408 (with-standard-io-syntax
409 (mustache:render* "\"{{power}} jiggawatts!\""
410 (mustache:make-context :data '((:power . 1.21f0))
411 :partials 'nil)))
412 "\"1.21 jiggawatts!\""
413 (format nil "~A :: ~A" "Basic Decimal Interpolation"
414 "Decimals should interpolate seamlessly with proper significance."))
415 (is
416 (mustache:render* "\"{{&mph}} miles an hour!\""
417 (mustache:make-context :data '((:mph . 85)) :partials 'nil))
418 "\"85 miles an hour!\""
419 (format nil "~A :: ~A" "Ampersand Integer Interpolation"
420 "Integers should interpolate seamlessly."))
421 (is
422 (mustache:render* "\"{{{mph}}} miles an hour!\""
423 (mustache:make-context :data '((:mph . 85)) :partials 'nil))
424 "\"85 miles an hour!\""
425 (format nil "~A :: ~A" "Triple Mustache Integer Interpolation"
426 "Integers should interpolate seamlessly."))
427 (is
428 (mustache:render* "\"{{mph}} miles an hour!\""
429 (mustache:make-context :data '((:mph . 85)) :partials 'nil))
430 "\"85 miles an hour!\""
431 (format nil "~A :: ~A" "Basic Integer Interpolation"
432 "Integers should interpolate seamlessly."))
433 (is
434 (mustache:render*
435 "These characters should not be HTML escaped: {{&forbidden}}
436 "
437 (mustache:make-context :data '((:forbidden . "& \" < >")) :partials 'nil))
438 "These characters should not be HTML escaped: & \" < >
439 "
440 (format nil "~A :: ~A" "Ampersand"
441 "Ampersand should interpolate without HTML escaping."))
442 (is
443 (mustache:render*
444 "These characters should not be HTML escaped: {{{forbidden}}}
445 "
446 (mustache:make-context :data '((:forbidden . "& \" < >")) :partials 'nil))
447 "These characters should not be HTML escaped: & \" < >
448 "
449 (format nil "~A :: ~A" "Triple Mustache"
450 "Triple mustaches should interpolate without HTML escaping."))
451 (is
452 (mustache:render*
453 "These characters should be HTML escaped: {{forbidden}}
454 "
455 (mustache:make-context :data '((:forbidden . "& \" < >")) :partials 'nil))
456 "These characters should be HTML escaped: &amp; &quot; &lt; &gt;
457 "
458 (format nil "~A :: ~A" "HTML Escaping"
459 "Basic interpolation should be HTML escaped."))
460 (is
461 (mustache:render* "Hello, {{subject}}!
462 "
463 (mustache:make-context :data '((:subject . "world")) :partials 'nil))
464 "Hello, world!
465 "
466 (format nil "~A :: ~A" "Basic Interpolation"
467 "Unadorned tags should interpolate content into the template."))
468 (is
469 (mustache:render* "Hello from {Mustache}!
470 "
471 (mustache:make-context :data 'nil :partials 'nil))
472 "Hello from {Mustache}!
473 "
474 (format nil "~A :: ~A" "No Interpolation"
475 "Mustache-free templates should render as-is."))
476 (is
477 (mustache:render* "|{{^ boolean }}={{/ boolean }}|"
478 (mustache:make-context :data '((:boolean)) :partials 'nil))
479 "|=|"
480 (format nil "~A :: ~A" "Padding"
481 "Superfluous in-tag whitespace should be ignored."))
482 (is
483 (mustache:render* "^{{^boolean}}
484 /
485 {{/boolean}}"
486 (mustache:make-context :data '((:boolean)) :partials 'nil))
487 "^
488 /
489 "
490 (format nil "~A :: ~A" "Standalone Without Newline"
491 "Standalone tags should not require a newline to follow them."))
492 (is
493 (mustache:render* " {{^boolean}}
494 ^{{/boolean}}
495 /"
496 (mustache:make-context :data '((:boolean)) :partials 'nil))
497 "^
498 /"
499 (format nil "~A :: ~A" "Standalone Without Previous Line"
500 "Standalone tags should not require a newline to precede them."))
501 (is
502 (mustache:render* "|
503 {{^boolean}}
504 {{/boolean}}
505 |"
506 (mustache:make-context :data '((:boolean)) :partials 'nil))
507 "|
508 |"
509 (format nil "~A :: ~A" "Standalone Line Endings"
510 "\"\\r\\n\" should be considered a newline for standalone tags."))
511 (is
512 (mustache:render* "| This Is
513 {{^boolean}}
514 |
515 {{/boolean}}
516 | A Line
517 "
518 (mustache:make-context :data '((:boolean)) :partials 'nil))
519 "| This Is
520 |
521 | A Line
522 "
523 (format nil "~A :: ~A" "Standalone Indented Lines"
524 "Standalone indented lines should be removed from the template."))
525 (is
526 (mustache:render* "| This Is
527 {{^boolean}}
528 |
529 {{/boolean}}
530 | A Line
531 "
532 (mustache:make-context :data '((:boolean)) :partials 'nil))
533 "| This Is
534 |
535 | A Line
536 "
537 (format nil "~A :: ~A" "Standalone Lines"
538 "Standalone lines should be removed from the template."))
539 (is
540 (mustache:render* " {{^boolean}}NO{{/boolean}}
541 {{^boolean}}WAY{{/boolean}}
542 "
543 (mustache:make-context :data '((:boolean)) :partials 'nil))
544 " NO
545 WAY
546 "
547 (format nil "~A :: ~A" "Indented Inline Sections"
548 "Single-line sections should not alter surrounding whitespace."))
549 (is
550 (mustache:render* " | {{^boolean}} {{! Important Whitespace }}
551 {{/boolean}} |
552 "
553 (mustache:make-context :data '((:boolean)) :partials 'nil))
554 " |
555 |
556 "
557 (format nil "~A :: ~A" "Internal Whitespace"
558 "Inverted should not alter internal whitespace."))
559 (is
560 (mustache:render* " | {{^boolean}} | {{/boolean}} |
561 "
562 (mustache:make-context :data '((:boolean)) :partials 'nil))
563 " | | |
564 "
565 (format nil "~A :: ~A" "Surrounding Whitespace"
566 "Inverted sections should not alter surrounding whitespace."))
567 (is
568 (mustache:render* "\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"Not Here\""
569 (mustache:make-context :data '((:a)) :partials 'nil))
570 "\"Not Here\" == \"Not Here\""
571 (format nil "~A :: ~A" "Dotted Names - Broken Chains"
572 "Dotted names that cannot be resolved should be considered falsey."))
573 (is
574 (mustache:render* "\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"Not Here\""
575 (mustache:make-context :data '((:a (:b (:c)))) :partials 'nil))
576 "\"Not Here\" == \"Not Here\""
577 (format nil "~A :: ~A" "Dotted Names - Falsey"
578 "Dotted names should be valid for Inverted Section tags."))
579 (is
580 (mustache:render* "\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"\""
581 (mustache:make-context :data '((:a (:b (:c . t)))) :partials 'nil))
582 "\"\" == \"\""
583 (format nil "~A :: ~A" "Dotted Names - Truthy"
584 "Dotted names should be valid for Inverted Section tags."))
585 (is
586 (mustache:render*
587 "[{{^missing}}Cannot find key 'missing'!{{/missing}}]"
588 (mustache:make-context :data 'nil :partials 'nil))
589 "[Cannot find key 'missing'!]"
590 (format nil "~A :: ~A" "Context Misses"
591 "Failed context lookups should be considered falsey."))
592 (is
593 (mustache:render*
594 "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
595 (mustache:make-context :data '((:bool . t)) :partials 'nil))
596 "| A E |"
597 (format nil "~A :: ~A" "Nested (Truthy)"
598 "Nested truthy sections should be omitted."))
599 (is
600 (mustache:render*
601 "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
602 (mustache:make-context :data '((:bool)) :partials 'nil))
603 "| A B C D E |"
604 (format nil "~A :: ~A" "Nested (Falsey)"
605 "Nested falsey sections should have their contents rendered."))
606 (is
607 (mustache:render* "{{^bool}}
608 * first
609 {{/bool}}
610 * {{two}}
611 {{^bool}}
612 * third
613 {{/bool}}
614 "
615 (mustache:make-context :data '((:two . "second") (:bool)) :partials 'nil))
616 "* first
617 * second
618 * third
619 "
620 (format nil "~A :: ~A" "Doubled"
621 "Multiple inverted sections per template should be permitted."))
622 (is
623 (mustache:render* "\"{{^list}}Yay lists!{{/list}}\""
624 (mustache:make-context :data '((:list . #())) :partials 'nil))
625 "\"Yay lists!\""
626 (format nil "~A :: ~A" "Empty List"
627 "Empty lists should behave like falsey values."))
628 (is
629 (mustache:render* "\"{{^list}}{{n}}{{/list}}\""
630 (mustache:make-context :data '((:list . #(((:n . 1)) ((:n . 2)) ((:n . 3)))))
631 :partials 'nil))
632 "\"\""
633 (format nil "~A :: ~A" "List" "Lists should behave like truthy values."))
634 (is
635 (mustache:render* "\"{{^context}}Hi {{name}}.{{/context}}\""
636 (mustache:make-context :data '((:context (:name . "Joe"))) :partials 'nil))
637 "\"\""
638 (format nil "~A :: ~A" "Context"
639 "Objects and hashes should behave like truthy values."))
640 (is
641 (mustache:render*
642 "\"{{^boolean}}This should not be rendered.{{/boolean}}\""
643 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
644 "\"\""
645 (format nil "~A :: ~A" "Truthy"
646 "Truthy sections should have their contents omitted."))
647 (is
648 (mustache:render*
649 "\"{{^boolean}}This should be rendered.{{/boolean}}\""
650 (mustache:make-context :data '((:boolean)) :partials 'nil))
651 "\"This should be rendered.\""
652 (format nil "~A :: ~A" "Falsey"
653 "Falsey sections should have their contents rendered."))
654 (is
655 (mustache:render* "|{{> partial }}|"
656 (mustache:make-context :data '((:boolean . t)) :partials '((:partial . "[]"))))
657 "|[]|"
658 (format nil "~A :: ~A" "Padding Whitespace"
659 "Superfluous in-tag whitespace should be ignored."))
660 (is
661 (mustache:render* "\\
662 {{>partial}}
663 /
664 "
665 (mustache:make-context :data
666 '((:content . "<
667 ->"))
668 :partials
669 '((:partial . "|
670 {{{content}}}
671 |
672 "))))
673 "\\
674 |
675 <
676 ->
677 |
678 /
679 "
680 (format nil "~A :: ~A" "Standalone Indentation"
681 "Each line of the partial should be indented before rendering."))
682 (is
683 (mustache:render* ">
684 {{>partial}}"
685 (mustache:make-context :data 'nil :partials
686 '((:partial . ">
687 >"))))
688 ">
689 >
690 >"
691 (format nil "~A :: ~A" "Standalone Without Newline"
692 "Standalone tags should not require a newline to follow them."))
693 (is
694 (mustache:render* " {{>partial}}
695 >"
696 (mustache:make-context :data 'nil :partials
697 '((:partial . ">
698 >"))))
699 " >
700 >>"
701 (format nil "~A :: ~A" "Standalone Without Previous Line"
702 "Standalone tags should not require a newline to precede them."))
703 (is
704 (mustache:render* "|
705 {{>partial}}
706 |"
707 (mustache:make-context :data 'nil :partials '((:partial . ">"))))
708 "|
709 >|"
710 (format nil "~A :: ~A" "Standalone Line Endings"
711 "\"\\r\\n\" should be considered a newline for standalone tags."))
712 (is
713 (mustache:render* " {{data}} {{> partial}}
714 "
715 (mustache:make-context :data '((:data . "|")) :partials
716 '((:partial . ">
717 >"))))
718 " | >
719 >
720 "
721 (format nil "~A :: ~A" "Inline Indentation"
722 "Whitespace should be left untouched."))
723 (is
724 (mustache:render* "| {{>partial}} |"
725 (mustache:make-context :data 'nil :partials '((:partial . " | "))))
726 "| | |"
727 (format nil "~A :: ~A" "Surrounding Whitespace"
728 "The greater-than operator should not alter surrounding whitespace."))
729 (is
730 (mustache:render* "{{>node}}"
731 (mustache:make-context :data
732 '((:content . "X") (:nodes . #(((:content . "Y") (:nodes . #())))))
733 :partials '((:node . "{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"))))
734 "X<Y<>>"
735 (format nil "~A :: ~A" "Recursion"
736 "The greater-than operator should properly recurse."))
737 (is
738 (mustache:render* "\"{{>partial}}\""
739 (mustache:make-context :data '((:text . "content")) :partials
740 '((:partial . "*{{text}}*"))))
741 "\"*content*\""
742 (format nil "~A :: ~A" "Context"
743 "The greater-than operator should operate within the current context."))
744 (is
745 (mustache:render* "\"{{>text}}\""
746 (mustache:make-context :data 'nil :partials 'nil))
747 "\"\""
748 (format nil "~A :: ~A" "Failed Lookup"
749 "The empty string should be used when the named partial is not found."))
750 (is
751 (mustache:render* "\"{{>text}}\""
752 (mustache:make-context :data 'nil :partials '((:text . "from partial"))))
753 "\"from partial\""
754 (format nil "~A :: ~A" "Basic Behavior"
755 "The greater-than operator should expand to the named partial."))
756 (is
757 (mustache:render* "|{{# boolean }}={{/ boolean }}|"
758 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
759 "|=|"
760 (format nil "~A :: ~A" "Padding"
761 "Superfluous in-tag whitespace should be ignored."))
762 (is
763 (mustache:render* "#{{#boolean}}
764 /
765 {{/boolean}}"
766 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
767 "#
768 /
769 "
770 (format nil "~A :: ~A" "Standalone Without Newline"
771 "Standalone tags should not require a newline to follow them."))
772 (is
773 (mustache:render* " {{#boolean}}
774 #{{/boolean}}
775 /"
776 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
777 "#
778 /"
779 (format nil "~A :: ~A" "Standalone Without Previous Line"
780 "Standalone tags should not require a newline to precede them."))
781 (is
782 (mustache:render* "|
783 {{#boolean}}
784 {{/boolean}}
785 |"
786 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
787 "|
788 |"
789 (format nil "~A :: ~A" "Standalone Line Endings"
790 "\"\\r\\n\" should be considered a newline for standalone tags."))
791 (is
792 (mustache:render* "| This Is
793 {{#boolean}}
794 |
795 {{/boolean}}
796 | A Line
797 "
798 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
799 "| This Is
800 |
801 | A Line
802 "
803 (format nil "~A :: ~A" "Indented Standalone Lines"
804 "Indented standalone lines should be removed from the template."))
805 (is
806 (mustache:render* "| This Is
807 {{#boolean}}
808 |
809 {{/boolean}}
810 | A Line
811 "
812 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
813 "| This Is
814 |
815 | A Line
816 "
817 (format nil "~A :: ~A" "Standalone Lines"
818 "Standalone lines should be removed from the template."))
819 (is
820 (mustache:render* " {{#boolean}}YES{{/boolean}}
821 {{#boolean}}GOOD{{/boolean}}
822 "
823 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
824 " YES
825 GOOD
826 "
827 (format nil "~A :: ~A" "Indented Inline Sections"
828 "Single-line sections should not alter surrounding whitespace."))
829 (is
830 (mustache:render* " | {{#boolean}} {{! Important Whitespace }}
831 {{/boolean}} |
832 "
833 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
834 " |
835 |
836 "
837 (format nil "~A :: ~A" "Internal Whitespace"
838 "Sections should not alter internal whitespace."))
839 (is
840 (mustache:render* " | {{#boolean}} | {{/boolean}} |
841 "
842 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
843 " | | |
844 "
845 (format nil "~A :: ~A" "Surrounding Whitespace"
846 "Sections should not alter surrounding whitespace."))
847 (is
848 (mustache:render* "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\""
849 (mustache:make-context :data '((:a)) :partials 'nil))
850 "\"\" == \"\""
851 (format nil "~A :: ~A" "Dotted Names - Broken Chains"
852 "Dotted names that cannot be resolved should be considered falsey."))
853 (is
854 (mustache:render* "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\""
855 (mustache:make-context :data '((:a (:b (:c)))) :partials 'nil))
856 "\"\" == \"\""
857 (format nil "~A :: ~A" "Dotted Names - Falsey"
858 "Dotted names should be valid for Section tags."))
859 (is
860 (mustache:render* "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"Here\""
861 (mustache:make-context :data '((:a (:b (:c . t)))) :partials 'nil))
862 "\"Here\" == \"Here\""
863 (format nil "~A :: ~A" "Dotted Names - Truthy"
864 "Dotted names should be valid for Section tags."))
865 (is
866 (with-standard-io-syntax
867 (mustache:render* "\"{{#list}}({{.}}){{/list}}\""
868 (mustache:make-context :data '((:list . #(1.1f0 2.2f0 3.3f0 4.4f0 5.5f0)))
869 :partials 'nil)))
870 "\"(1.1)(2.2)(3.3)(4.4)(5.5)\""
871 (format nil "~A :: ~A" "Implicit Iterator - Decimal"
872 "Implicit iterators should cast decimals to strings and interpolate."))
873 (is
874 (mustache:render* "\"{{#list}}({{.}}){{/list}}\""
875 (mustache:make-context :data '((:list . #(1 2 3 4 5))) :partials 'nil))
876 "\"(1)(2)(3)(4)(5)\""
877 (format nil "~A :: ~A" "Implicit Iterator - Integer"
878 "Implicit iterators should cast integers to strings and interpolate."))
879 (is
880 (mustache:render* "\"{{#list}}({{.}}){{/list}}\""
881 (mustache:make-context :data '((:list . #("a" "b" "c" "d" "e"))) :partials 'nil))
882 "\"(a)(b)(c)(d)(e)\""
883 (format nil "~A :: ~A" "Implicit Iterator - String"
884 "Implicit iterators should directly interpolate strings."))
885 (is
886 (mustache:render* "\"{{#list}}({{.}}){{/list}}\""
887 (mustache:make-context :data '((:list . #("<a>" "<b>" "<c>" "<d>" "<e>"))) :partials 'nil))
888 "\"(&lt;a&gt;)(&lt;b&gt;)(&lt;c&gt;)(&lt;d&gt;)(&lt;e&gt;)\""
889 (format nil "~A :: ~A" "Implicit Iterator - String"
890 "Implicit iterators should be properly escaped."))
891 (is
892 (mustache:render* "\"{{#list}}({{{.}}}){{/list}}\""
893 (mustache:make-context :data '((:list . #("<a>" "<b>" "<c>" "<d>" "<e>"))) :partials 'nil))
894 "\"(<a>)(<b>)(<c>)(<d>)(<e>)\""
895 (format nil "~A :: ~A" "Implicit Iterator - String"
896 "Triple Mustache implicit iterators should interpolate without HTML escaping."))
897 (is
898 (mustache:render* "[{{#missing}}Found key 'missing'!{{/missing}}]"
899 (mustache:make-context :data 'nil :partials 'nil))
900 "[]"
901 (format nil "~A :: ~A" "Context Misses"
902 "Failed context lookups should be considered falsey."))
903 (is
904 (mustache:render*
905 "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
906 (mustache:make-context :data '((:bool)) :partials 'nil))
907 "| A E |"
908 (format nil "~A :: ~A" "Nested (Falsey)"
909 "Nested falsey sections should be omitted."))
910 (is
911 (mustache:render*
912 "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
913 (mustache:make-context :data '((:bool . t)) :partials 'nil))
914 "| A B C D E |"
915 (format nil "~A :: ~A" "Nested (Truthy)"
916 "Nested truthy sections should have their contents rendered."))
917 (is
918 (mustache:render* "{{#bool}}
919 * first
920 {{/bool}}
921 * {{two}}
922 {{#bool}}
923 * third
924 {{/bool}}
925 "
926 (mustache:make-context :data '((:two . "second") (:bool . t)) :partials 'nil))
927 "* first
928 * second
929 * third
930 "
931 (format nil "~A :: ~A" "Doubled"
932 "Multiple sections per template should be permitted."))
933 (is
934 (mustache:render* "\"{{#list}}Yay lists!{{/list}}\""
935 (mustache:make-context :data '((:list . #())) :partials 'nil))
936 "\"\""
937 (format nil "~A :: ~A" "Empty List"
938 "Empty lists should behave like falsey values."))
939 (is
940 (mustache:render* "\"{{#list}}{{item}}{{/list}}\""
941 (mustache:make-context :data
942 '((:list . #(((:item . 1)) ((:item . 2)) ((:item . 3))))) :partials 'nil))
943 "\"123\""
944 (format nil "~A :: ~A" "List"
945 "Lists should be iterated; list items should visit the context stack."))
946 (is
947 (mustache:render* "{{#a}}
948 {{one}}
949 {{#b}}
950 {{one}}{{two}}{{one}}
951 {{#c}}
952 {{one}}{{two}}{{three}}{{two}}{{one}}
953 {{#d}}
954 {{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
955 {{#e}}
956 {{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
957 {{/e}}
958 {{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
959 {{/d}}
960 {{one}}{{two}}{{three}}{{two}}{{one}}
961 {{/c}}
962 {{one}}{{two}}{{one}}
963 {{/b}}
964 {{one}}
965 {{/a}}
966 "
967 (mustache:make-context :data
968 '((:a (:one . 1)) (:b (:two . 2)) (:c (:three . 3)) (:d (:four . 4))
969 (:e (:five . 5)))
970 :partials 'nil))
971 "1
972 121
973 12321
974 1234321
975 123454321
976 1234321
977 12321
978 121
979 1
980 "
981 (format nil "~A :: ~A" "Deeply Nested Contexts"
982 "All elements on the context stack should be accessible."))
983 (is
984 (mustache:render* "\"{{#context}}Hi {{name}}.{{/context}}\""
985 (mustache:make-context :data '((:context (:name . "Joe"))) :partials 'nil))
986 "\"Hi Joe.\""
987 (format nil "~A :: ~A" "Context"
988 "Objects and hashes should be pushed onto the context stack."))
989 (is
990 (mustache:render*
991 "\"{{#boolean}}This should not be rendered.{{/boolean}}\""
992 (mustache:make-context :data '((:boolean)) :partials 'nil))
993 "\"\""
994 (format nil "~A :: ~A" "Falsey"
995 "Falsey sections should have their contents omitted."))
996 (is
997 (mustache:render*
998 "\"{{#boolean}}This should be rendered.{{/boolean}}\""
999 (mustache:make-context :data '((:boolean . t)) :partials 'nil))
1000 "\"This should be rendered.\""
1001 (format nil "~A :: ~A" "Truthy"
1002 "Truthy sections should have their contents rendered."))
1003 (is
1004 (mustache:render* "<{{^lambda}}{{static}}{{/lambda}}>"
1005 (mustache:make-context :data
1006 `((:static . "static")
1007 (:lambda . ,(lambda (text)
1008 (declare (ignore text)))))
1009 :partials 'nil))
1010 "<>"
1011 (format nil "~A :: ~A" "Inverted Section"
1012 "Lambdas used for inverted sections should be considered truthy."))
1013 (is
1014 (mustache:render*
1015 "{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}"
1016 (mustache:make-context :data
1017 `((:lambda . ,(lambda (text) (format nil "__~a__" text))))
1018 :partials 'nil))
1019 "__FILE__ != __LINE__"
1020 (format nil "~A :: ~A" "Section - Multiple Calls"
1021 "Lambdas used for sections should not be cached."))
1022 (is
1023 (mustache:render* "{{= | | =}}<|#lambda|-|/lambda|>"
1024 (mustache:make-context :data
1025 `((:planet . "Earth")
1026 (:lambda . ,(lambda (text) (format nil "~a{{planet}} => |planet|~a" text text))))
1027 :partials 'nil))
1028 "<-{{planet}} => Earth->"
1029 (format nil "~A :: ~A" "Section - Alternate Delimiters"
1030 "Lambdas used for sections should parse with the current delimiters."))
1031 (is
1032 (mustache:render* "<{{#lambda}}-{{/lambda}}>"
1033 (mustache:make-context :data
1034 `((:planet . "Earth")
1035 (:lambda . ,(lambda (text) (format nil "~a{{planet}}~a" text text))))
1036 :partials 'nil))
1037 "<-Earth->"
1038 (format nil "~A :: ~A" "Section - Expansion"
1039 "Lambdas used for sections should have their results parsed."))
1040 (is
1041 (mustache:render* "<{{#lambda}}{{x}}{{/lambda}}>"
1042 (mustache:make-context :data
1043 `((:x . "Error!")
1044 (:lambda . ,(lambda (text) (if (equal text "{{x}}") "yes" "no"))))
1045 :partials 'nil))
1046 "<yes>"
1047 (format nil "~A :: ~A" "Section"
1048 "Lambdas used for sections should receive the raw section string."))
1049 (is
1050 (mustache:render* "<{{lambda}}{{{lambda}}}"
1051 (mustache:make-context :data
1052 `((:lambda . ,(lambda () ">")))
1053 :partials 'nil))
1054 "<&gt;>"
1055 (format nil "~A :: ~A" "Escaping"
1056 "Lambda results should be appropriately escaped."))
1057 (is
1058 (mustache:render* "{{lambda}} == {{{lambda}}} == {{lambda}}"
1059 (mustache:make-context :data
1060 `((:lambda . ,(let ((calls 0)) (lambda () (incf calls)))))
1061 :partials 'nil))
1062 "1 == 2 == 3"
1063 (format nil "~A :: ~A" "Interpolation - Multiple Calls"
1064 "Interpolated lambdas should not be cached."))
1065 (is
1066 (mustache:render* "{{= | | =}}
1067 Hello, (|&lambda|)!"
1068 (mustache:make-context :data
1069 `((:planet . "world")
1070 (:lambda . ,(lambda () "|planet| => {{planet}}")))
1071 :partials 'nil))
1072 "Hello, (|planet| => world)!"
1073 (format nil "~A :: ~A" "Interpolation - Alternate Delimiters"
1074 "A lambda's return value should parse with the default delimiters."))
1075 (is
1076 (mustache:render* "Hello, {{lambda}}!"
1077 (mustache:make-context :data
1078 `((:planet . "world")
1079 (:lambda . ,(lambda () "{{planet}}")))
1080 :partials 'nil))
1081 "Hello, world!"
1082 (format nil "~A :: ~A" "Interpolation - Expansion"
1083 "A lambda's return value should be parsed."))
1084 (is
1085 (mustache:render* "Hello, {{lambda}}!"
1086 (mustache:make-context :data
1087 `((:lambda . ,(lambda () "world")))
1088 :partials 'nil))
1089 "Hello, world!"
1090 (format nil "~A :: ~A" "Interpolation"
1091 "A lambda's return value should be interpolated."))
1092
1093 (finalize)