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-4
38 (test-ps-js number-literals-1
42 (test-ps-js number-literals-2
46 (test-ps-js number-literals-3
50 (test-ps-js string-literals-1
54 (test-ps-js string-literals-2
58 (test-ps-js string-literals-3
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
81 "new Array(1, 2, 3);")
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
106 (@ an-object foo bar
)
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 function-calls-and-method-calls-1
162 (test-ps-js function-calls-and-method-calls-2
163 (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4))
164 "foobar(blorg(1, 2), blabla(3, 4), [ 2, 3, 4 ]);")
166 (test-ps-js function-calls-and-method-calls-3
167 ((slot-value this
'blorg
) 1 2)
170 (test-ps-js function-calls-and-method-calls-4
174 (test-ps-js function-calls-and-method-calls-5
175 ((slot-value (aref foobar
1) 'blorg
) NIL T
)
176 "foobar[1].blorg(null, true);")
178 (test-ps-js operator-expressions-1
182 (test-ps-js operator-expressions-2
186 (test-ps-js operator-expressions-3
190 (test-ps-js operator-expressions-4
191 (* 1 (+ 2 3 4) 4 (/ 6 7))
192 "1 * (2 + 3 + 4) * 4 * (6 / 7);")
194 (test-ps-js operator-expressions-5
198 (test-ps-js operator-expressions-6
202 (test-ps-js operator-expressions-7
206 (test-ps-js operator-expressions-8
210 (test-ps-js operator-expressions-9
214 (test-ps-js operator-expressions-10
218 (test-ps-js body-forms-1
219 (progn (blorg i
) (blafoo i
))
223 (test-ps-js body-forms-2
224 (+ i
(progn (blorg i
) (blafoo i
)))
225 "i + (blorg(i), blafoo(i));")
227 (test-ps-js function-definition-1
228 (defun a-function (a b
)
230 "function aFunction(a, b) {
234 (test-ps-js function-definition-2
235 (lambda (a b
) (return (+ a b
)))
240 (test-ps-js assignment-1
244 (test-ps-js assignment-2
245 (setf a
2 b
3 c
4 x
(+ a b c
))
251 (test-ps-js assignment-3
252 (setf a
(+ a
2 3 4 a
))
253 "a += 2 + 3 + 4 + a;")
255 (test-ps-js assignment-4
259 (test-ps-js assignment-5
269 (test-ps-js assignment-6
273 (test-ps-js assignment-8
274 (defun (setf color
) (new-color el
)
275 (setf (slot-value (slot-value el
'style
) 'color
) new-color
))
276 "function __setf_color(newColor, el) {
277 el.style.color = newColor;
280 (test-ps-js assignment-9
281 (setf (color some-div
) (+ 23 "em"))
282 "var _js2_3 = someDiv;
283 var _js1_4 = 23 + 'em';
284 __setf_color(_js1_4, _js2_3);")
286 (test-ps-js assignment-10
287 (defsetf left
(el) (offset)
288 `(setf (slot-value (slot-value ,el
'style
) 'left
) ,offset
))
291 (test-ps-js assignment-11
292 (setf (left some-div
) (+ 123 "px"))
293 "var _js2_3 = someDiv;
294 var _js1_4 = 123 + 'px';
295 _js2_3.style.left = _js1_4;")
297 (test-ps-js assignment-12
298 (macrolet ((left (el)
299 `(slot-value ,el
'offset-left
)))
301 "someDiv.offsetLeft;")
303 (test-ps-js single-argument-statements-1
307 (test-ps-js single-argument-statements-2
311 (test-ps-js single-argument-expression-1
312 (delete (new (*foobar
2 3 4)))
313 "delete new Foobar(2, 3, 4);")
315 (test-ps-js single-argument-expression-2
316 (if (= (typeof blorg
) *string
)
317 (alert (+ "blorg is a string: " blorg
))
318 (alert "blorg is not a string"))
319 "if (typeof blorg == String) {
320 alert('blorg is a string: ' + blorg);
322 alert('blorg is not a string');
325 (test-ps-js conditional-statements-1
326 (if ((@ blorg is-correct
))
327 (progn (carry-on) (return i
))
328 (alert "blorg is not correct!"))
329 "if (blorg.isCorrect()) {
333 alert('blorg is not correct!');
336 (test-ps-js conditional-statements-2
337 (+ i
(if ((@ blorg add-one
)) 1 2))
338 "i + (blorg.addOne() ? 1 : 2);")
340 (test-ps-js conditional-statements-3
341 (when ((@ blorg is-correct
))
344 "if (blorg.isCorrect()) {
349 (test-ps-js conditional-statements-4
350 (unless ((@ blorg is-correct
))
351 (alert "blorg is not correct!"))
352 "if (!blorg.isCorrect()) {
353 alert('blorg is not correct!');
356 (test-ps-js variable-declaration-1
357 (defvar *a
* (array 1 2 3))
358 "var A = [ 1, 2, 3 ];")
360 (test-ps-js variable-declaration-2
381 (test-ps-js iteration-constructs-1
382 (do* ((a) b
(c (array "a" "b" "c" "d" "e"))
384 (e (aref c d
) (aref c d
)))
385 ((or (= d
(@ c length
)) (eql e
"x")))
387 ((@ document write
) (+ "a: " a
" b: " b
"<br/>")))
388 "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]) {
391 document.write('a: ' + a + ' b: ' + b + '<br/>');
394 (test-ps-js iteration-constructs-2
396 (s 0 (+ s i
(1+ i
))))
398 ((@ document write
) (+ "i: " i
" s: " s
"<br/>")))
402 document.write('i: ' + i1 + ' s: ' + s2 + '<br/>');
404 var _js4_6 = s2 + i1 + (i1 + 1);
409 (test-ps-js iteration-constructs-3
411 (s 0 (+ s i
(1- i
))))
413 ((@ document write
) (+ "i: " i
" s: " s
"<br/>")))
414 "for (var i = 0, s = 0; i <= 10; i += 1, s += i + (i - 1)) {
415 document.write('i: ' + i + ' s: ' + s + '<br/>');
418 (test-ps-js iteration-constructs-4
419 (let ((arr (array "a" "b" "c" "d" "e")))
420 (dotimes (i (@ arr length
))
421 ((@ document write
) (+ "i: " i
" arr[i]: " (aref arr i
) "<br/>"))))
422 "var arr1 = ['a', 'b', 'c', 'd', 'e'];
423 for (var i = 0; i < arr1.length; i += 1) {
424 document.write('i: ' + i + ' arr[i]: ' + arr1[i] + '<br/>');
427 (test-ps-js iteration-constructs-5
429 (alert (+ "Summation to 10 is "
431 (incf res
(1+ i
))))))
433 alert('Summation to 10 is ' + (function () {
434 for (var i = 0; i < 10; i += 1) {
440 (test-ps-js iteration-constructs-6
441 (let ((l (list 1 2 4 8 16 32)))
443 ((@ document write
) (+ "c: " c
"<br/>"))))
444 "var l1 = [1, 2, 4, 8, 16, 32];
445 for (var c = null, _js_arrvar3 = l1, _js_idx2 = 0; _js_idx2 < _js_arrvar3.length; _js_idx2 += 1) {
446 c = _js_arrvar3[_js_idx2];
447 document.write('c: ' + c + '<br/>');
450 (test-ps-js iteration-constructs-7
451 (let ((l '(1 2 4 8 16 32))
453 (alert (+ "Sum of " l
" is: "
456 "var l1 = [1, 2, 4, 8, 16, 32];
458 alert('Sum of ' + l1 + ' is: ' + (function () {
459 for (var c = null, _js_arrvar4 = l1, _js_idx3 = 0; _js_idx3 < _js_arrvar4.length; _js_idx3 += 1) {
460 c = _js_arrvar4[_js_idx3];
466 (test-ps-js iteration-constructs-8
467 (let ((obj (create :a
1 :b
2 :c
3)))
469 ((@ document write
) (+ i
": " (aref obj i
) "<br/>"))))
470 "var obj1 = { a : 1, b : 2, c : 3 };
471 for (var i in obj1) {
472 document.write(i + ': ' + obj1[i] + '<br/>');
475 (test-ps-js iteration-constructs-9
476 (while ((@ film is-not-finished
))
477 ((@ this eat
) (new *popcorn
)))
478 "while (film.isNotFinished()) {
479 this.eat(new Popcorn);
482 (test-ps-js the-case-statement-1
484 ((1 "one") (alert "one"))
486 (t (alert "default clause")))
496 alert('default clause');
499 (test-ps-js the-case-statement-2
500 (switch (aref blorg i
)
501 (1 (alert "If I get here"))
502 (2 (alert "I also get here"))
503 (default (alert "I always get here")))
505 case 1: alert('If I get here');
506 case 2: alert('I also get here');
507 default: alert('I always get here');
510 (test-ps-js the-with-statement-1
511 (with (create :foo
"foo" :i
"i")
512 (alert (+ "i is now intermediary scoped: " i
)))
513 "with ({ foo : 'foo', i : 'i' }) {
514 alert('i is now intermediary scoped: ' + i);
517 (test-ps-js the-try-statement-1
520 (alert (+ "an error happened: " error
)))
522 (alert "Leaving the try form")))
526 alert('an error happened: ' + error);
528 alert('Leaving the try form');
531 (test-ps-js the-html-generator-1
532 (ps-html ((:a
:href
"foobar") "blorg"))
533 "'<A HREF=\"foobar\">blorg</A>';")
535 (test-ps-js the-html-generator-2
536 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
537 "'<A HREF=\"' + generateALink() + '\">blorg</A>';")
539 (test-ps-js the-html-generator-3
541 (ps-html ((:a
:href
"#"
542 :onclick
(ps-inline (transport))) "link")))
543 "document.write('<A HREF=\"#\" ONCLICK=\"' + ('javascript:' + 'transport' + '(' + ')') + '\">link</A>');")
545 (test-ps-js the-html-generator-4
548 (setf (@ element inner-h-t-m-l
)
549 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
551 "var disabled1 = null;
552 var authorized2 = true;
555 + (disabled1 || !authorized2 ? ' DISABLED=\"' + 'disabled' + '\"' : '')
556 + '>Edit me</TEXTAREA>';")