3 ;; Testcases for parenscript
5 (defun normalize-whitespace (str)
6 (substitute #\Space
#\Newline
(substitute #\Space
#\Tab str
)))
8 (defun same-space-between-statements(code)
9 (cl-ppcre:regex-replace-all
"\\s*;\\s*" code
"; "))
11 (defun remove-duplicate-spaces (str)
12 (labels ((spacep (char) (and char
(char= char
#\Space
)))
14 (cond ((null list
) nil
)
15 ((and (spacep (first list
)) (spacep (second list
))) (rds (cons #\Space
(cddr list
))))
16 (t (cons (car list
) (rds (cdr list
)))))))
17 (coerce (rds (coerce str
'list
)) 'string
)))
19 (defun trim-spaces (str)
20 (string-trim '(#\Space
) str
))
22 (defun remove-spaces-near-brackets (str)
23 (reduce (lambda (str rex-pair
) (cl-ppcre:regex-replace-all
(first rex-pair
) str
(second rex-pair
)))
24 (cons str
'(("\\[ " "[") (" \\]" "]") ("\\( " "(") (" \\)" ")")))))
26 (defun normalize-js-code (str)
27 (remove-spaces-near-brackets
29 (remove-duplicate-spaces
30 (same-space-between-statements
31 (normalize-whitespace str
))))))
33 (defmacro test-ps-js
(testname parenscript javascript
)
35 (setf js
::*var-counter
* 0)
36 ;; is-macro expands its argument again when reporting failures, so
37 ;; the reported temporary js-variables get wrong if we don't evalute first.
38 (let ((generated-code (js-to-string ',parenscript
))
39 (js-code ,javascript
))
40 (is (string= (normalize-js-code generated-code
)
41 (normalize-js-code js-code
))))))
44 (format t
"Running reference tests:~&")
46 (format t
"Running other tests:~&")