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 string-literals-3
66 (test-ps-js array-literals-1
70 (test-ps-js array-literals-2
74 (test-ps-js array-literals-3
76 (array "foobar" "bratzel bub"))
77 "[ [ 2, 3 ], [ 'foobar', 'bratzel bub' ] ]")
79 (test-ps-js array-literals-4
83 (test-ps-js array-literals-5
87 (test-ps-js array-literals-6
90 (make-array "foobar" "bratzel bub"))
91 "new Array(new Array(2, 3), new Array('foobar', 'bratzel bub'))")
93 (test-ps-js object-literals-1
94 (create :foo
"bar" :blorg
1)
95 "{ foo : 'bar', blorg : 1 }")
97 (test-ps-js object-literals-2
100 :another-object
(create :schtrunz
1))
103 anotherObject : { schtrunz : 1 } }")
105 (test-ps-js object-literals-3
106 (slot-value an-object
'foo
)
109 (test-ps-js object-literals-4
113 (test-ps-js object-literals-5
114 (with-slots (a b c
) this
116 "this.a + this.b + this.c;")
118 (test-ps-js regular-expression-literals-1
122 (test-ps-js regular-expression-literals-2
126 (test-ps-js literal-symbols-1
130 (test-ps-js literal-symbols-2
134 (test-ps-js literal-symbols-3
138 (test-ps-js literal-symbols-4
142 (test-ps-js literal-symbols-5
146 (test-ps-js literal-symbols-6
150 (test-ps-js variables-1
154 (test-ps-js variables-2
158 (test-ps-js variables-3
162 (test-ps-js variables-4
166 (test-ps-js function-calls-and-method-calls-1
170 (test-ps-js function-calls-and-method-calls-2
171 (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4))
172 "foobar(blorg(1, 2), blabla(3, 4), [ 2, 3, 4 ])")
174 (test-ps-js function-calls-and-method-calls-3
175 ((slot-value this
'blorg
) 1 2)
178 (test-ps-js function-calls-and-method-calls-4
182 (test-ps-js function-calls-and-method-calls-5
183 ((slot-value (aref foobar
1) 'blorg
) NIL T
)
184 "foobar[1].blorg(null, true)")
186 (test-ps-js function-calls-and-method-calls-6
190 (test-ps-js operator-expressions-1
194 (test-ps-js operator-expressions-2
198 (test-ps-js operator-expressions-3
202 (test-ps-js operator-expressions-4
203 (* 1 (+ 2 3 4) 4 (/ 6 7))
204 "1 * (2 + 3 + 4) * 4 * (6 / 7)")
206 (test-ps-js operator-expressions-5
210 (test-ps-js operator-expressions-6
214 (test-ps-js operator-expressions-7
218 (test-ps-js operator-expressions-8
222 (test-ps-js operator-expressions-9
226 (test-ps-js operator-expressions-10
230 (test-ps-js body-forms-1
231 (progn (blorg i
) (blafoo i
))
235 (test-ps-js body-forms-2
236 (+ i
(progn (blorg i
) (blafoo i
)))
237 "i + (blorg(i), blafoo(i))")
239 (test-ps-js function-definition-1
240 (defun a-function (a b
)
242 "function aFunction(a, b) {
246 (test-ps-js function-definition-2
247 (lambda (a b
) (return (+ a b
)))
252 (test-ps-js assignment-1
256 (test-ps-js assignment-2
257 (setf a
2 b
3 c
4 x
(+ a b c
))
263 (test-ps-js assignment-3
264 (setf a
(+ a
2 3 4 a
))
265 "a += 2 + 3 + 4 + a;")
267 (test-ps-js assignment-4
271 (test-ps-js assignment-5
281 (test-ps-js assignment-6
285 (test-ps-js assignment-8
286 (defun (setf color
) (new-color el
)
287 (setf (slot-value (slot-value el
'style
) 'color
) new-color
))
288 "function __setf_color(newColor, el) {
289 el.style.color = newColor;
292 (test-ps-js assignment-9
293 (setf (color some-div
) (+ 23 "em"))
295 var _js1 = 23 + 'em';
296 __setf_color(_js1, _js2);")
298 (test-ps-js assignment-10
299 (defsetf left
(el) (offset)
300 `(setf (slot-value (slot-value ,el
'style
) 'left
) ,offset
))
303 (test-ps-js assignment-11
304 (setf (left some-div
) (+ 123 "px"))
306 var _js1 = 123 + 'px';
307 _js2.style.left = _js1;")
309 (test-ps-js assignment-12
310 (progn (defmacro left
(el)
311 `(slot-value ,el
'offset-left
))
313 "someDiv.offsetLeft;")
315 (test-ps-js single-argument-statements-1
319 (test-ps-js single-argument-statements-2
323 (test-ps-js single-argument-expression-1
324 (delete (new (*foobar
2 3 4)))
325 "delete new Foobar(2, 3, 4)")
327 (test-ps-js single-argument-expression-2
328 (if (= (typeof blorg
) *string
)
329 (alert (+ "blorg is a string: " blorg
))
330 (alert "blorg is not a string"))
331 "if (typeof blorg == String) {
332 alert('blorg is a string: ' + blorg);
334 alert('blorg is not a string');
337 (test-ps-js conditional-statements-1
338 (if (blorg.is-correct
)
339 (progn (carry-on) (return i
))
340 (alert "blorg is not correct!"))
341 "if (blorg.isCorrect()) {
345 alert('blorg is not correct!');
348 (test-ps-js conditional-statements-2
349 (+ i
(if (blorg.add-one
) 1 2))
350 "i + (blorg.addOne() ? 1 : 2)")
352 (test-ps-js conditional-statements-3
353 (when (blorg.is-correct
)
356 "if (blorg.isCorrect()) {
361 (test-ps-js conditional-statements-4
362 (unless (blorg.is-correct
)
363 (alert "blorg is not correct!"))
364 "if (!blorg.isCorrect()) {
365 alert('blorg is not correct!');
368 (test-ps-js variable-declaration-1
369 (defvar *a
* (array 1 2 3))
370 "var A = [ 1, 2, 3 ]")
372 (test-ps-js variable-declaration-2
373 (simple-let* ((a 0) (b 1))
379 (test-ps-js variable-declaration-3
380 (simple-let* ((a "World") (b "Hello"))
381 (simple-let ((a b
) (b a
))
393 (test-ps-js variable-declaration-4
394 (simple-let* ((a 0) (b 1))
395 (lexical-let* ((a 9) (b 8))
407 (test-ps-js variable-declaration-5
408 (simple-let* ((a "World") (b "Hello"))
409 (lexical-let ((a b
) (b a
))
419 (test-ps-js iteration-constructs-1
420 (do* ((a) b
(c (array "a" "b" "c" "d" "e"))
422 (e (aref c d
) (aref c d
)))
423 ((or (= d c.length
) (eql e
"x")))
425 (document.write
(+ "a: " a
" b: " b
"<br/>")))
426 "for (var a = null, b = null, c = ['a', 'b', 'c', 'd', 'e'], d = 0, e = c[d]; !(d == c.length || e == 'x'); d += 1, e = c[d]) {
429 document.write('a: ' + a + ' b: ' + b + '<br/>');
432 (test-ps-js iteration-constructs-2
434 (s 0 (+ s i
(1+ i
))))
436 (document.write
(+ "i: " i
" s: " s
"<br/>")))
444 document.write('i: ' + i + ' s: ' + s + '<br/>');
446 var _js4 = s + i + (i + 1);
451 (test-ps-js iteration-constructs-3
453 (s 0 (+ s i
(1- i
))))
455 (document.write
(+ "i: " i
" s: " s
"<br/>")))
456 "for (var i = 0, s = 0; i <= 10; i += 1, s += i + (i - 1)) {
457 document.write('i: ' + i + ' s: ' + s + '<br/>');
460 (test-ps-js iteration-constructs-4
461 (let* ((arr (array "a" "b" "c" "d" "e")))
462 (dotimes (i arr.length
)
463 (document.write
(+ "i: " i
" arr[i]: " (aref arr i
) "<br/>"))))
464 "var arr = ['a', 'b', 'c', 'd', 'e'];
465 for (var i = 0; i < arr.length; i += 1) {
466 document.write('i: ' + i + ' arr[i]: ' + arr[i] + '<br/>');
469 (test-ps-js iteration-constructs-5
471 (alert (+ "Summation to 10 is "
473 (incf res
(1+ i
))))))
475 alert('Summation to 10 is ' + (function () {
476 for (var i = 0; i < 10; i += 1) {
482 (test-ps-js iteration-constructs-6
483 (let* ((l (list 1 2 4 8 16 32)))
485 (document.write
(+ "c: " c
"<br/>"))))
486 "var l = [1, 2, 4, 8, 16, 32];
487 for (var c = null, _js_arrvar2 = l, _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
488 c = _js_arrvar2[_js_idx1];
489 document.write('c: ' + c + '<br/>');
492 (test-ps-js iteration-constructs-7
493 (let* ((l (list 1 2 4 8 16 32))
495 (alert (+ "Sum of " l
" is: "
498 "var l = [1, 2, 4, 8, 16, 32];
500 alert('Sum of ' + l + ' is: ' + (function () {
501 for (var c = null, _js_arrvar2 = l, _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
502 c = _js_arrvar2[_js_idx1];
508 (test-ps-js iteration-constructs-8
509 (let* ((obj (create :a
1 :b
2 :c
3)))
511 (document.write
(+ i
": " (aref obj i
) "<br/>"))))
512 "var obj = { a : 1, b : 2, c : 3 };
514 document.write(i + ': ' + obj[i] + '<br/>');
517 (test-ps-js iteration-constructs-9
518 (let* ((obj (create :a
1 :b
2 :c
3)))
520 (document.write
(+ k
": " v
"<br/>"))))
521 "var obj = { a : 1, b : 2, c : 3 };
525 document.write(k + ': ' + v + '<br/>');
528 (test-ps-js iteration-constructs-10
529 (while (film.is-not-finished
)
530 (this.eat
(new *popcorn
)))
531 "while (film.isNotFinished()) {
532 this.eat(new Popcorn);
535 (test-ps-js the-case-statement-1
537 ((1 "one") (alert "one"))
539 (t (alert "default clause")))
549 alert('default clause');
552 (test-ps-js the-case-statement-2
553 (switch (aref blorg i
)
554 (1 (alert "If I get here"))
555 (2 (alert "I also get here"))
556 (default (alert "I always get here")))
558 case 1: alert('If I get here');
559 case 2: alert('I also get here');
560 default: alert('I always get here');
563 (test-ps-js the-with-statement-1
564 (with (create :foo
"foo" :i
"i")
565 (alert (+ "i is now intermediary scoped: " i
)))
566 "with ({ foo : 'foo', i : 'i' }) {
567 alert('i is now intermediary scoped: ' + i);
570 (test-ps-js the-try-statement-1
573 (alert (+ "an error happened: " error
)))
575 (alert "Leaving the try form")))
579 alert('an error happened: ' + error);
581 alert('Leaving the try form');
584 (test-ps-js the-html-generator-1
585 (ps-html ((:a
:href
"foobar") "blorg"))
586 "'<A HREF=\"foobar\">blorg</A>'")
588 (test-ps-js the-html-generator-2
589 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
590 "'<A HREF=\"' + generateALink() + '\">blorg</A>'")
592 (test-ps-js the-html-generator-3
594 (ps-html ((:a
:href
"#"
595 :onclick
(ps-inline (transport))) "link")))
596 "document.write('<A HREF=\"#\" ONCLICK=\"' + ('javascript:' + 'transport' + '(' + ')') + '\">link</A>')")
598 (test-ps-js the-html-generator-4
599 (let* ((disabled nil
)
601 (setf element.inner-h-t-m-l
602 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
604 "var disabled = null;
605 var authorized = true;
608 + (disabled || !authorized ? ' DISABLED=\"' + 'disabled' + '\"' : '')
609 + '>Edit me</TEXTAREA>';")