Whitespaceification: removed indentation tabs throughout project.
[clinton/parenscript.git] / t / test.lisp
CommitLineData
171bbab3 1(in-package :ps-test)
711dd89e 2
cf460f93
VS
3(defun normalize-whitespace (str)
4 (substitute #\Space #\Newline (substitute #\Space #\Tab str)))
a9dd0664 5
7a7d6c73 6(defun same-space-between-statements(code)
a9dd0664
VS
7 (let ((cl-ppcre:*use-bmh-matchers* nil)) ;; disable Booyer Moore string matching algorithm, which doesn't work very well on unicode lisps
8 (cl-ppcre:regex-replace-all "\\s*;\\s*" code "; ")))
9
cf460f93
VS
10(defun remove-duplicate-spaces (str)
11 (labels ((spacep (char) (and char (char= char #\Space)))
12 (rds (list)
13 (cond ((null list) nil)
14 ((and (spacep (first list)) (spacep (second list))) (rds (cons #\Space (cddr list))))
15 (t (cons (car list) (rds (cdr list)))))))
16 (coerce (rds (coerce str 'list)) 'string)))
a9dd0664 17
cf460f93
VS
18(defun trim-spaces (str)
19 (string-trim '(#\Space) str))
a9dd0664 20
cf460f93 21(defun remove-spaces-near-brackets (str)
a9dd0664
VS
22 (let ((cl-ppcre:*use-bmh-matchers* nil)) ;; disable Booyer Moore string matching algorithm, which doesn't work very well on unicode lisps
23 (reduce (lambda (str rex-pair) (cl-ppcre:regex-replace-all (first rex-pair) str (second rex-pair)))
24 (cons str '(("\\[ " "[") (" \\]" "]") ("\\( " "(") (" \\)" ")"))))))
25
cf460f93
VS
26(defun normalize-js-code (str)
27 (remove-spaces-near-brackets
28 (trim-spaces
29 (remove-duplicate-spaces
30 (same-space-between-statements
31 (normalize-whitespace str))))))
7a7d6c73 32
eb17f15c 33(defmacro test-ps-js (testname parenscript javascript)
5aa10005 34 (let (
b508414b
TC
35 ;; (parenscript
36 ;; `(progn
37 ;; (defpackage parenscript-test
38 ;; (:lisp-package :parenscript-test))
39 ;; ,parenscript)))
40 )
a9dd0664 41 `(test ,testname ()
07afea38 42 (setf ps:*ps-gensym-counter* 0)
5aa10005 43
a9dd0664
VS
44 ;; is-macro expands its argument again when reporting failures, so
45 ;; the reported temporary js-variables get wrong if we don't evalute first.
905f534e 46 (let* ((generated-code (compile-script ',parenscript))
a9dd0664
VS
47 (js-code ,javascript))
48 (is (string= (normalize-js-code generated-code)
49 (normalize-js-code js-code)))))))
5aa10005 50
905f534e 51(defmacro defpstest (testname (&key (optimize t)) parenscript javascript)
5aa10005 52 `(test ,testname
07afea38 53 (setf ps:*ps-gensym-counter* 0)
905f534e 54 (let* ((generated-code (compile-script ',parenscript))
a9dd0664 55 (js-code ,javascript))
7a7d6c73 56 (is (string= (normalize-js-code generated-code)
94a05cdf 57 (normalize-js-code js-code))))))
eb17f15c
HH
58
59(defun run-tests()
711dd89e
HH
60 (format t "Running reference tests:~&")
61 (run! 'ref-tests)
62 (format t "Running other tests:~&")
5aa10005
RD
63 (run! 'ps-tests)
64 (format t "Running Package System tests:~&")
65 (run! 'package-system-tests))
711dd89e 66