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)
91 "{ foo : 'bar', blorg : 1 }")
93 (test-ps-js object-literals-2
96 :another-object
(create :schtrunz
1))
99 anotherObject : { schtrunz : 1 } }")
101 (test-ps-js object-literals-3
102 (slot-value an-object
'foo
)
105 (test-ps-js object-literals-4
109 (test-ps-js object-literals-5
110 (with-slots (a b c
) this
112 "this.a + this.b + this.c;")
114 (test-ps-js regular-expression-literals-1
118 (test-ps-js regular-expression-literals-2
122 (test-ps-js literal-symbols-1
126 (test-ps-js literal-symbols-2
130 (test-ps-js literal-symbols-3
134 (test-ps-js literal-symbols-4
138 (test-ps-js literal-symbols-5
142 (test-ps-js literal-symbols-6
146 (test-ps-js variables-1
150 (test-ps-js variables-2
154 (test-ps-js variables-3
158 (test-ps-js variables-4
162 (test-ps-js function-calls-and-method-calls-1
166 (test-ps-js function-calls-and-method-calls-2
167 (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4))
168 "foobar(blorg(1, 2), blabla(3, 4), [ 2, 3, 4 ])")
170 (test-ps-js function-calls-and-method-calls-3
171 ((slot-value this
'blorg
) 1 2)
174 (test-ps-js function-calls-and-method-calls-4
178 (test-ps-js function-calls-and-method-calls-5
179 ((slot-value (aref foobar
1) 'blorg
) NIL T
)
180 "foobar[1].blorg(null, true)")
182 (test-ps-js function-calls-and-method-calls-6
186 (test-ps-js operator-expressions-1
190 (test-ps-js operator-expressions-2
194 (test-ps-js operator-expressions-3
198 (test-ps-js operator-expressions-4
199 (* 1 (+ 2 3 4) 4 (/ 6 7))
200 "1 * (2 + 3 + 4) * 4 * (6 / 7)")
202 (test-ps-js operator-expressions-5
206 (test-ps-js operator-expressions-6
210 (test-ps-js operator-expressions-7
214 (test-ps-js operator-expressions-8
218 (test-ps-js operator-expressions-9
222 (test-ps-js operator-expressions-10
226 (test-ps-js body-forms-1
227 (progn (blorg i
) (blafoo i
))
231 (test-ps-js body-forms-2
232 (+ i
(progn (blorg i
) (blafoo i
)))
233 "i + (blorg(i), blafoo(i))")
235 (test-ps-js function-definition-1
236 (defun a-function (a b
)
238 "function aFunction(a, b) {
242 (test-ps-js function-definition-2
243 (lambda (a b
) (return (+ a b
)))
248 (test-ps-js assignment-1
252 (test-ps-js assignment-2
253 (setf a
2 b
3 c
4 x
(+ a b c
))
259 (test-ps-js assignment-3
260 (setf a
(+ a
2 3 4 a
))
261 "a += 2 + 3 + 4 + a;")
263 (test-ps-js assignment-4
267 (test-ps-js assignment-5
277 (test-ps-js assignment-6
281 (test-ps-js assignment-8
282 (defun (setf color
) (new-color el
)
283 (setf (slot-value (slot-value el
'style
) 'color
) new-color
))
284 "function __setf_color(newColor, el) {
285 el.style.color = newColor;
288 (test-ps-js assignment-9
289 (setf (color some-div
) (+ 23 "em"))
291 var _js1 = 23 + 'em';
292 __setf_color(_js1, _js2);")
294 (test-ps-js assignment-10
295 (defsetf left
(el) (offset)
296 `(setf (slot-value (slot-value ,el
'style
) 'left
) ,offset
))
299 (test-ps-js assignment-11
300 (setf (left some-div
) (+ 123 "px"))
302 var _js1 = 123 + 'px';
303 _js2.style.left = _js1;")
305 (test-ps-js assignment-12
306 (progn (defmacro left
(el)
307 `(slot-value ,el
'offset-left
))
309 "someDiv.offsetLeft;")
311 (test-ps-js single-argument-statements-1
315 (test-ps-js single-argument-statements-2
319 (test-ps-js single-argument-expression-1
320 (delete (new (*foobar
2 3 4)))
321 "delete new Foobar(2, 3, 4)")
323 (test-ps-js single-argument-expression-2
324 (if (= (typeof blorg
) *string
)
325 (alert (+ "blorg is a string: " blorg
))
326 (alert "blorg is not a string"))
327 "if (typeof blorg == String) {
328 alert('blorg is a string: ' + blorg);
330 alert('blorg is not a string');
333 (test-ps-js conditional-statements-1
334 (if (blorg.is-correct
)
335 (progn (carry-on) (return i
))
336 (alert "blorg is not correct!"))
337 "if (blorg.isCorrect()) {
341 alert('blorg is not correct!');
344 (test-ps-js conditional-statements-2
345 (+ i
(if (blorg.add-one
) 1 2))
346 "i + (blorg.addOne() ? 1 : 2)")
348 (test-ps-js conditional-statements-3
349 (when (blorg.is-correct
)
352 "if (blorg.isCorrect()) {
357 (test-ps-js conditional-statements-4
358 (unless (blorg.is-correct
)
359 (alert "blorg is not correct!"))
360 "if (!blorg.isCorrect()) {
361 alert('blorg is not correct!');
364 (test-ps-js variable-declaration-1
365 (defvar *a
* (array 1 2 3))
366 "var A = [ 1, 2, 3 ]")
368 (test-ps-js variable-declaration-2
369 (simple-let* ((a 0) (b 1))
375 (test-ps-js variable-declaration-3
376 (simple-let* ((a "World") (b "Hello"))
377 (simple-let ((a b
) (b a
))
389 (test-ps-js variable-declaration-4
390 (simple-let* ((a 0) (b 1))
391 (lexical-let* ((a 9) (b 8))
403 (test-ps-js variable-declaration-5
404 (simple-let* ((a "World") (b "Hello"))
405 (lexical-let ((a b
) (b a
))
415 (test-ps-js iteration-constructs-1
416 (do* ((a) b
(c (array "a" "b" "c" "d" "e"))
418 (e (aref c d
) (aref c d
)))
419 ((or (= d c.length
) (eql e
"x")))
421 (document.write
(+ "a: " a
" b: " b
"<br/>")))
422 "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]) {
425 document.write('a: ' + a + ' b: ' + b + '<br/>');
428 (test-ps-js iteration-constructs-2
430 (s 0 (+ s i
(1+ i
))))
432 (document.write
(+ "i: " i
" s: " s
"<br/>")))
440 document.write('i: ' + i + ' s: ' + s + '<br/>');
442 var _js4 = s + i + (i + 1);
447 (test-ps-js iteration-constructs-3
449 (s 0 (+ s i
(1- i
))))
451 (document.write
(+ "i: " i
" s: " s
"<br/>")))
452 "for (var i = 0, s = 0; i <= 10; i += 1, s += i + (i - 1)) {
453 document.write('i: ' + i + ' s: ' + s + '<br/>');
456 (test-ps-js iteration-constructs-4
457 (let* ((arr (array "a" "b" "c" "d" "e")))
458 (dotimes (i arr.length
)
459 (document.write
(+ "i: " i
" arr[i]: " (aref arr i
) "<br/>"))))
460 "var arr = ['a', 'b', 'c', 'd', 'e'];
461 for (var i = 0; i < arr.length; i += 1) {
462 document.write('i: ' + i + ' arr[i]: ' + arr[i] + '<br/>');
465 (test-ps-js iteration-constructs-5
467 (alert (+ "Summation to 10 is "
469 (incf res
(1+ i
))))))
471 alert('Summation to 10 is ' + (function () {
472 for (var i = 0; i < 10; i += 1) {
478 (test-ps-js iteration-constructs-6
479 (let* ((l (list 1 2 4 8 16 32)))
481 (document.write
(+ "c: " c
"<br/>"))))
482 "var l = [1, 2, 4, 8, 16, 32];
483 for (var c = null, _js_arrvar2 = l, _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
484 c = _js_arrvar2[_js_idx1];
485 document.write('c: ' + c + '<br/>');
488 (test-ps-js iteration-constructs-7
489 (let* ((l (list 1 2 4 8 16 32))
491 (alert (+ "Sum of " l
" is: "
494 "var l = [1, 2, 4, 8, 16, 32];
496 alert('Sum of ' + l + ' is: ' + (function () {
497 for (var c = null, _js_arrvar2 = l, _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
498 c = _js_arrvar2[_js_idx1];
504 (test-ps-js iteration-constructs-8
505 (let* ((obj (create :a
1 :b
2 :c
3)))
507 (document.write
(+ i
": " (aref obj i
) "<br/>"))))
508 "var obj = { a : 1, b : 2, c : 3 };
510 document.write(i + ': ' + obj[i] + '<br/>');
513 (test-ps-js iteration-constructs-9
514 (let* ((obj (create :a
1 :b
2 :c
3)))
516 (document.write
(+ k
": " v
"<br/>"))))
517 "var obj = { a : 1, b : 2, c : 3 };
521 document.write(k + ': ' + v + '<br/>');
524 (test-ps-js iteration-constructs-10
525 (while (film.is-not-finished
)
526 (this.eat
(new *popcorn
)))
527 "while (film.isNotFinished()) {
528 this.eat(new Popcorn);
531 (test-ps-js the-case-statement-1
533 ((1 "one") (alert "one"))
535 (t (alert "default clause")))
545 alert('default clause');
548 (test-ps-js the-case-statement-2
549 (switch (aref blorg i
)
550 (1 (alert "If I get here"))
551 (2 (alert "I also get here"))
552 (default (alert "I always get here")))
554 case 1: alert('If I get here');
555 case 2: alert('I also get here');
556 default: alert('I always get here');
559 (test-ps-js the-with-statement-1
560 (with (create :foo
"foo" :i
"i")
561 (alert (+ "i is now intermediary scoped: " i
)))
562 "with ({ foo : 'foo', i : 'i' }) {
563 alert('i is now intermediary scoped: ' + i);
566 (test-ps-js the-try-statement-1
569 (alert (+ "an error happened: " error
)))
571 (alert "Leaving the try form")))
575 alert('an error happened: ' + error);
577 alert('Leaving the try form');
580 (test-ps-js the-html-generator-1
581 (ps-html ((:a
:href
"foobar") "blorg"))
582 "'<A HREF=\"foobar\">blorg</A>'")
584 (test-ps-js the-html-generator-2
585 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
586 "'<A HREF=\"' + generateALink() + '\">blorg</A>'")
588 (test-ps-js the-html-generator-3
590 (ps-html ((:a
:href
"#"
591 :onclick
(ps-inline (transport))) "link")))
592 "document.write('<A HREF=\"#\" ONCLICK=\"' + ('javascript:' + 'transport()') + '\">link</A>')")
594 (test-ps-js the-html-generator-4
595 (let* ((disabled nil
)
597 (setf element.inner-h-t-m-l
598 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
600 "var disabled = null;
601 var authorized = true;
604 + (disabled || !authorized ? ' DISABLED=\"' + 'disabled' + '\"' : '')
605 + '>Edit me</TEXTAREA>';")