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
()
45 (string= (normalize-js-output ,javascript
)
47 (let ((*js-target-version
* ,js-target-version
))
48 (ps-doc* ',parenscript
)))))))
51 (cond ((or (consp x
) (simple-vector-p x
))
53 (make-array (length x
)
54 :initial-contents
(map 'vector
#'js-repr x
)
59 (defmacro %test-js-eval
(testname parenscript test-statement
61 `(fiveam:test
,testname
()
63 (let* ((*js-target-version
* ,js-target-version
)
64 (js-result (cl-js:run-js
(ps-doc* ',parenscript
))))
67 (defmacro test-js-eval
(testname parenscript expected
68 &key
(js-target-version *js-target-version
*))
69 `(%test-js-eval
,testname
,parenscript
70 (fiveam:is
(equalp js-result
(js-repr ,expected
)))
73 (defmacro test-js-eval-epsilon
(testname parenscript expected
74 &key
(js-target-version *js-target-version
*))
75 `(%test-js-eval
,testname
,parenscript
76 (fiveam:is
(< (abs (- js-result
,expected
)) 0.0001))
79 (fiveam:def-suite parenscript-tests
)
80 (fiveam:def-suite output-tests
:in parenscript-tests
)
81 (fiveam:def-suite package-system-tests
:in parenscript-tests
)
82 (fiveam:def-suite eval-tests
:in parenscript-tests
)
85 (let ((*js-string-delimiter
* #\'))
86 (fiveam:run
! 'parenscript-tests
)))