+
+(test-ps-js set-timeout
+ (do-set-timeout (10) (alert "foo"))
+ "setTimeout(function () { alert('foo'); }, 10)")
+(test-ps-js operator-precedence
+ (* 3 (+ 4 5) 6)
+ "3 * (4 + 5) * 6")
+
+(test-ps-js operators-1
+ (in prop obj)
+ "prop in obj")
+
+(test-ps-js incf1
+ (incf foo bar)
+ "foo += bar")
+
+(test-ps-js decf1
+ (decf foo bar)
+ "foo -= bar")
+
+(test-ps-js incf2
+ (incf x 5)
+ "x += 5")
+
+(test-ps-js decf2
+ (decf y 10)
+ "y -= 10")
+
+(test-ps-js setf-conditional
+ (setf foo (if x 1 2))
+ "foo = x ? 1 : 2;")
+
+(test-ps-js obj-literal-numbers
+ (create 1 "foo")
+ "{ 1 : 'foo' }")
+
+(test-ps-js obj-literal-strings
+ (create "foo" 2)
+ "{ 'foo' : 2 }")
+
+(test-ps-js slot-value-string
+ (slot-value foo "bar")
+ "foo['bar']")
+
+(test-ps-js slot-value-progn
+ (slot-value (progn (some-fun "abc") "123") "length")
+ "(someFun('abc'), '123')['length']")
+
+(test-ps-js method-call-block
+ (.to-string (progn (some-fun "abc") "123"))
+ "(someFun('abc'), '123').toString()")
+
+(test-ps-js create-blank
+ (create)
+ "{ }")
+
+(test-ps-js blank-object-literal
+ {}
+ "{ }")
+
+(test-ps-js object-literal-1
+ ({})
+ "{ }")
+
+(test-ps-js object-literal-2
+ ({} a 1 b 2)
+ "{a: 1, b: 2 }")
+
+(test-ps-js array-literal1
+ []
+ "[]")
+
+(test-ps-js array-literal2
+ ([])
+ "[]")
+
+(test-ps-js array-literal3
+ ([] 1 2 3)
+ "[1, 2, 3]")
+
+(test-ps-js array-literal4
+ ([] 1 (2 3))
+ "[1, [2, 3]]")
+
+(test-ps-js array-literal5
+ ([] (1 2) ("a" "b"))
+ "[[1, 2], ['a', 'b']]")
+
+(test-ps-js defun-rest1
+ (defun foo (&rest bar) (alert bar[1]))
+ "function foo() {
+ var bar = [];
+ for (var i2 = 0; i2 < arguments.length - 0; i2 += 1) {
+ bar[i2] = arguments[i2 + 0];
+ };
+ alert(bar[1]);
+}")
+
+(test-ps-js defun-rest2
+ (defun foo (baz &rest bar) (return (+ baz (aref bar 1))))
+ "function foo(baz) {
+ var bar = [];
+ for (var i2 = 0; i2 < arguments.length - 1; i2 += 1) {
+ bar[i2] = arguments[i2 + 1];
+ };
+ return baz + bar[1];
+}")
+
+(test-ps-js defun-keyword1
+ (defun zoo (foo bar &key baz) (return (+ foo bar baz)))
+ "function zoo(foo, bar, _js1) {
+ if (_js1 === undefined) {
+ _js1 = { };
+ };
+ return foo + bar + _js1.baz;
+}")
+
+(test-ps-js defun-keyword2
+ (defun zoo (&key baz) (return (* baz baz)))
+ "function zoo(_js1) {
+ if (_js1 === undefined) {
+ _js1 = { };
+ };
+ return _js1.baz * _js1.baz;
+}")
+
+(test-ps-js defun-keyword3
+ (defun zoo (&key baz (bar 4)) (return (* baz bar)))
+ "function zoo(_js1) {
+ if (_js1 === undefined) {
+ _js1 = { };
+ };
+ if (_js1.bar === undefined) {
+ _js1.bar = 4;
+ };
+ return _js1.baz * _js1.bar;
+}")
+
+(test-ps-js keyword-funcall1
+ (func :baz 1)
+ "func({ baz : 1 })")
+
+(test-ps-js keyword-funcall2
+ (func :baz 1 :bar foo)
+ "func({ baz : 1, bar : foo })")
+
+(test-ps-js keyword-funcall3
+ (fun a b :baz c)
+ "fun(a, b, { baz : c })")
+
+(test-ps-js cond1
+ (cond ((= x 1) 1))
+ "if (x == 1) {
+ 1;
+}")
+
+(test-ps-js cond2
+ (cond ((= x 1) 2) ((= y (* x 4)) (foo "blah") (* x y)))
+ "if (x == 1) {
+ 2;
+} else if (y == x * 4) {
+ foo('blah');
+ x * y;
+}")
+
+(test-ps-js if-exp-without-else-returns-null
+ (return (if x 1))
+ "return x ? 1 : null")
+
+(test-ps-js progn-expression-single-statement
+ (return (progn (* x y)))
+ "return x * y")
+
+(test-ps-js cond-expression1
+ (defun foo () (return (cond ((< 1 2) (bar "foo") (* 4 5)))))
+ "function foo() {
+ return 1 < 2 ? (bar('foo'), 4 * 5) : null;
+}")
+
+(test-ps-js cond-expression2
+ (defun foo () (return (cond ((< 2 1) "foo") ((= 7 7) "bar"))))
+ "function foo() {
+ return 2 < 1 ? 'foo' : (7 == 7 ? 'bar' : null);
+}")
+
+(test-ps-js cond-expression-final-t-clause
+ (defun foo () (return (cond ((< 1 2) (bar "foo") (* 4 5)) ((= a b) (+ c d)) ((< 1 2 3 4 5) x) (t "foo"))))
+ "function foo() {
+ return 1 < 2 ? (bar('foo'), 4 * 5) : (a == b ? c + d : (1 < 2 < 3 < 4 < 5 ? x : 'foo'));
+}")
+
+(test-ps-js cond-expression-middle-t-clause ;; should this signal a warning?
+ (defun foo () (return (cond ((< 2 1) 5) (t "foo") ((< 1 2) "bar"))))
+ "function foo() {
+ return 2 < 1 ? 5 : 'foo';
+}")
+
+(test-ps-js funcall-if-expression
+ (document.write
+ (if (= *linkornot* 1)
+ (ps-html ((:a :href "#"
+ :onclick (lisp (ps-inline (transport))))
+ img))
+ img))
+ "document.write(LINKORNOT == 1 ? '<A HREF=\"#\" ONCLICK=\"' + 'javascript:transport()' + '\">' + img + '</A>' : img)")
+
+(test-ps-js negate-number-literal ;; ok, this was broken and fixed before, but no one bothered to add the test!
+ (- 1)
+ "-1")
+
+(test macro-environment1
+ (is (string= (normalize-js-code (let* ((macroname (gensym)))
+ (ps* `(defmacro ,macroname (x) `(+ ,x 123))
+ `(defun test1 ()
+ (macrolet ((,macroname (x) `(aref data ,x)))
+ (when (,macroname x)
+ (setf (,macroname x) 123)))))))
+ (normalize-js-code
+"function test1() {
+ if (data[x]) {
+ data[x] = 123;
+ };
+};
+"))))
+
+(test-ps-js ampersand-whole-1
+ (macrolet ((foo (&whole foo bar baz)
+ (declare (ignore bar baz))
+ (format nil "~a" foo)))
+ (foo 1 2))
+ "'(FOO 1 2)';")
+
+(test-ps-js keyword-consistent
+ :x
+ "'x'")
+
+(test-ps-js simple-symbol-macrolet
+ (symbol-macrolet ((x 1)) x)
+ "1;")
+
+(test-ps-js compound-symbol-macrolet
+ (symbol-macrolet ((x 123)
+ (y (* 2 x)))
+ y)
+ "2 * 123;")
+
+(test-ps-js define-symbol-macro
+ (progn (define-symbol-macro tst-sym-macro 2)
+ tst-sym-macro)
+ "2;")
+
+(test-ps-js expression-progn
+ (defun f () (return (progn (foo) (if x 1 2))))
+ "function f() {
+ return (foo(), x ? 1 : 2);
+}")
+
+(test-ps-js let-decl-in-expression
+ (defun f (x) (return (if x 1 (let* ((foo x)) foo))))
+ "function f(x) {
+ var foo;
+ return x ? 1 : (foo = x, foo);
+}")
+
+(test-ps-js special-var1
+ (progn (defvar *foo*) (let* ((*foo* 2)) (* *foo* 2)))
+ "var FOO;
+var tempstackvar1;
+try {
+ tempstackvar1 = FOO;
+ FOO = 2;
+ FOO * 2;
+} finally {
+ FOO = tempstackvar1;
+ delete tempstackvar1;
+};")
+
+(test-ps-js special-var2
+ (progn (defvar *foo*) (let* ((*baz* 3) (*foo* 2)) (* *foo* 2 *baz*)))
+ "var FOO;
+var BAZ = 3;
+var tempstackvar1;
+try {
+ tempstackvar1 = FOO;
+ FOO = 2;
+ FOO * 2 * BAZ;
+} finally {
+ FOO = tempstackvar1;
+ delete tempstackvar1;
+};
+")
+
+(test-ps-js literal1
+ (setf x undefined)
+ "x = undefined;")
+
+(test-ps-js literal2
+ (aref this x)
+ "this[x]")
+
+(test-ps-js setf-dec1
+ (setf x (- 1 x 2))
+ "x = 1 - x - 2;")
+
+(test-ps-js setf-dec2
+ (setf x (- x 1 2))
+ "x = x - 1 - 2;")
+
+(test-ps-js special-char-equals
+ blah=
+ "blahequals")
+
+(test-ps-js setf-operator-priority
+ (return (or (slot-value cache id)
+ (setf (slot-value cache id) (document.get-element-by-id id))))
+ "return cache[id] || (cache[id] = document.getElementById(id))")
+
+(test-ps-js aref-operator-priority
+ (aref (if (and x (> (length x) 0))
+ (aref x 0)
+ y)
+ z)
+ "(x && x.length > 0 ? x[0] : y)[z]")
+
+(test-ps-js aref-operator-priority1
+ (aref (or (slot-value x 'y)
+ (slot-value a 'b))
+ z)
+ "(x.y || a.b)[z]")
+
+(test-ps-js aref-operator-priority2
+ (aref (if a b c) 0)
+ "(a ? b : c)[0]")
+
+(test-ps-js negative-operator-priority
+ (- (if x y z))
+ "-(x ? y : z)")
+
+(test-ps-js op-p1
+ (new (or a b))
+ "new (a || b)")
+
+(test-ps-js op-p2
+ (delete (if a (or b c) d))
+ "delete (a ? b || c : d)")
+
+(test-ps-js op-p3
+ (not (if (or x (not y)) z))
+ "!(x || !y ? z : null)")
+
+(test-ps-js op-p4
+ (- (- (* 1 2) 3))
+ "-(1 * 2 - 3)")
+
+(test-ps-js op-p5
+ (instanceof (or a b) (if x y z))
+ "((a || b) instanceof (x ? y : z))")
+
+(test-ps-js op-p6
+ (doeach (x (or a b)))
+ "for (var x in (a || b)) { };")
+
+(test-ps-js op-p7
+ (or x (if (= x 0) "zero" "empty"))
+ "x || (x == 0 ? 'zero' : 'empty')")
+
+(test-ps-js named-op-expression
+ (throw (if a b c))
+ "throw a ? b : c")
+
+(test-ps-js named-op-expression1
+ (typeof (or x y))
+ "typeof (x || y)")
+
+(test-ps-js aref-array-expression
+ (aref (or a b c) 0)
+ "(a || b || c)[0]")
+
+(test-ps-js slot-value-operator
+ (slot-value (or a b c) 'd)
+ "(a || b || c).d")
+
+(test-ps-js slot-value-parens
+ (slot-value (slot-value foo 'bar) 'baz)
+ "foo.bar.baz")