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
187 (* 1 (+ 2 3 4) 4 (/ 6 7))
188 "1 * (2 + 3 + 4) * 4 * (6 / 7);")
190 (test-ps-js operator-expressions-4
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 body-forms-1
211 (progn (blorg i
) (blafoo i
))
215 (test-ps-js body-forms-2
216 (+ i
(progn (blorg i
) (blafoo i
)))
217 "i + (blorg(i), blafoo(i));")
219 (test-ps-js function-definition-1
220 (defun a-function (a b
)
222 "function aFunction(a, b) {
226 (test-ps-js function-definition-2
227 (lambda (a b
) (return (+ a b
)))
232 (test-ps-js assignment-1
236 (test-ps-js assignment-2
237 (setf a
2 b
3 c
4 x
(+ a b c
))
243 (test-ps-js assignment-3
244 (setf a
(+ a
2 3 4 a
))
245 "a += 2 + 3 + 4 + a;")
247 (test-ps-js assignment-4
251 (test-ps-js assignment-5
261 (test-ps-js assignment-6
265 (test-ps-js assignment-8
266 (defun (setf color
) (new-color el
)
267 (setf (slot-value (slot-value el
'style
) 'color
) new-color
))
268 "function __setf_color(newColor, el) {
269 el.style.color = newColor;
272 (test-ps-js assignment-9
273 (setf (color some-div
) (+ 23 "em"))
275 var _js1 = 23 + 'em';
276 __setf_color(_js1, _js2);")
278 (test-ps-js assignment-10
279 (defsetf left
(el) (offset)
280 `(setf (slot-value (slot-value ,el
'style
) 'left
) ,offset
))
283 (test-ps-js assignment-11
284 (setf (left some-div
) (+ 123 "px"))
286 var _js1 = 123 + 'px';
287 _js2.style.left = _js1;")
289 (test-ps-js assignment-12
290 (macrolet ((left (el)
291 `(slot-value ,el
'offset-left
)))
293 "someDiv.offsetLeft;")
295 (test-ps-js single-argument-statements-1
299 (test-ps-js single-argument-statements-2
303 (test-ps-js single-argument-expression-1
304 (delete (new (*foobar
2 3 4)))
305 "delete new Foobar(2, 3, 4);")
307 (test-ps-js single-argument-expression-2
308 (if (= (typeof blorg
) *string
)
309 (alert (+ "blorg is a string: " blorg
))
310 (alert "blorg is not a string"))
311 "if (typeof blorg == String) {
312 alert('blorg is a string: ' + blorg);
314 alert('blorg is not a string');
317 (test-ps-js conditional-statements-1
318 (if ((@ blorg is-correct
))
319 (progn (carry-on) (return i
))
320 (alert "blorg is not correct!"))
321 "if (blorg.isCorrect()) {
325 alert('blorg is not correct!');
328 (test-ps-js conditional-statements-2
329 (+ i
(if ((@ blorg add-one
)) 1 2))
330 "i + (blorg.addOne() ? 1 : 2);")
332 (test-ps-js conditional-statements-3
333 (when ((@ blorg is-correct
))
336 "if (blorg.isCorrect()) {
341 (test-ps-js conditional-statements-4
342 (unless ((@ blorg is-correct
))
343 (alert "blorg is not correct!"))
344 "if (!blorg.isCorrect()) {
345 alert('blorg is not correct!');
348 (test-ps-js variable-declaration-1
349 (defvar *a
* (array 1 2 3))
350 "var A = [ 1, 2, 3 ];")
352 (test-ps-js variable-declaration-2
373 (test-ps-js iteration-constructs-1
374 (do* ((a) b
(c (array "a" "b" "c" "d" "e"))
376 (e (aref c d
) (aref c d
)))
377 ((or (= d
(@ c length
)) (== e
"x")))
379 ((@ document write
) (+ "a: " a
" b: " b
"<br/>")))
380 "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]) {
383 document.write('a: ' + a + ' b: ' + b + '<br/>');
386 (test-ps-js iteration-constructs-2
388 (s 0 (+ s i
(1+ i
))))
390 ((@ document write
) (+ "i: " i
" s: " s
"<br/>")))
394 document.write('i: ' + i + ' s: ' + s + '<br/>');
396 var _js2 = s + i + (i + 1);
401 (test-ps-js iteration-constructs-3
403 (s 0 (+ s i
(1- i
))))
405 ((@ document write
) (+ "i: " i
" s: " s
"<br/>")))
406 "for (var i = 0, s = 0; i <= 10; i += 1, s += i + (i - 1)) {
407 document.write('i: ' + i + ' s: ' + s + '<br/>');
410 (test-ps-js iteration-constructs-4
411 (let ((arr (array "a" "b" "c" "d" "e")))
412 (dotimes (i (@ arr length
))
413 ((@ document write
) (+ "i: " i
" arr[i]: " (aref arr i
) "<br/>"))))
414 "var arr = ['a', 'b', 'c', 'd', 'e'];
415 for (var i = 0; i < arr.length; i += 1) {
416 document.write('i: ' + i + ' arr[i]: ' + arr[i] + '<br/>');
419 (test-ps-js iteration-constructs-5
421 (alert (+ "Summation to 10 is "
423 (incf res
(1+ i
))))))
425 alert('Summation to 10 is ' + (function () {
426 for (var i = 0; i < 10; i += 1) {
432 (test-ps-js iteration-constructs-6
433 (let ((l (list 1 2 4 8 16 32)))
435 ((@ document write
) (+ "c: " c
"<br/>"))))
436 "var l = [1, 2, 4, 8, 16, 32];
437 for (var c = null, _js_arrvar2 = l, _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
438 c = _js_arrvar2[_js_idx1];
439 document.write('c: ' + c + '<br/>');
442 (test-ps-js iteration-constructs-7
443 (let ((l '(1 2 4 8 16 32))
445 (alert (+ "Sum of " l
" is: "
448 "var l = [1, 2, 4, 8, 16, 32];
450 alert('Sum of ' + l + ' is: ' + (function () {
451 for (var c = null, _js_arrvar2 = l, _js_idx1 = 0; _js_idx1 < _js_arrvar2.length; _js_idx1 += 1) {
452 c = _js_arrvar2[_js_idx1];
458 (test-ps-js iteration-constructs-8
459 (let ((obj (create a
1 b
2 c
3)))
461 ((@ document write
) (+ i
": " (aref obj i
) "<br/>"))))
462 "var obj = { a : 1, b : 2, c : 3 };
464 document.write(i + ': ' + obj[i] + '<br/>');
467 (test-ps-js iteration-constructs-9
468 (while ((@ film is-not-finished
))
469 ((@ this eat
) (new *popcorn
)))
470 "while (film.isNotFinished()) {
471 this.eat(new Popcorn);
474 (test-ps-js the-case-statement-1
476 ((1 "one") (alert "one"))
478 (t (alert "default clause")))
488 alert('default clause');
491 (test-ps-js the-case-statement-2
492 (switch (aref blorg i
)
493 (1 (alert "If I get here"))
494 (2 (alert "I also get here"))
495 (default (alert "I always get here")))
497 case 1: alert('If I get here');
498 case 2: alert('I also get here');
499 default: alert('I always get here');
502 (test-ps-js the-with-statement-1
503 (with (create foo
"foo" i
"i")
504 (alert (+ "i is now intermediary scoped: " i
)))
505 "with ({ foo : 'foo', i : 'i' }) {
506 alert('i is now intermediary scoped: ' + i);
509 (test-ps-js the-try-statement-1
512 (alert (+ "an error happened: " error
)))
514 (alert "Leaving the try form")))
518 alert('an error happened: ' + error);
520 alert('Leaving the try form');
523 (test-ps-js the-html-generator-1
524 (ps-html ((:a
:href
"foobar") "blorg"))
525 "'<A HREF=\"foobar\">blorg</A>';")
527 (test-ps-js the-html-generator-2
528 (ps-html ((:a
:href
(generate-a-link)) "blorg"))
529 "'<A HREF=\"' + generateALink() + '\">blorg</A>';")
531 (test-ps-js the-html-generator-3
533 (ps-html ((:a
:href
"#"
534 :onclick
(ps-inline (transport))) "link")))
535 "document.write('<A HREF=\"#\" ONCLICK=\"' + ('javascript:' + 'transport' + '(' + ')') + '\">link</A>');")
537 (test-ps-js the-html-generator-4
540 (setf (@ element inner-h-t-m-l
)
541 (ps-html ((:textarea
(or disabled
(not authorized
)) :disabled
"disabled")
543 "var disabled = null;
544 var authorized = true;
547 + (disabled || !authorized ? ' DISABLED=\"' + 'disabled' + '\"' : '')
548 + '>Edit me</TEXTAREA>';")