1 ;; SPDX-License-Identifier: BSD-3-Clause
3 (in-package #:parenscript.tests
)
5 (in-suite package-system-tests
)
7 (test-ps-js operator-packages1
11 (defpackage #:parenscript.tests.my-library
13 (setf (ps-package-prefix '#:parenscript.tests.my-library
) "my_library_")
15 (test-ps-js lib-function1
16 (defun parenscript.tests.my-library
::library-function
(x y
)
18 "function my_library_libraryFunction(x, y) {
22 (test-ps-js uniform-symbol-handling1
23 (progn (create parenscript.tests.my-library
::foo
1)
24 (getprop foo
'parenscript.tests.my-library
::foo
))
25 "({ my_library_foo : 1 });
28 (let ((map (make-hash-table)))
29 (defun symbol-obfuscator (symbol)
30 (or #1=(gethash symbol map
)
31 (setf #1# (make-symbol (map 'string
(lambda (x)
32 (code-char (1+ (char-code x
))))
33 (symbol-name symbol
)))))))
35 (defpackage #:parenscript.tests.obfuscate-me
)
36 (obfuscate-package '#:parenscript.tests.obfuscate-me
#'symbol-obfuscator
)
38 (test-ps-js obfuscation1
39 (defun parenscript.tests.obfuscate-me
::libfun2
(a b parenscript.tests.obfuscate-me
::foo
)
40 (+ a
(parenscript.tests.my-library
::library-function b parenscript.tests.obfuscate-me
::foo
)))
41 "function mjcgvo3(a, b, gpp) {
42 return a + my_library_libraryFunction(b, gpp);
45 (defpackage #:parenscript.tests.obfuscate-and-prefix
)
46 (obfuscate-package '#:parenscript.tests.obfuscate-and-prefix
#'symbol-obfuscator
)
47 (setf (ps-package-prefix '#:parenscript.tests.obfuscate-and-prefix
) "__FOO___")
49 (test-ps-js obfuscate-and-prefix
50 (defun parenscript.tests.obfuscate-and-prefix
::xfun
(a parenscript.tests.obfuscate-and-prefix
::b parenscript.tests.my-library
::d
)
52 (parenscript.tests.obfuscate-me
::libfun2 parenscript.tests.obfuscate-and-prefix
::b a
)
53 (parenscript.tests.my-library
::library-function parenscript.tests.my-library
::d parenscript.tests.obfuscate-and-prefix
::b
)))
54 "function __FOO___ygvo(a, __FOO___c, my_library_d) {
55 return a * mjcgvo3(__FOO___c, a) * my_library_libraryFunction(my_library_d, __FOO___c);
58 (defpackage #:parenscript.tests.pststpkg
61 (setf (ps-package-prefix '#:parenscript.tests.pststpkg
) "prefix_")
64 (is (string= "prefix_foo;" (normalize-js-code (ps* 'parenscript.tests.pststpkg
::foo
)))))
66 (cl:in-package
#:parenscript.tests.pststpkg
)
68 (parenscript.tests
::test-ps-js namespace-and-special-forms
70 (let ((foo (create bar
1 not-a-keyword something
)))
71 (return-from foo
(and (not foo
) (+ (getprop foo
'bar
) some-other-var
)))))
72 "function prefix_foo() {
73 var foo1 = { prefix_bar : 1, prefix_notAKeyword : prefix_something };
74 return !foo1 && foo1.prefix_bar + prefix_someOtherVar;
77 (parenscript.tests
::test-ps-js exported-interface
78 (defun parenscript.tests
:interface-function
(baz)
79 (+ baz parenscript.tests.obfuscate-me
::foo
))
80 "function interfaceFunction(prefix_baz) {
81 return prefix_baz + gpp;
84 (parenscript.tests
::test-ps-js prefixed-symbol-macro-obj1
85 (symbol-macrolet ((x (+ 1 2)))
87 "({ prefix_x : 1 + 2 });")
89 (cl:in-package
#:parenscript.tests
)
91 (test compile-stream-in-package
93 "function __FOO___ygvo(a, __FOO___c, my_library_d) {
94 return a * mjcgvo3(__FOO___c, a) * my_library_libraryFunction(my_library_d, __FOO___c);
96 function interfaceFunction(prefix_baz) {
97 return prefix_baz + gpp;
100 (with-input-from-string (s "
101 (defun parenscript.tests.obfuscate-and-prefix::xfun (a parenscript.tests.obfuscate-and-prefix::b parenscript.tests.my-library::d)
103 (parenscript.tests.obfuscate-me::libfun2 parenscript.tests.obfuscate-and-prefix::b a)
104 (parenscript.tests.my-library::library-function parenscript.tests.my-library::d parenscript.tests.obfuscate-and-prefix::b)))
106 (in-package #:parenscript.tests.pststpkg)
108 (defun parenscript.tests:interface-function (baz)
109 (+ baz parenscript.tests.obfuscate-me::foo))
111 (ps-compile-stream s
)))))