Verified Commit 2806eec2 authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Added ARRAYP, LISTP predicates

Thanks to Paul M. Rodriguez for the patch.
parent b2af98bf
...@@ -145,6 +145,15 @@ ...@@ -145,6 +145,15 @@
(defpsmacro booleanp (x) (defpsmacro booleanp (x)
`(string= (typeof ,x) "boolean")) `(string= (typeof ,x) "boolean"))
(defpsmacro listp (x)
(if (js-target-at-least "1.8.5")
`(funcall (getprop Array 'is-array) ,x)
`(string= (funcall (getprop Object 'prototype 'to-string 'call) ,x)
"[object Array]")))
(defpsmacro arrayp (x)
`(listp ,x))
;;; Data structures ;;; Data structures
(defpsmacro make-array (&rest args) (defpsmacro make-array (&rest args)
...@@ -1040,6 +1040,16 @@ ...@@ -1040,6 +1040,16 @@
(funcall (ps:getprop obj 'foo))) (funcall (ps:getprop obj 'foo)))
4) 4)
(test-js-eval arrayp1
(arrayp '(1 2 3))
:js-target-version "1.3")
(test-js-eval arrayp2
(arrayp '(1 2 3))
:js-target-version "1.8.5")
;;; Multiple value cases that are currently unimplemented ;;; Multiple value cases that are currently unimplemented
;; (test-js-eval multiple-value-call-twice ;; (test-js-eval multiple-value-call-twice
...@@ -56,19 +56,25 @@ ...@@ -56,19 +56,25 @@
((null x) :null) ((null x) :null)
(t x))) (t x)))
(defmacro %test-js-eval (testname parenscript test-statement) (defmacro %test-js-eval (testname parenscript test-statement
`(fiveam:test ,testname () `(fiveam:test ,testname ()
(cl-js:with-js-env () (cl-js:with-js-env ()
(let ((js-result (cl-js:run-js (ps-doc* ',parenscript)))) (let* ((*js-target-version* ,js-target-version)
(js-result (cl-js:run-js (ps-doc* ',parenscript))))
,test-statement)))) ,test-statement))))
(defmacro test-js-eval (testname parenscript expected) (defmacro test-js-eval (testname parenscript expected
&key (js-target-version *js-target-version*))
`(%test-js-eval ,testname ,parenscript `(%test-js-eval ,testname ,parenscript
(fiveam:is (equalp js-result (js-repr ,expected))))) (fiveam:is (equalp js-result (js-repr ,expected)))
(defmacro test-js-eval-epsilon (testname parenscript expected) (defmacro test-js-eval-epsilon (testname parenscript expected
&key (js-target-version *js-target-version*))
`(%test-js-eval ,testname ,parenscript `(%test-js-eval ,testname ,parenscript
(fiveam:is (< (abs (- js-result ,expected)) 0.0001)))) (fiveam:is (< (abs (- js-result ,expected)) 0.0001))
(fiveam:def-suite parenscript-tests) (fiveam:def-suite parenscript-tests)
(fiveam:def-suite output-tests :in parenscript-tests) (fiveam:def-suite output-tests :in parenscript-tests)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment