Misc. formatting changes
[parenscript.git] / tests / test.lisp
blob07d6cbfd10f38518cedc1b3ad21a34895ce88ad7
1 ;;; Copyright 2005-2006 Henrik Hjelte
2 ;;; Copyright 2007-2012 Vladimir Sedach
4 ;;; SPDX-License-Identifier: BSD-3-Clause
6 ;;; Redistribution and use in source and binary forms, with or
7 ;;; without modification, are permitted provided that the following
8 ;;; conditions are met:
10 ;;; 1. Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
13 ;;; 2. Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials provided
16 ;;; with the distribution.
18 ;;; 3. Neither the name of the copyright holder nor the names of its
19 ;;; contributors may be used to endorse or promote products derived
20 ;;; from this software without specific prior written permission.
22 ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 ;;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 ;;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 ;;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 ;;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
27 ;;; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 ;;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 ;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 ;;; ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 ;;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 ;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 ;;; POSSIBILITY OF SUCH DAMAGE.
36 (in-package #:parenscript.tests)
38 (defun normalize-js-output (str)
39 (cl-ppcre:regex-replace-all "\\s+" str " "))
41 (defmacro test-ps-js (testname parenscript javascript
42 &key (js-target-version *js-target-version*))
43 `(fiveam:test ,testname ()
44 (fiveam:is
45 (string= (normalize-js-output ,javascript)
46 (normalize-js-output
47 (let ((*js-target-version* ,js-target-version))
48 (ps-doc* ',parenscript)))))))
50 (defun js-repr (x)
51 (if (listp x)
52 (cl-js:js-array
53 (make-array (length x)
54 :initial-contents (mapcar #'js-repr x)
55 :adjustable t))
56 x))
58 (defmacro %test-js-eval (testname parenscript test-statement)
59 `(fiveam:test ,testname ()
60 (cl-js:with-js-env ()
61 (let ((js-result (cl-js:run-js (ps-doc* ',parenscript))))
62 ,test-statement))))
64 (defmacro test-js-eval (testname parenscript expected)
65 `(%test-js-eval ,testname ,parenscript
66 (fiveam:is (equalp js-result (js-repr ,expected)))))
68 (defmacro test-js-eval-epsilon (testname parenscript expected)
69 `(%test-js-eval ,testname ,parenscript
70 (fiveam:is (< (abs (- js-result ,expected)) 0.0001))))
72 (fiveam:def-suite parenscript-tests)
73 (fiveam:def-suite output-tests :in parenscript-tests)
74 (fiveam:def-suite package-system-tests :in parenscript-tests)
75 (fiveam:def-suite eval-tests :in parenscript-tests)
77 (defun run-tests ()
78 (let ((*js-string-delimiter* #\'))
79 (fiveam:run! 'parenscript-tests)))