Fixed up bug where defuns were getting wrapped in lambdas because toplevel form check...
[parenscript.git] / t / package-system-tests.lisp
blobb659a2a97c70b9bfc4405f018988c0fe37738c41
1 ;; Copying and distribution of this file, with or without
2 ;; modification, are permitted in any medium without royalty. This
3 ;; file is offered as-is, without any warranty.
5 (in-package #:ps-test)
7 (in-suite package-system-tests)
9 (test-ps-js operator-packages1
10 (#:new)
11 "new();")
13 (defpackage #:ps-test.my-library
14 (:use #:parenscript))
15 (setf (ps-package-prefix '#:ps-test.my-library) "my_library_")
17 (test-ps-js lib-function1
18 (defun ps-test.my-library::library-function (x y)
19 (+ x y))
20 "function my_library_libraryFunction(x, y) {
21 return x + y;
22 };")
24 (test-ps-js uniform-symbol-handling1
25 (progn (create ps-test.my-library::foo 1)
26 (getprop foo 'ps-test.my-library::foo))
27 "({ my_library_foo : 1 });
28 foo.my_library_foo;")
30 (let ((map (make-hash-table)))
31 (defun symbol-obfuscator (symbol)
32 (or #1=(gethash symbol map)
33 (setf #1# (make-symbol (map 'string (lambda (x)
34 (code-char (1+ (char-code x))))
35 (symbol-name symbol)))))))
37 (defpackage #:ps-test.obfuscate-me)
38 (obfuscate-package '#:ps-test.obfuscate-me #'symbol-obfuscator)
40 (test-ps-js obfuscation1
41 (defun ps-test.obfuscate-me::libfun2 (a b ps-test.obfuscate-me::foo)
42 (+ a (ps-test.my-library::library-function b ps-test.obfuscate-me::foo)))
43 "function mjcgvo3(a, b, gpp) {
44 return a + my_library_libraryFunction(b, gpp);
45 };")
47 (defpackage #:ps-test.obfuscate-and-prefix)
48 (obfuscate-package '#:ps-test.obfuscate-and-prefix #'symbol-obfuscator)
49 (setf (ps-package-prefix '#:ps-test.obfuscate-and-prefix) "__FOO___")
51 (test-ps-js obfuscate-and-prefix
52 (defun ps-test.obfuscate-and-prefix::xfun (a ps-test.obfuscate-and-prefix::b ps-test.my-library::d)
53 (* a
54 (ps-test.obfuscate-me::libfun2 ps-test.obfuscate-and-prefix::b a)
55 (ps-test.my-library::library-function ps-test.my-library::d ps-test.obfuscate-and-prefix::b)))
56 "function __FOO___ygvo(a, __FOO___c, my_library_d) {
57 return a * mjcgvo3(__FOO___c, a) * my_library_libraryFunction(my_library_d, __FOO___c);
58 };")
60 (defpackage #:ps-test.pststpkg
61 (:use #:parenscript))
63 (setf (ps-package-prefix '#:ps-test.pststpkg) "prefix_")
65 (test namespace1 ()
66 (is (string= "prefix_foo;" (normalize-js-code (ps* 'ps-test.pststpkg::foo)))))
68 (cl:in-package #:ps-test.pststpkg)
70 (ps-test::test-ps-js namespace-and-special-forms
71 (defun foo ()
72 (let ((foo (create bar 1 not-a-keyword something)))
73 (return-from foo (and (not foo) (+ (getprop foo 'bar) some-other-var)))))
74 "function prefix_foo() {
75 var foo1 = { prefix_bar : 1, prefix_notAKeyword : prefix_something };
76 return !foo1 && foo1.prefix_bar + prefix_someOtherVar;
77 };")
79 (ps-test::test-ps-js exported-interface
80 (defun ps-test:interface-function (baz)
81 (+ baz ps-test.obfuscate-me::foo))
82 "function interfaceFunction(prefix_baz) {
83 return prefix_baz + gpp;
84 };")
86 (cl:in-package #:ps-test)
88 (test compile-stream-in-package
89 (is (string=
90 "function __FOO___ygvo(a, __FOO___c, my_library_d) {
91 return a * mjcgvo3(__FOO___c, a) * my_library_libraryFunction(my_library_d, __FOO___c);
93 function interfaceFunction(prefix_baz) {
94 return prefix_baz + gpp;
97 (with-input-from-string (s "
98 (defun ps-test.obfuscate-and-prefix::xfun (a ps-test.obfuscate-and-prefix::b ps-test.my-library::d)
99 (* a
100 (ps-test.obfuscate-me::libfun2 ps-test.obfuscate-and-prefix::b a)
101 (ps-test.my-library::library-function ps-test.my-library::d ps-test.obfuscate-and-prefix::b)))
103 (in-package #:ps-test.pststpkg)
105 (defun ps-test:interface-function (baz)
106 (+ baz ps-test.obfuscate-me::foo))
108 (ps-compile-stream s)))))