c883c910121bb31dfb641d2d8f3a88a84026d243
[clinton/parenscript.git] / t / ps-tests.lisp
1 (in-package :ps-test)
2
3 ;;; Hand-written unit tests
4
5 (eval-when (:compile-toplevel :load-toplevel :execute)
6 (def-suite ps-tests))
7 (in-suite ps-tests)
8
9 (test-ps-js plus-is-not-commutative
10 (setf x (+ "before" x "after"))
11 "x = 'before' + x + 'after';")
12
13 (test-ps-js plus-works-if-first
14 (setf x (+ x "middle" "after"))
15 "x += 'middle' + 'after';")
16
17 (test-ps-js setf-side-effects
18 (progn
19 (let* ((x 10))
20 (defun side-effect()
21 (setf x 4)
22 (return 3))
23 (setf x (+ 2 (side-effect) x 5))))
24 "var x = 10;
25 function sideEffect() {
26 x = 4;
27 return 3;
28 };
29 x = 2 + sideEffect() + x + 5;")
30 ;; Parenscript used to optimize incorrectly:
31 ;; var x = 10;
32 ;; function sideEffect() {
33 ;; x = 4;
34 ;; return 3;
35 ;; };
36 ;; x += 2 + sideEffect() + 5;
37 ;;
38 ;; Which is 20, not 14
39
40
41 (test-ps-js method-call-op-form
42 ((@ (+ "" x) to-string))
43 "('' + x).toString()")
44
45 (test-ps-js method-call-op-form-args
46 ((@ (+ "" x) to-string) 1 2 :baz 3)
47 "('' + x).toString(1, 2, 'baz', 3)")
48
49 (test-ps-js method-call-number
50 ((@ 10 to-string))
51 "( 10 ).toString()")
52
53 (test-ps-js method-call-string
54 ((@ "hi" to-string))
55 "'hi'.toString()")
56
57 (test-ps-js method-call-lit-object
58 ((@ (create :to-string (lambda () (return "it works"))) to-string))
59 "( { toString : function () { return 'it works'; } } ).toString()")
60
61 (test-ps-js method-call-conditional
62 ((if a x y) 1)
63 "(a ? x : y)(1)")
64
65 (test-ps-js method-call-variable
66 ((@ x to-string))
67 "x.toString()")
68
69 (test-ps-js method-call-array
70 ((@ (list 10 20) to-string))
71 "[ 10, 20 ].toString()")
72
73 (test-ps-js method-call-fn-call
74 ((@ (foo) to-string))
75 "foo().toString()")
76
77 (test-ps-js method-call-lambda-fn
78 ((@ (lambda () (alert 10)) to-string))
79 "( function () { alert(10); } ).toString()")
80
81 (test-ps-js method-call-lambda-call
82 ((@ ((lambda (x) (return x)) 10) to-string))
83 "(function (x) { return x; })(10).toString()")
84
85 (test no-whitespace-before-dot
86 (let* ((str (ps1* '((@ ((lambda (x) (return x)) 10) to-string))))
87 (dot-pos (position #\. str :test #'char=))
88 (char-before (elt str (1- dot-pos)))
89 (a-parenthesis #\)))
90 (is (char= char-before a-parenthesis))))
91
92 (test-ps-js simple-slot-value
93 (let* ((foo (create :a 1)))
94 (alert (slot-value foo 'a)))
95 "var foo = { a : 1 };
96 alert(foo.a);")
97
98 (test-ps-js buggy-slot-value
99 (let* ((foo (create :a 1))
100 (slot-name "a"))
101 (alert (slot-value foo slot-name)))
102 " var foo = { a : 1 };
103 var slotName = 'a';
104 alert(foo[slotName]);
105 "); Last line was alert(foo.slotName) before bug-fix.
106
107 (test-ps-js buggy-slot-value-two
108 (slot-value foo (get-slot-name))
109 "foo[getSlotName()]")
110
111 (test-ps-js old-case-is-now-switch
112 ;; Switch was "case" before, but that was very non-lispish.
113 ;; For example, this code makes three messages and not one
114 ;; which may have been expected. This is because a switch
115 ;; statment must have a break statement for it to return
116 ;; after the alert. Otherwise it continues on the next
117 ;; clause.
118 (switch (aref blorg i)
119 (1 (alert "one"))
120 (2 (alert "two"))
121 (default (alert "default clause")))
122 "switch (blorg[i]) {
123 case 1: alert('one');
124 case 2: alert('two');
125 default: alert('default clause');
126 }")
127
128 (test-ps-js lisp-like-case
129 (case (aref blorg i)
130 (1 (alert "one"))
131 (2 (alert "two"))
132 (default (alert "default clause")))
133 "switch (blorg[i]) {
134 case 1:
135 alert('one');
136 break;
137 case 2:
138 alert('two');
139 break;
140 default: alert('default clause');
141 }")
142
143
144 (test-ps-js even-lispier-case
145 (case (aref blorg i)
146 ((1 2) (alert "Below three"))
147 (3 (alert "Three"))
148 (t (alert "Something else")))
149 "switch (blorg[i]) {
150 case 1:
151 case 2:
152 alert('Below three');
153 break;
154 case 3:
155 alert('Three');
156 break;
157 default: alert('Something else');
158 }")
159
160 (test-ps-js otherwise-case
161 (case (aref blorg i)
162 (1 (alert "one"))
163 (otherwise (alert "default clause")))
164 "switch (blorg[i]) {
165 case 1:
166 alert('one');
167 break;
168 default: alert('default clause');
169 }")
170
171 (test escape-sequences-in-string
172 (let ((escapes `((#\\ . #\\)
173 (#\b . #\Backspace)
174 (#\f . ,(code-char 12))
175 ("u000B" . ,(code-char #x000b));;Vertical tab, too uncommon to bother with
176 (#\n . #\Newline)
177 (#\r . #\Return)
178 (#\' . #\');;Double quote need not be quoted because parenscript strings are single quoted
179 (#\t . #\Tab)
180 ("u001F" . ,(code-char #x001f));; character below 32
181 ("u0080" . ,(code-char 128)) ;;Character over 127. Actually valid, parenscript escapes them to be sure.
182 ("uABCD" . ,(code-char #xabcd)))));; Really above ascii.
183 (loop for (js-escape . lisp-char) in escapes
184 for generated = (ps1* `(let* ((x ,(format nil "hello~ahi" lisp-char)))))
185 for wanted = (format nil "var x = 'hello\\~ahi';" js-escape)
186 do (is (string= (normalize-js-code generated) wanted)))))
187
188 (test-ps-js complicated-symbol-name1
189 grid-rows[foo].bar
190 "gridRows[foo].bar")
191
192 (test-ps-js complicated-symbol-name2
193 *grid-rows*[foo].bar
194 "GRIDROWS[foo].bar")
195
196 (test-ps-js slot-value-setf
197 (setf (slot-value x 'y) (+ (+ a 3) 4))
198 "x.y = (a + 3) + 4;")
199
200 (test-ps-js slot-value-conditional1
201 (slot-value (if zoo foo bar) 'x)
202 "(zoo ? foo : bar).x")
203
204 (test-ps-js slot-value-conditional2
205 (slot-value (if (not zoo) foo bar) 'x)
206 "(!zoo ? foo : bar).x")
207
208 (test script-star-eval1
209 (is (string= "x = 1; y = 2;" (normalize-js-code (ps* '(setf x 1) '(setf y 2))))))
210
211 (test script-star-eval2
212 (is (string= "x = 1;" (normalize-js-code (ps* '(setf x 1))))))
213
214 (test-ps-js unquoted-nil
215 nil
216 "null")
217
218 (test-ps-js list-with-single-nil
219 (array nil)
220 "[null]")
221
222 (test-ps-js quoted-nil-is-array
223 'nil
224 "[]")
225
226 (test-ps-js defsetf1
227 (progn (defsetf baz (x y) (newval) `(set-baz ,x ,y ,newval))
228 (setf (baz 1 2) 3))
229 "var _js2 = 1; var _js3 = 2; var _js1 = 3; setBaz(_js2, _js3, _js1);")
230
231 (test-ps-js defsetf-short
232 (progn (defsetf baz set-baz "docstring")
233 (setf (baz 1 2 3) "foo"))
234 "setBaz(1, 2, 3, 'foo');")
235
236 (test-ps-js defun-setf1
237 (progn (defun (setf some-thing) (new-val i1 i2)
238 (setf (aref *some-thing* i1 i2) new-val))
239 (setf (some-thing 1 2) "foo"))
240 "function __setf_someThing(newVal, i1, i2) {
241 SOMETHING[i1][i2] = newVal;
242 };
243 var _js2 = 1;
244 var _js3 = 2;
245 var _js1 = 'foo';
246 __setf_someThing(_js1, _js2, _js3);")
247
248 (test-ps-js defun-optional1
249 (defun test-opt (&optional x) (return (if x "yes" "no")))
250 "function testOpt(x) {
251 if (x === undefined) {
252 x = null;
253 };
254 return x ? 'yes' : 'no';
255 }")
256
257 (test-ps-js defun-optional2
258 (defun foo (x &optional y) (+ x y))
259 "function foo(x, y) {
260 if (y === undefined) {
261 y = null;
262 };
263 x + y;
264 }")
265
266 (test-ps-js defun-optional3
267 (defun blah (&optional (x 0))
268 (return x))
269 "function blah(x) {
270 if (x === undefined) {
271 x = 0;
272 };
273 return x;
274 }")
275
276 (test-ps-js return-nothing
277 (return)
278 "return null")
279
280 (test-ps-js set-timeout
281 (do-set-timeout (10) (alert "foo"))
282 "setTimeout(function () { alert('foo'); }, 10)")
283 (test-ps-js operator-precedence
284 (* 3 (+ 4 5) 6)
285 "3 * (4 + 5) * 6")
286
287 (test-ps-js operators-1
288 (in prop obj)
289 "prop in obj")
290
291 (test-ps-js incf1
292 (incf foo bar)
293 "foo += bar")
294
295 (test-ps-js decf1
296 (decf foo bar)
297 "foo -= bar")
298
299 (test-ps-js incf2
300 (incf x 5)
301 "x += 5")
302
303 (test-ps-js decf2
304 (decf y 10)
305 "y -= 10")
306
307 (test-ps-js setf-conditional
308 (setf foo (if x 1 2))
309 "foo = x ? 1 : 2;")
310
311 (test-ps-js obj-literal-numbers
312 (create 1 "foo")
313 "{ 1 : 'foo' }")
314
315 (test-ps-js obj-literal-strings
316 (create "foo" 2)
317 "{ 'foo' : 2 }")
318
319 (test-ps-js slot-value-string
320 (slot-value foo "bar")
321 "foo['bar']")
322
323 (test-ps-js slot-value-string1
324 (slot-value "bar" 'length)
325 "'bar'.length")
326
327 (test-ps-js slot-value-progn
328 (slot-value (progn (some-fun "abc") "123") "length")
329 "(someFun('abc'), '123')['length']")
330
331 (test-ps-js method-call-block
332 ((@ (progn (some-fun "abc") "123") to-string))
333 "(someFun('abc'), '123').toString()")
334
335 (test-ps-js create-blank
336 (create)
337 "{ }")
338
339 (test-ps-js blank-object-literal
340 {}
341 "{ }")
342
343 (test-ps-js array-literal1
344 []
345 "[]")
346
347 (test-ps-js array-literal2
348 ([])
349 "[]")
350
351 (test-ps-js array-literal3
352 ([] 1 2 3)
353 "[1, 2, 3]")
354
355 (test-ps-js array-literal4
356 ([] 1 (2 3))
357 "[1, [2, 3]]")
358
359 (test-ps-js array-literal5
360 ([] (1 2) ("a" "b"))
361 "[[1, 2], ['a', 'b']]")
362
363 (test-ps-js defun-rest1
364 (defun foo (&rest bar) (alert bar[1]))
365 "function foo() {
366 var bar = [];
367 for (var i1 = 0; i1 < arguments.length - 0; i1 += 1) {
368 bar[i1] = arguments[i1 + 0];
369 };
370 alert(bar[1]);
371 }")
372
373 (test-ps-js defun-rest2
374 (defun foo (baz &rest bar) (return (+ baz (aref bar 1))))
375 "function foo(baz) {
376 var bar = [];
377 for (var i1 = 0; i1 < arguments.length - 1; i1 += 1) {
378 bar[i1] = arguments[i1 + 1];
379 };
380 return baz + bar[1];
381 }")
382
383 (test-ps-js defun-keyword1
384 (defun zoo (foo bar &key baz) (return (+ foo bar baz)))
385 "function zoo(foo, bar) {
386 var baz;
387 var _js3 = arguments.length;
388 for (var n1 = 2; n1 < _js3; n1 += 2) {
389 switch (arguments[n1]) {
390 case 'baz':
391 {
392 baz = arguments[n1 + 1];
393 };
394 };
395 };
396 if (baz === undefined) {
397 baz = null;
398 };
399 return foo + bar + baz;
400 }")
401
402 (test-ps-js defun-keyword2
403 (defun zoo (&key baz) (return (* baz baz)))
404 "function zoo() {
405 var baz;
406 var _js3 = arguments.length;
407 for (var n1 = 0; n1 < _js3; n1 += 2) {
408 switch (arguments[n1]) {
409 case 'baz':
410 {
411 baz = arguments[n1 + 1];
412 };
413 };
414 };
415 if (baz === undefined) {
416 baz = null;
417 };
418 return baz * baz;
419 }")
420
421 (test-ps-js defun-keyword3
422 (defun zoo (&key baz (bar 4)) (return (* baz bar)))
423 "function zoo() {
424 var baz;
425 var bar;
426 var _js3 = arguments.length;
427 for (var n1 = 0; n1 < _js3; n1 += 2) {
428 switch (arguments[n1]) {
429 case 'baz':
430 {
431 baz = arguments[n1 + 1];
432 };
433 break;
434 case 'bar':
435 {
436 bar = arguments[n1 + 1];
437 };
438 };
439 };
440 if (baz === undefined) {
441 baz = null;
442 };
443 if (bar === undefined) {
444 bar = 4;
445 };
446 return baz * bar;
447 }")
448
449 (test-ps-js keyword-funcall1
450 (func :baz 1)
451 "func('baz', 1)")
452
453 (test-ps-js keyword-funcall2
454 (func :baz 1 :bar foo)
455 "func('baz', 1, 'bar', foo)")
456
457 (test-ps-js keyword-funcall3
458 (fun a b :baz c)
459 "fun(a, b, 'baz', c)")
460
461 (test-ps-js cond1
462 (cond ((= x 1) 1))
463 "if (x == 1) {
464 1;
465 }")
466
467 (test-ps-js cond2
468 (cond ((= x 1) 2)
469 ((= y (* x 4)) (foo "blah") (* x y)))
470 "if (x == 1) {
471 2;
472 } else if (y == x * 4) {
473 foo('blah');
474 x * y;
475 }")
476
477 (test-ps-js if-exp-without-else-returns-null
478 (return (if x 1))
479 "return x ? 1 : null")
480
481 (test-ps-js progn-expression-single-statement
482 (return (progn (* x y)))
483 "return x * y")
484
485 (test-ps-js cond-expression1
486 (defun foo () (return (cond ((< 1 2) (bar "foo") (* 4 5)))))
487 "function foo() {
488 return 1 < 2 ? (bar('foo'), 4 * 5) : null;
489 }")
490
491 (test-ps-js cond-expression2
492 (defun foo () (return (cond ((< 2 1) "foo") ((= 7 7) "bar"))))
493 "function foo() {
494 return 2 < 1 ? 'foo' : (7 == 7 ? 'bar' : null);
495 }")
496
497 (test-ps-js cond-expression-final-t-clause
498 (defun foo () (return (cond ((< 1 2) (bar "foo") (* 4 5)) ((= a b) (+ c d)) ((< 1 2 3 4 5) x) (t "foo"))))
499 "function foo() {
500 return 1 < 2 ? (bar('foo'), 4 * 5) : (a == b ? c + d : (1 < 2 < 3 < 4 < 5 ? x : 'foo'));
501 }")
502
503 (test-ps-js cond-expression-middle-t-clause ;; should this signal a warning?
504 (defun foo () (return (cond ((< 2 1) 5) (t "foo") ((< 1 2) "bar"))))
505 "function foo() {
506 return 2 < 1 ? 5 : 'foo';
507 }")
508
509 (test-ps-js funcall-if-expression
510 (document.write
511 (if (= *linkornot* 1)
512 (ps-html ((:a :href "#"
513 :onclick (ps-inline (transport)))
514 img))
515 img))
516 "document.write(LINKORNOT == 1 ? '<A HREF=\"#\" ONCLICK=\"' + ('javascript:' + 'transport' + '(' + ')') + '\">' + img + '</A>' : img)")
517
518 (test-ps-js negate-number-literal ;; ok, this was broken and fixed before, but no one bothered to add the test!
519 (- 1)
520 "-1")
521
522 (test macro-environment1
523 (is (string= (normalize-js-code (let* ((macroname (gensym)))
524 (ps* `(defmacro ,macroname (x) `(+ ,x 123))
525 `(defun test1 ()
526 (macrolet ((,macroname (x) `(aref data ,x)))
527 (when (,macroname x)
528 (setf (,macroname x) 123)))))))
529 (normalize-js-code
530 "function test1() {
531 if (data[x]) {
532 data[x] = 123;
533 };
534 };
535 "))))
536
537 (test macro-environment2
538 (is (string= (normalize-js-code (let ((outer-lexical-variable 1))
539 (defpsmacro macro-environment2-macro (x)
540 `(+ ,outer-lexical-variable ,x))
541 (ps* '(macro-environment2-macro 2))))
542 (normalize-js-code "1 + 2;"))))
543
544 (test-ps-js ampersand-whole-1
545 (macrolet ((foo (&whole foo bar baz)
546 (declare (ignore bar baz))
547 (format nil "~a" foo)))
548 (foo 1 2))
549 "'(FOO 1 2)';")
550
551 (test-ps-js keyword-consistent
552 :x
553 "'x'")
554
555 (test-ps-js simple-symbol-macrolet
556 (symbol-macrolet ((x 1)) x)
557 "1;")
558
559 (test-ps-js compound-symbol-macrolet
560 (symbol-macrolet ((x 123)
561 (y (* 2 x)))
562 y)
563 "2 * 123;")
564
565 (test-ps-js define-symbol-macro
566 (progn (define-symbol-macro tst-sym-macro 2)
567 tst-sym-macro)
568 "2;")
569
570 (test-ps-js expression-progn
571 (defun f () (return (progn (foo) (if x 1 2))))
572 "function f() {
573 return (foo(), x ? 1 : 2);
574 }")
575
576 (test-ps-js let-decl-in-expression
577 (defun f (x) (return (if x 1 (let* ((foo x)) foo))))
578 "function f(x) {
579 var foo;
580 return x ? 1 : (foo = x, foo);
581 }")
582
583 (test-ps-js special-var1
584 (progn (defvar *foo*) (let* ((*foo* 2)) (* *foo* 2)))
585 "var FOO;
586 var tempstackvar1;
587 try {
588 tempstackvar1 = FOO;
589 FOO = 2;
590 FOO * 2;
591 } finally {
592 FOO = tempstackvar1;
593 delete tempstackvar1;
594 };")
595
596 (test-ps-js special-var2
597 (progn (defvar *foo*) (let* ((*baz* 3) (*foo* 2)) (* *foo* 2 *baz*)))
598 "var FOO;
599 var BAZ = 3;
600 var tempstackvar1;
601 try {
602 tempstackvar1 = FOO;
603 FOO = 2;
604 FOO * 2 * BAZ;
605 } finally {
606 FOO = tempstackvar1;
607 delete tempstackvar1;
608 };
609 ")
610
611 (test-ps-js literal1
612 (setf x undefined)
613 "x = undefined;")
614
615 (test-ps-js literal2
616 (aref this x)
617 "this[x]")
618
619 (test-ps-js setf-dec1
620 (setf x (- 1 x 2))
621 "x = 1 - x - 2;")
622
623 (test-ps-js setf-dec2
624 (setf x (- x 1 2))
625 "x = x - 1 - 2;")
626
627 (test-ps-js special-char-equals
628 blah=
629 "blahequals")
630
631 (test-ps-js setf-operator-priority
632 (return (or (slot-value cache id)
633 (setf (slot-value cache id) (document.get-element-by-id id))))
634 "return cache[id] || (cache[id] = document.getElementById(id))")
635
636 (test-ps-js aref-operator-priority
637 (aref (if (and x (> (length x) 0))
638 (aref x 0)
639 y)
640 z)
641 "(x && x.length > 0 ? x[0] : y)[z]")
642
643 (test-ps-js aref-operator-priority1
644 (aref (or (slot-value x 'y)
645 (slot-value a 'b))
646 z)
647 "(x.y || a.b)[z]")
648
649 (test-ps-js aref-operator-priority2
650 (aref (if a b c) 0)
651 "(a ? b : c)[0]")
652
653 (test-ps-js negative-operator-priority
654 (- (if x y z))
655 "-(x ? y : z)")
656
657 (test-ps-js op-p1
658 (new (or a b))
659 "new (a || b)")
660
661 (test-ps-js op-p2
662 (delete (if a (or b c) d))
663 "delete (a ? b || c : d)")
664
665 (test-ps-js op-p3
666 (not (if (or x (not y)) z))
667 "!(x || !y ? z : null)")
668
669 (test-ps-js op-p4
670 (- (- (* 1 2) 3))
671 "-(1 * 2 - 3)")
672
673 (test-ps-js op-p5
674 (instanceof (or a b) (if x y z))
675 "((a || b) instanceof (x ? y : z))")
676
677 (test-ps-js op-p7
678 (or x (if (= x 0) "zero" "empty"))
679 "x || (x == 0 ? 'zero' : 'empty')")
680
681 (test-ps-js named-op-expression
682 (throw (if a b c))
683 "throw a ? b : c")
684
685 (test-ps-js named-op-expression1
686 (typeof (or x y))
687 "typeof (x || y)")
688
689 (test-ps-js aref-array-expression
690 (aref (or a b c) 0)
691 "(a || b || c)[0]")
692
693 (test-ps-js slot-value-operator
694 (slot-value (or a b c) 'd)
695 "(a || b || c).d")
696
697 (test-ps-js slot-value-parens
698 (slot-value (slot-value foo 'bar) 'baz)
699 "foo.bar.baz")
700
701 (test-ps-js funcall-funcall
702 ((foo))
703 "foo()()")
704
705 (test-ps-js expression-funcall
706 ((or (@ window eval) eval) foo nil)
707 "(window.eval || eval)(foo, null)")
708
709 (test-ps-js expression-funcall1
710 (((or (@ window eval) eval) foo nil))
711 "(window.eval || eval)(foo, null)()")
712
713 (test-ps-js expression-funcall2
714 (((or (@ window eval) eval)) foo nil)
715 "(window.eval || eval)()(foo, null)")
716
717 (test-ps-js slot-value-object-literal
718 (slot-value (create :a 1) 'a)
719 "({ a : 1 }).a")
720
721 (test-ps-js slot-value-lambda
722 (slot-value (lambda ()) 'prototype)
723 "(function () { }).prototype")
724
725 (test-ps-js who-html1
726 (who-ps-html (:span :class "ticker-symbol"
727 :ticker-symbol symbol
728 (:a :href "http://foo.com"
729 symbol)
730 (:span :class "ticker-symbol-popup")))
731 "'<SPAN CLASS=\"ticker-symbol\" TICKER-SYMBOL=\"' + symbol + '\"><A HREF=\"http://foo.com\">' + symbol + '</A><SPAN CLASS=\"ticker-symbol-popup\"></SPAN></SPAN>'")
732
733 (test-ps-js flet1
734 ((lambda () (flet ((foo (x) (return (1+ x)))) (return (foo 1)))))
735 "(function () {
736 var foo = function (x) {
737 return x + 1;
738 };
739 return foo(1);
740 })()")
741
742 (test-ps-js labels1
743 ((lambda () (labels ((foo (x)
744 (return (if (=== 0 x)
745 0
746 (+ x (foo (1- x)))))))
747 (return (foo 3)))))
748 "(function () {
749 var foo = function foo(x) {
750 return 0 === x ? 0 : x + foo(x - 1);
751 };
752 return foo(3);
753 })()")
754
755 (test-ps-js for-loop-var-init-exp
756 ((lambda (x)
757 (return (do* ((y (if x 0 1) (1+ y))
758 (z 0 (1+ z)))
759 ((= y 3) z))))
760 true)
761 "(function (x) {
762 return (function () {
763 for (var y = x ? 0 : 1, z = 0; y != 3; y += 1, z += 1) {
764 };
765 return z;
766 })();
767 })(true)")
768
769 (test-ps-js math-pi
770 pi
771 "Math.PI")
772
773 (test-ps-js literal-array
774 '(1 2 3)
775 "[1, 2, 3]")
776
777 (test-ps-js literal-array-1
778 '(1 foo 3)
779 "[1, 'foo', 3]")
780
781 (test ps-lisp-expands-in-lexical-environment
782 (is (string= "5;" (let ((x 5)) (ps (lisp x))))))
783
784 (test ps*-lisp-expands-in-null-lexical-environment
785 (signals error (let ((x 5)) (declare (ignore x)) (ps* '(lisp x)))))
786
787 (test ps*-lisp-expands-in-dynamic-environment
788 (is (string= "1 + 2;" (let ((*print-level* 2)) (ps* '(+ 1 (lisp *print-level*)))))))
789
790 (test ps-lisp-dynamic-environment
791 (is (string= "1 + 2;" (let ((*print-level* 2)) (ps (+ 1 (lisp *print-level*)))))))
792
793 (test-ps-js ps-js-target-version-keyword-test1
794 (defun foo (x y &key bar baz))
795 "function foo(x, y) {
796 var x1 = Array.prototype.indexOf.call(arguments, 'bar', 2);
797 var bar = -1 == x1 ? null : arguments[x1 + 1];
798 var x2 = Array.prototype.indexOf.call(arguments, 'baz', 2);
799 var baz = -1 == x2 ? null : arguments[x2 + 1];
800 }"
801 :js-target-version 1.6)