Renamed src/lib Parenscript library files, got rid of Parenscript CSS system.
[clinton/parenscript.git] / t / reference-tests.lisp
index e497db1..a90792e 100644 (file)
@@ -1,4 +1,4 @@
-(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
   "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")
 
@@ -252,7 +244,7 @@ blafoo(i);")
 
 (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))
@@ -263,15 +255,45 @@ x = a + b + c;")
 
 (test-ps-js assignment-3
   (setf a (1+ a))
-  "a++")
+  "a++;")
 
 (test-ps-js assignment-4
   (setf a (+ a 2 3 4 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)
@@ -328,14 +350,14 @@ x = a + b + c;")
 
 (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);
@@ -346,16 +368,26 @@ x = a + b + c;")
 
 (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
@@ -380,14 +412,12 @@ x = a + b + c;")
 (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)
@@ -409,7 +439,7 @@ x = a + b + c;")
   (2 (alert "two"))
   (t (alert "default clause")))
   "switch (blorg[i]) {
-  case 1:   ;
+  case 1:   
   case 'one':
             alert('one');
             break;
@@ -453,46 +483,29 @@ x = a + b + c;")
 }")
 
 (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
-  (let ((disabled nil)
+  (let* ((disabled nil)
       (authorized t))
    (setf element.inner-h-t-m-l
-         (html ((:textarea (or disabled (not authorized)) :disabled "disabled")
+         (ps-html ((:textarea (or disabled (not authorized)) :disabled "disabled")
                 "Edit me"))))
-  " {
-   var disabled = null;
+  "   var disabled = null;
    var authorized = true;
    element.innerHTML =
    '<textarea'
    + (disabled || !authorized ? ' disabled=\"' + 'disabled' + '\"' : '')
-   + '>Edit me</textarea>';
- }")
-
-(test-ps-js the-html-generator-5
-  (css-inline :color "red"
-            :font-size "x-small")
-  "'color:red;font-size:x-small'")
-
-(test-ps-js the-html-generator-6
-  (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>';
-}")
+   + '>Edit me</textarea>';")