2 ;; Tests of everything in the reference.
3 ;; File is generated automatically from the text in reference.lisp by
4 ;; the function make-reference-tests-dot-lisp in ref2test.lisp
5 ;; so do not edit this file.
6 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
10 (test-ps-js statements-and-expressions-1
14 (test-ps-js statements-and-expressions-2
22 (test-ps-js symbol-conversion-1
24 "bangwhathashatpercent")
26 (test-ps-js symbol-conversion-2
30 (test-ps-js symbol-conversion-3
34 (test-ps-js symbol-conversion-6
38 (test-ps-js symbol-conversion-7
42 (test-ps-js number-literals-1
46 (test-ps-js number-literals-2
50 (test-ps-js number-literals-3
54 (test-ps-js string-literals-1
58 (test-ps-js string-literals-2
62 (test-ps-js array-literals-1
66 (test-ps-js array-literals-2
70 (test-ps-js array-literals-3
72 (array "foobar" "bratzel bub"))
73 "[ [ 2, 3 ], [ 'foobar', 'bratzel bub' ] ]")
75 (test-ps-js array-literals-4
79 (test-ps-js array-literals-5
83 (test-ps-js array-literals-6
86 (make-array "foobar" "bratzel bub"))
87 "new Array(new Array(2, 3), new Array('foobar', 'bratzel bub'))")
89 (test-ps-js object-literals-1
90 (create :foo
"bar" :blorg
1)
94 (test-ps-js object-literals-2
97 :another-object
(create :schtrunz
1))
100 anotherObject : { schtrunz : 1 } }")
102 (test-ps-js object-literals-3
103 (slot-value an-object
'foo
)
106 (test-ps-js object-literals-4
110 (test-ps-js object-literals-5
111 (with-slots (a b c
) this
113 "this.a + this.b + this.c;")
115 (test-ps-js regular-expression-literals-1
119 (test-ps-js regular-expression-literals-2
123 (test-ps-js literal-symbols-1
127 (test-ps-js literal-symbols-2
131 (test-ps-js literal-symbols-3
135 (test-ps-js literal-symbols-4
139 (test-ps-js literal-symbols-5
143 (test-ps-js variables-1
147 (test-ps-js variables-2
151 (test-ps-js variables-3
155 (test-ps-js variables-4
159 (test-ps-js function-calls-and-method-calls-1
163 (test-ps-js function-calls-and-method-calls-2
164 (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4))
165 "foobar(blorg(1, 2), blabla(3, 4), [ 2, 3, 4 ])")
167 (test-ps-js function-calls-and-method-calls-3
171 (test-ps-js function-calls-and-method-calls-4
175 (test-ps-js function-calls-and-method-calls-5
179 (test-ps-js function-calls-and-method-calls-6
180 (.blorg
(aref foobar
1) NIL T
)
181 "foobar[1].blorg(null, true)")
183 (test-ps-js operator-expressions-1
187 (test-ps-js operator-expressions-2
191 (test-ps-js operator-expressions-3
195 (test-ps-js operator-expressions-5
196 (* 1 (+ 2 3 4) 4 (/ 6 7))
197 "1 * (2 + 3 + 4) * 4 * (6 / 7)")
199 (test-ps-js operator-expressions-6
203 (test-ps-js operator-expressions-7
207 (test-ps-js operator-expressions-8
211 (test-ps-js operator-expressions-9
215 (test-ps-js operator-expressions-10
219 (test-ps-js operator-expressions-11
223 (test-ps-js body-forms-1
224 (progn (blorg i
) (blafoo i
))
228 (test-ps-js body-forms-2
229 (+ i
(progn (blorg i
) (blafoo i
)))
230 "i + (blorg(i), blafoo(i))")
232 (test-ps-js function-definition-1
233 (defun a-function (a b
)
235 "function aFunction(a, b) {
239 (test-ps-js function-definition-2
240 (lambda (a b
) (return (+ a b
)))
245 (test-ps-js assignment-1
249 (test-ps-js assignment-2
250 (setf a
2 b
3 c
4 x
(+ a b c
))
256 (test-ps-js assignment-3
257 (setf a
(+ a
2 3 4 a
))
258 "a += 2 + 3 + 4 + a;")
260 (test-ps-js assignment-4
264 (test-ps-js assignment-5
265 (defun (setf color
) (new-color el
)
266 (setf (slot-value (slot-value el
'style
) 'color
) new-color
))
267 "function __setf_color(newColor, el) {
268 el.style.color = newColor;
271 (test-ps-js assignment-6
272 (setf (color some-div
) (+ 23 "em"))
274 var _js1 = 23 + 'em';
275 __setf_color(_js1, _js2);")
277 (test-ps-js assignment-7
278 (defsetf left
(el) (offset)
279 `(setf (slot-value (slot-value ,el
'style
) 'left
) ,offset
))
282 (test-ps-js assignment-8
283 (setf (left some-div
) (+ 123 "px"))
285 var _js1 = 123 + 'px';
286 _js2.style.left = _js1;")
288 (test-ps-js assignment-9
289 (progn (defmacro left
(el)
290 `(slot-value ,el
'offset-left
))
292 "someDiv.offsetLeft;")
294 (test-ps-js single-argument-statements-1
298 (test-ps-js single-argument-statements-2
302 (test-ps-js single-argument-expression-1
303 (delete (new (*foobar
2 3 4)))
304 "delete new Foobar(2, 3, 4)")
306 (test-ps-js single-argument-expression-2
307 (if (= (typeof blorg
) *string
)
308 (alert (+ "blorg is a string: " blorg
))
309 (alert "blorg is not a string"))
310 "if (typeof blorg == String) {
311 alert('blorg is a string: ' + blorg);
313 alert('blorg is not a string');
316 (test-ps-js conditional-statements-1
317 (if (blorg.is-correct
)
318 (progn (carry-on) (return i
))
319 (alert "blorg is not correct!"))
320 "if (blorg.isCorrect()) {
324 alert('blorg is not correct!');
327 (test-ps-js conditional-statements-2
328 (+ i
(if (blorg.add-one
) 1 2))
329 "i + (blorg.addOne() ? 1 : 2)")
331 (test-ps-js conditional-statements-3
332 (when (blorg.is-correct
)
335 "if (blorg.isCorrect()) {
340 (test-ps-js conditional-statements-4
341 (unless (blorg.is-correct
)
342 (alert "blorg is not correct!"))
343 "if (!blorg.isCorrect()) {
344 alert('blorg is not correct!');
347 (test-ps-js variable-declaration-1
348 (defvar *a
* (array 1 2 3))
349 "var A = [ 1, 2, 3 ]")
351 (test-ps-js variable-declaration-2
353 (let* ((blorg "hallo"))
355 (let* ((blorg "blitzel"))
361 var blorg = 'blitzel';
365 (test-ps-js variable-declaration-3
367 (lexical-let* ((blorg "hallo"))
369 (lexical-let* ((blorg "blitzel"))
373 var newlexicalcontext1 = new Object;
374 newlexicalcontext1['blorg'] = 'hallo';
375 with (newlexicalcontext1) {
381 var newlexicalcontext3 = new Object;
382 newlexicalcontext3['blorg'] = 'blitzel';
383 with (newlexicalcontext3) {
389 (test-ps-js iteration-constructs-1
391 (l (aref blorg i
) (aref blorg i
)))
392 ((or (= i blorg.length
)
393 (eql l
"Fumitastic")))
394 (document.write
(+ "L is " l
)))
395 "for (var i = 0, l = blorg[i];
396 !(i == blorg.length || l == 'Fumitastic');
397 i = i + 1, l = blorg[i]) {
398 document.write('L is ' + l);
401 (test-ps-js iteration-constructs-2
402 (dotimes (i blorg.length
)
403 (document.write
(+ "L is " (aref blorg i
))))
404 "for (var i = 0; i < blorg.length; i = i + 1) {
405 document.write('L is ' + blorg[i]);
408 (test-ps-js iteration-constructs-3
410 (document.write
(+ "L is " l
)))
411 " var tmpArr1 = blorg;
412 for (var tmpI2 = 0; tmpI2 < tmpArr1.length;
414 var l = tmpArr1[tmpI2];
415 document.write('L is ' + l);
418 (test-ps-js iteration-constructs-4
420 (document.write
(+ i
" is " (aref object i
))))
421 "for (var i in object) {
422 document.write(i + ' is ' + object[i]);
425 (test-ps-js iteration-constructs-5
426 (while (film.is-not-finished
)
427 (this.eat
(new *popcorn
)))
428 "while (film.isNotFinished()) {
429 this.eat(new Popcorn);
432 (test-ps-js the-case-statement-1
434 ((1 "one") (alert "one"))
436 (t (alert "default clause")))
445 default: alert('default clause');
448 (test-ps-js the-case-statement-2
449 (switch (aref blorg i
)
450 (1 (alert "If I get here"))
451 (2 (alert "I also get here"))
452 (default (alert "I always get here")))
454 case 1: alert('If I get here');
455 case 2: alert('I also get here');
456 default: alert('I always get here');
459 (test-ps-js the-with-statement-1
460 (with (create :foo
"foo" :i
"i")
461 (alert (+ "i is now intermediary scoped: " i
)))
462 "with ({ foo : 'foo',
464 alert('i is now intermediary scoped: ' + i);
467 (test-ps-js the-try-statement-1
470 (alert (+ "an error happened: " error
)))
472 (alert "Leaving the try form")))
476 alert('an error happened: ' + error);
478 alert('Leaving the try form');
481 (test-ps-js the-html-generator-1
482 (ps-html ((:a
:href
"foobar") "blorg"))
483 "'<a href=\"foobar\">blorg</a>'")
485 (test-ps-js the-html-generator-2
486 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
487 "'<a href=\"' + generateALink() + '\">blorg</a>'")
489 (test-ps-js the-html-generator-3
491 (ps-html ((:a
:href
"#"
492 :onclick
(lisp (ps-inline (transport)))) "link")))
493 "document.write('<a href=\"#\" onclick=\"' + 'javascript:transport()' + '\">link</a>')")
495 (test-ps-js the-html-generator-4
496 (let* ((disabled nil
)
498 (setf element.inner-h-t-m-l
499 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
501 " var disabled = null;
502 var authorized = true;
505 + (disabled || !authorized ? ' disabled=\"' + 'disabled' + '\"' : '')
506 + '>Edit me</textarea>';")