-(in-package :js-test)
+(in-package :ps-test)
;; Tests of everything in the reference.
;; File is generated automatically from the text in reference.lisp by
;; the function make-reference-tests-dot-lisp in ref2test.lisp
;; so do not edit this file.
-(def-suite ref-tests)
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (def-suite ref-tests))
(in-suite ref-tests)
(test-ps-js statements-and-expressions-1
"1 * (2 + 3 + 4) * 4 * (6 / 7)")
(test-ps-js operator-expressions-6
- (++ i)
- "i++")
-
-(test-ps-js operator-expressions-7
- (-- i)
- "i--")
-
-(test-ps-js operator-expressions-8
(incf i)
"++i")
-(test-ps-js operator-expressions-9
+(test-ps-js operator-expressions-7
(decf i)
"--i")
-(test-ps-js operator-expressions-10
+(test-ps-js operator-expressions-8
(1- i)
"i - 1")
-(test-ps-js operator-expressions-11
+(test-ps-js operator-expressions-9
(1+ i)
"i + 1")
-(test-ps-js operator-expressions-12
+(test-ps-js operator-expressions-10
(not (< i 2))
"i >= 2")
-(test-ps-js operator-expressions-13
+(test-ps-js operator-expressions-11
(not (eql i 2))
"i != 2")
(test-ps-js assignment-1
(setf a 1)
- "a = 1")
+ "a = 1;")
(test-ps-js assignment-2
(setf a 2 b 3 c 4 x (+ a b c))
(test-ps-js assignment-3
(setf a (1+ a))
- "a++")
+ "a++;")
(test-ps-js assignment-4
- (setf a (* 2 3 4 a 4 a))
- "a *= 2 * 3 * 4 * 4 * a")
+ (setf a (+ a 2 3 4 a))
+ "a += 2 + 3 + 4 + a;")
(test-ps-js assignment-5
(setf a (- 1 a))
- "a = 1 - a")
+ "a = 1 - a;")
+
+(test-ps-js assignment-6
+ (defun (setf color) (new-color el)
+ (setf (slot-value (slot-value el 'style) 'color) new-color))
+ "function __setf_color(newColor, el) {
+ el.style.color = newColor;
+};")
+
+(test-ps-js assignment-7
+ (setf (color some-div) (+ 23 "em"))
+ "var _js2 = someDiv;
+var _js1 = 23 + 'em';
+__setf_color(_js1, _js2);")
+
+(test-ps-js assignment-8
+ (defsetf left (el) (offset)
+ `(setf (slot-value (slot-value ,el 'style) 'left) ,offset))
+ "null")
+
+(test-ps-js assignment-9
+ (setf (left some-div) (+ 123 "px"))
+ "var _js2 = someDiv;
+var _js1 = 123 + 'px';
+_js2.style.left = _js1;")
+
+(test-ps-js assignment-10
+ (progn (defmacro left (el)
+ `(slot-value ,el 'offset-left))
+ (left some-div))
+ "someDiv.offsetLeft;")
(test-ps-js single-argument-statements-1
(return 1)
(test-ps-js variable-declaration-1
(defvar *a* (array 1 2 3))
- "var A = [ 1, 2, 3 ];")
+ "var A = [ 1, 2, 3 ]")
(test-ps-js variable-declaration-2
(if (= i 1)
- (progn (defvar blorg "hallo")
- (alert blorg))
- (progn (defvar blorg "blitzel")
- (alert blorg)))
+ (let* ((blorg "hallo"))
+ (alert blorg))
+ (let* ((blorg "blitzel"))
+ (alert blorg)))
"if (i == 1) {
var blorg = 'hallo';
alert(blorg);
(test-ps-js variable-declaration-3
(if (= i 1)
- (let ((blorg "hallo"))
+ (lexical-let* ((blorg "hallo"))
(alert blorg))
- (let ((blorg "blitzel"))
+ (lexical-let* ((blorg "blitzel"))
(alert blorg)))
"if (i == 1) {
- var blorg = 'hallo';
- alert(blorg);
+ (function () {
+ var newlexicalcontext1 = new Object;
+ newlexicalcontext1['blorg'] = 'hallo';
+ with (newlexicalcontext1) {
+ alert(blorg);
+ };
+ })();
} else {
- var blorg = 'blitzel';
- alert(blorg);
+ (function () {
+ var newlexicalcontext3 = new Object;
+ newlexicalcontext3['blorg'] = 'blitzel';
+ with (newlexicalcontext3) {
+ alert(blorg);
+ };
+ })();
}")
(test-ps-js iteration-constructs-1
(test-ps-js iteration-constructs-3
(dolist (l blorg)
(document.write (+ "L is " l)))
- "{
- var tmpArr1 = blorg;
+ " var tmpArr1 = blorg;
for (var tmpI2 = 0; tmpI2 < tmpArr1.length;
tmpI2 = tmpI2 + 1) {
var l = tmpArr1[tmpI2];
document.write('L is ' + l);
- };
-}")
+ };")
(test-ps-js iteration-constructs-4
(doeach (i object)
(2 (alert "two"))
(t (alert "default clause")))
"switch (blorg[i]) {
- case 1: ;
+ case 1:
case 'one':
alert('one');
break;
}")
(test-ps-js the-with-statement-1
- (with ((create :foo "foo" :i "i"))
+ (with (create :foo "foo" :i "i")
(alert (+ "i is now intermediary scoped: " i)))
"with ({ foo : 'foo',
i : 'i' }) {
}")
(test-ps-js the-html-generator-1
- (html ((:a :href "foobar") "blorg"))
+ (ps-html ((:a :href "foobar") "blorg"))
"'<a href=\"foobar\">blorg</a>'")
(test-ps-js the-html-generator-2
- (html ((:a :href (generate-a-link)) "blorg"))
+ (ps-html ((:a :href (generate-a-link)) "blorg"))
"'<a href=\"' + generateALink() + '\">blorg</a>'")
(test-ps-js the-html-generator-3
(document.write
- (html ((:a :href "#"
- :onclick (js-inline (transport))) "link")))
- "document.write
-('<a href=\"#\" onclick=\"' + 'javascript:transport();' + '\">link</a>')")
+ (ps-html ((:a :href "#"
+ :onclick (lisp (ps-inline (transport)))) "link")))
+ "document.write('<a href=\"#\" onclick=\"' + 'javascript:transport()' + '\">link</a>')")
(test-ps-js the-html-generator-4
- (css-inline :color "red"
- :font-size "x-small")
- "'color:red;font-size:x-small'")
-
-(test-ps-js the-html-generator-5
- (defun make-color-div(color-name)
- (return (html ((:div :style (css-inline :color color-name))
- color-name " looks like this."))))
- "function makeColorDiv(colorName) {
- return '<div style=\"' + ('color:' + colorName) + '\">' + colorName
- + ' looks like this.</div>';
-}")
-
+ (let* ((disabled nil)
+ (authorized t))
+ (setf element.inner-h-t-m-l
+ (ps-html ((:textarea (or disabled (not authorized)) :disabled "disabled")
+ "Edit me"))))
+ " var disabled = null;
+ var authorized = true;
+ element.innerHTML =
+ '<textarea'
+ + (disabled || !authorized ? ' disabled=\"' + 'disabled' + '\"' : '')
+ + '>Edit me</textarea>';")
-(run-tests)