bug in dwim-join
authorHenrik Hjelte <henrik.hjelte@poboxes.com>
Sun, 18 Dec 2005 17:17:24 +0000 (17:17 +0000)
committerHenrik Hjelte <henrik.hjelte@poboxes.com>
Sun, 18 Dec 2005 17:17:24 +0000 (17:17 +0000)
js.lisp
ref2test.lisp
reference-tests.lisp
test.lisp

diff --git a/js.lisp b/js.lisp
index bd3df21..94a5a2c 100644 (file)
--- a/js.lisp
+++ b/js.lisp
          (t (error "unsupported form ~S" form)))))
 
 (defun dwim-join (value-string-lists max-length
-                 &key start end
-                      join-before join-after
-                 white-space (separator " ")
+                 &key (start "")
+                       end
+                      (join-before "")
+                       join-after
+                      (white-space (make-string (length start) :initial-element #\Space))
+                       (separator " ")
                  (append-to-last #'append-to-last)
                  (collect t))
     #+nil
     (format t "value-string-lists: ~S~%" value-string-lists)
 
-    (unless start
-      (setf start ""))
-
-    (unless join-before
-      (setf join-before ""))
-
     ;;; collect single value-string-lists until line full
     
     (do* ((string-lists value-string-lists (cdr string-lists))
          (string-list (car string-lists) (car string-lists))
          (cur-elt start)
+          (is-first t nil)
          (cur-empty t)
-         (white-space (or white-space (make-string (length start) :initial-element #\Space)))
          (res nil))
         ((null string-lists)
          (unless cur-empty
                  (setf (first res)
                        (funcall append-to-last (first res) end)))
                (nreverse res))))
-
       #+nil
       (format t "string-list: ~S~%" string-list)
 
                          (length cur-elt)) max-length))
                (setf cur-elt
                      (concatenate 'string cur-elt
-                                  (if cur-empty "" (concatenate 'string separator join-before))
+                                  (if (or is-first (and cur-empty (string= join-before "")))
+                                        "" (concatenate 'string separator join-before))
                                   (first string-list))
                      cur-empty nil)
                (progn
                    cur-empty t))
            (setf res (nconc (nreverse
                              (cons (concatenate 'string
-                                                cur-elt (if (null res)
-                                                            "" join-before)
+                                                cur-elt
+                                                 (if (null res)
+                                                    "" join-before)
                                                 (first string-list))
                                    (mapcar #'(lambda (x) (concatenate 'string white-space x))
-                                           (cdr string-list)))) res))
+                                           (cdr string-list))))
+                             res))
            (setf cur-elt white-space cur-empty t)))))
 
 (defmethod js-to-strings ((expression expression) start-pos)
@@ -479,7 +478,8 @@ this macro."
                  (op-args form)))
         (max-length (- 80 start-pos 2))
         (op-string (format nil "~A " (operator form))))
-    (dwim-join value-string-lists max-length :join-before op-string)))
+    (dwim-join value-string-lists max-length :join-before op-string)    
+    ))
 
 (defjsmacro 1- (form)
   `(- ,form 1))
index 88153a1..390ab09 100644 (file)
@@ -96,4 +96,4 @@
                                             (when (not (empty-p built))
                                               (list #\Newline))
                                             line))))))
-        (format out-stream "~%(run! 'ref-tests)~%")))))
+        (format out-stream "~%(run-tests)~%")))))
index 7fc9a09..bd99496 100644 (file)
@@ -461,4 +461,4 @@ x = a + b + c;")
 }")
 
 
-(run! 'ref-tests)
+(run-tests)
index 2ed47b4..f6ebcf7 100644 (file)
--- a/test.lisp
+++ b/test.lisp
@@ -1,4 +1,5 @@
 (in-package :js-test)
+
 ;; Testcases for parenscript
 
 (defun trim-whitespace(str)
                    (normalize-js-code js-code)))))) 
 
 (defun run-tests()
-  (run! 'ref-tests))
+  (format t "Running reference tests:~&")
+  (run! 'ref-tests)
+  (format t "Running other tests:~&")
+  (run! 'ps-tests))
+
+;;---------------------------------------------------------------------------
+(def-suite ps-tests)
+(in-suite ps-tests)
+
+;; A problem with long nested operator, when the statement spanned several rows
+;; the rows would not be joined together correctly.
+(test-ps-js bug-dwim-join
+   (alert (html ((:div :id 777
+                       :style (css-inline :border "1pxsssssssssss"
+                                          :font-size "x-small"
+                                          :height (* 2 200)
+                                          :width (* 2 300))))))
+   "alert
+('<div id=\"777\" style=\"'
+ + ('border:1pxsssssssssss;font-size:x-small;height:' + 2 * 200 + ';width:'
+ + 2 * 300)
+ + '\"></div>')") ;";This line should start with a plus character.