Commit | Line | Data |
---|---|---|
eb17f15c | 1 | (in-package :js-test) |
711dd89e | 2 | |
eb17f15c HH |
3 | ;; Testcases for parenscript |
4 | ||
5 | (defun trim-whitespace(str) | |
6 | (string-trim '(#\Space #\Tab #\Newline) str)) | |
7 | ||
7a7d6c73 HH |
8 | (defun same-space-between-statements(code) |
9 | (cl-ppcre:regex-replace-all "\\s*;\\s*" code (concatenate 'string (list #\; #\Newline)))) | |
10 | ||
11 | (defun no-indentation(code) | |
12 | (cl-ppcre:regex-replace-all (cl-ppcre:create-scanner "^\\s*" :multi-line-mode t) code "")) | |
13 | ||
14 | (defun no-trailing-spaces(code) | |
15 | (cl-ppcre:regex-replace-all (cl-ppcre:create-scanner "\\s*$" :multi-line-mode t) code "")) | |
16 | ||
17 | (defun normalize-js-code(str) | |
18 | (trim-whitespace (no-indentation (no-trailing-spaces (same-space-between-statements str))))) | |
19 | ||
eb17f15c HH |
20 | (defmacro test-ps-js (testname parenscript javascript) |
21 | `(test ,testname () | |
7a7d6c73 HH |
22 | (setf js::*var-counter* 0) |
23 | ;; is-macro expands its argument again when reporting failures, so | |
24 | ;; the reported temporary js-variables get wrong if we don't evalute first. | |
25 | (let ((generated-code (js-to-string ',parenscript)) | |
26 | (js-code ,javascript)) | |
27 | (is (string= (normalize-js-code generated-code) | |
94a05cdf | 28 | (normalize-js-code js-code)))))) |
eb17f15c HH |
29 | |
30 | (defun run-tests() | |
711dd89e HH |
31 | (format t "Running reference tests:~&") |
32 | (run! 'ref-tests) | |
33 | (format t "Running other tests:~&") | |
34 | (run! 'ps-tests)) | |
35 |