(#:new)
"new()")
-(defpackage "MY-LIBRARY"
- (:use #:parenscript))
-(setf (ps-package-prefix :my-library) "my_library_")
+(defpackage "PS-TEST.MY-LIBRARY"
+ (:use "PARENSCRIPT"))
+(setf (ps-package-prefix "PS-TEST.MY-LIBRARY") "my_library_")
(test-ps-js lib-function1
- (defun my-library::library-function (x y)
+ (defun ps-test.my-library::library-function (x y)
(return (+ x y)))
"function my_library_libraryFunction(x, y) {
return x + y;
}")
-(defpackage "OBFUSCATE-ME")
-(obfuscate-package :obfuscate-me)
+(defpackage "PS-TEST.OBFUSCATE-ME")
+(obfuscate-package "PS-TEST.OBFUSCATE-ME")
(test-ps-js obfuscation1
- (defun obfuscate-me::library-function2 (a b obfuscate-me::foo)
- (+ a (my-library::library-function b obfuscate-me::foo)))
+ (defun ps-test.obfuscate-me::library-function2 (a b ps-test.obfuscate-me::foo)
+ (+ a (ps-test.my-library::library-function b ps-test.obfuscate-me::foo)))
"function g2(a, b, g3) {
a + my_library_libraryFunction(b, g3);
}")
-(defpackage "OBFUSCATE-AND-PREFIX")
-(obfuscate-package "OBFUSCATE-AND-PREFIX")
-(setf (ps-package-prefix "OBFUSCATE-AND-PREFIX") "__FOO___")
+(defpackage "PS-TEST.OBFUSCATE-AND-PREFIX")
+(obfuscate-package "PS-TEST.OBFUSCATE-AND-PREFIX")
+(setf (ps-package-prefix "PS-TEST.OBFUSCATE-AND-PREFIX") "__FOO___")
(test-ps-js obfuscate-and-prefix
- (defun obfuscate-and-prefix::some-function (a obfuscate-and-prefix::b my-library::d)
+ (defun ps-test.obfuscate-and-prefix::some-function (a ps-test.obfuscate-and-prefix::b ps-test.my-library::d)
(* a
- (obfuscate-me::library-function2 obfuscate-and-prefix::b a)
- (my-library::library-function my-library::d obfuscate-and-prefix::b)))
+ (ps-test.obfuscate-me::library-function2 ps-test.obfuscate-and-prefix::b a)
+ (ps-test.my-library::library-function ps-test.my-library::d ps-test.obfuscate-and-prefix::b)))
"function __FOO___g2(a, __FOO___g3, my_library_d) {
a * g2(__FOO___g3, a) * my_library_libraryFunction(my_library_d, __FOO___g3);
}")
-(defpackage "PSTSTPKG"
- (:use #:parenscript))
+(defpackage "PS-TEST.PSTSTPKG"
+ (:use "PARENSCRIPT"))
(test namespace1 ()
- (setf (ps-package-prefix "PSTSTPKG") "prefix_")
- (is (string= "prefix_foo;" (normalize-js-code (ps* 'pststpkg::foo)))))
+ (setf (ps-package-prefix "PS-TEST.PSTSTPKG") "prefix_")
+ (is (string= "prefix_foo;" (normalize-js-code (ps* 'ps-test.pststpkg::foo)))))
-(common-lisp:in-package "PSTSTPKG")
+(common-lisp:in-package "PS-TEST.PSTSTPKG")
(ps-test::test-ps-js namespace-and-special-forms
(let* ((foo (create :bar 1 not-a-keyword something)))
'nil
"null")
-(test defsetf1
- (ps (defsetf baz (x y) (newval) `(set-baz ,x ,y ,newval)))
- (is (string= "var _js2 = 1; var _js3 = 2; var _js1 = 3; setBaz(_js2, _js3, _js1);"
- (normalize-js-code (let* ((ps:*ps-gensym-counter* 0))
- (ps (setf (baz 1 2) 3)))))))
-
-(test defsetf-short
- (ps (defsetf baz set-baz "blah"))
- (is (string= "setBaz(1, 2, 3, 'foo');" (normalize-js-code (ps (setf (baz 1 2 3) "foo"))))))
-
-(test defun-setf1
- (is (and (string= (normalize-js-code (ps:ps (defun (setf some-thing) (new-val i1 i2)
- (setf (aref *some-thing* i1 i2) new-val))))
- "function __setf_someThing(newVal, i1, i2) { SOMETHING[i1][i2] = newVal; };")
- (string= (normalize-js-code (ps:ps-doc (setf (some-thing 1 2) "foo")))
- "var _js2 = 1; var _js3 = 2; var _js1 = 'foo'; __setf_someThing(_js1, _js2, _js3);"))))
+(test-ps-js defsetf1
+ (progn (defsetf baz (x y) (newval) `(set-baz ,x ,y ,newval))
+ (setf (baz 1 2) 3))
+ "var _js2 = 1; var _js3 = 2; var _js1 = 3; setBaz(_js2, _js3, _js1);")
+
+(test-ps-js defsetf-short
+ (progn (defsetf baz set-baz "docstring")
+ (setf (baz 1 2 3) "foo"))
+ "setBaz(1, 2, 3, 'foo');")
+
+(test-ps-js defun-setf1
+ (progn (defun (setf some-thing) (new-val i1 i2)
+ (setf (aref *some-thing* i1 i2) new-val))
+ (setf (some-thing 1 2) "foo"))
+ "function __setf_someThing(newVal, i1, i2) {
+ SOMETHING[i1][i2] = newVal;
+};
+var _js3 = 1;
+var _js4 = 2;
+var _js2 = 'foo';
+__setf_someThing(_js2, _js3, _js4);")
(test-ps-js defun-optional1
(defun test-opt (&optional x) (return (if x "yes" "no")))
-(in-package :ps-test)
+(in-package "PS-TEST")
(defun normalize-whitespace (str)
(substitute #\Space #\Newline (substitute #\Space #\Tab str)))
-(defun same-space-between-statements(code)
- (let ((cl-ppcre:*use-bmh-matchers* nil)) ;; disable Booyer Moore string matching algorithm, which doesn't work very well on unicode lisps
+(defun same-space-between-statements (code)
+ (let ((cl-ppcre:*use-bmh-matchers* nil))
(cl-ppcre:regex-replace-all "\\s*;\\s*" code "; ")))
(defun remove-duplicate-spaces (str)
(string-trim '(#\Space) str))
(defun remove-spaces-near-brackets (str)
- (let ((cl-ppcre:*use-bmh-matchers* nil)) ;; disable Booyer Moore string matching algorithm, which doesn't work very well on unicode lisps
+ (let ((cl-ppcre:*use-bmh-matchers* nil))
(reduce (lambda (str rex-pair) (cl-ppcre:regex-replace-all (first rex-pair) str (second rex-pair)))
(cons str '(("\\[ " "[") (" \\]" "]") ("\\( " "(") (" \\)" ")"))))))
(normalize-whitespace str))))))
(defmacro test-ps-js (testname parenscript javascript)
- (let (
- ;; (parenscript
- ;; `(progn
- ;; (defpackage parenscript-test
- ;; (:lisp-package :parenscript-test))
- ;; ,parenscript)))
- )
- `(test ,testname ()
- (setf ps:*ps-gensym-counter* 0)
-
- ;; is-macro expands its argument again when reporting failures, so
- ;; the reported temporary js-variables get wrong if we don't evalute first.
- (let* ((generated-code (ps1* ',parenscript))
- (js-code ,javascript))
- (is (string= (normalize-js-code generated-code)
- (normalize-js-code js-code)))))))
-
-(defmacro defpstest (testname (&key (optimize t)) parenscript javascript)
- (declare (ignore optimize))
- `(test ,testname
- (setf ps:*ps-gensym-counter* 0)
- (let* ((generated-code (ps1* ',parenscript))
- (js-code ,javascript))
- (is (string= (normalize-js-code generated-code)
- (normalize-js-code js-code))))))
+ `(test ,testname ()
+ (is (string= (normalize-js-code (ps-doc* ',parenscript))
+ (normalize-js-code ,javascript)))))
(defun run-tests()
(format t "Running reference tests:~&")