1 ;;;; -*- encoding:utf-8 -*-
3 ;;; Copyright 2007 Red Daly
4 ;;; Copyright 2007 Vladimir Sedach
6 ;;; SPDX-License-Identifier: BSD-3-Clause
8 ;;; Redistribution and use in source and binary forms, with or
9 ;;; without modification, are permitted provided that the following
10 ;;; conditions are met:
12 ;;; 1. Redistributions of source code must retain the above copyright
13 ;;; notice, this list of conditions and the following disclaimer.
15 ;;; 2. Redistributions in binary form must reproduce the above
16 ;;; copyright notice, this list of conditions and the following
17 ;;; disclaimer in the documentation and/or other materials provided
18 ;;; with the distribution.
20 ;;; 3. Neither the name of the copyright holder nor the names of its
21 ;;; contributors may be used to endorse or promote products derived
22 ;;; from this software without specific prior written permission.
24 ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 ;;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 ;;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 ;;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 ;;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
29 ;;; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 ;;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
31 ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33 ;;; ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 ;;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 ;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 ;;; POSSIBILITY OF SUCH DAMAGE.
38 (in-package #:parenscript.tests
)
40 (fiveam:in-suite package-system-tests
)
42 (test-ps-js operator-packages1
46 (defpackage #:parenscript.tests.my-library
48 (setf (ps-package-prefix '#:parenscript.tests.my-library
)
51 (test-ps-js lib-function1
52 (defun parenscript.tests.my-library
::library-function
(x y
)
54 "function my_library_libraryFunction(x, y) {
58 (test-ps-js lib-function2
59 (defun parenscript.tests.my-library
::library-function
60 (parenscript.tests.my-library
::x
61 &key
((:y parenscript.tests.my-library
::z
) 1))
62 (+ parenscript.tests.my-library
::x parenscript.tests.my-library
::z
))
63 "function my_library_libraryFunction(my_library_x) {
64 var _js2 = arguments.length;
65 for (var n1 = 1; n1 < _js2; n1 += 2) {
66 switch (arguments[n1]) {
68 my_library_z = arguments[n1 + 1];
71 var my_library_z = 'undefined' === typeof my_library_z ? 1 : my_library_z;
73 return my_library_x + my_library_z;
76 (test-ps-js uniform-symbol-handling1
77 (progn (create parenscript.tests.my-library
::foo
1)
78 (getprop foo
'parenscript.tests.my-library
::foo
))
79 "{ my_library_foo : 1 };
82 (let ((map (make-hash-table)))
83 (defun symbol-obfuscator (symbol)
84 (or #1=(gethash symbol map
)
85 (setf #1# (make-symbol (map 'string
(lambda (x)
86 (code-char (1+ (char-code x
))))
87 (symbol-name symbol
)))))))
89 (defpackage #:parenscript.tests.obfuscate-me
)
90 (obfuscate-package '#:parenscript.tests.obfuscate-me
93 (test-ps-js obfuscation1
94 (defun parenscript.tests.obfuscate-me
::libfun2
(a b parenscript.tests.obfuscate-me
::foo
)
95 (+ a
(parenscript.tests.my-library
::library-function b parenscript.tests.obfuscate-me
::foo
)))
96 "function mjcgvo3(a, b, gpp) {
98 return a + my_library_libraryFunction(b, gpp);
101 (defpackage #:parenscript.tests.obfuscate-and-prefix
)
102 (obfuscate-package '#:parenscript.tests.obfuscate-and-prefix
#'symbol-obfuscator
)
103 (setf (ps-package-prefix '#:parenscript.tests.obfuscate-and-prefix
) "__FOO___")
105 (test-ps-js obfuscate-and-prefix
106 (defun parenscript.tests.obfuscate-and-prefix
::xfun
(a parenscript.tests.obfuscate-and-prefix
::b parenscript.tests.my-library
::d
)
108 (parenscript.tests.obfuscate-me
::libfun2 parenscript.tests.obfuscate-and-prefix
::b a
)
109 (parenscript.tests.my-library
::library-function parenscript.tests.my-library
::d parenscript.tests.obfuscate-and-prefix
::b
)))
110 "function __FOO___ygvo(a, __FOO___c, my_library_d) {
112 return a * mjcgvo3(__FOO___c, a) * my_library_libraryFunction(my_library_d, __FOO___c);
115 (defpackage #:parenscript.tests.pststpkg
116 (:use
#:parenscript
))
118 (setf (ps-package-prefix '#:parenscript.tests.pststpkg
) "prefix_")
120 (fiveam:test namespace1
()
122 (ps* 'parenscript.tests.pststpkg
::foo
)
125 (cl:in-package
#:parenscript.tests.pststpkg
)
127 (parenscript.tests
::test-ps-js namespace-and-special-forms
129 (let ((foo (create bar
1 not-a-keyword something
)))
130 (return-from foo
(and (not foo
) (+ (getprop foo
'bar
) some-other-var
)))))
131 "function prefix_foo() {
132 var foo1 = { prefix_bar : 1, prefix_notAKeyword : prefix_something };
133 return !foo1 && foo1.prefix_bar + prefix_someOtherVar;
136 (parenscript.tests
::test-ps-js exported-interface
137 (defun parenscript.tests
:interface-function
(baz)
138 (+ baz parenscript.tests.obfuscate-me
::foo
))
139 "function interfaceFunction(prefix_baz) {
140 return prefix_baz + gpp;
143 (parenscript.tests
::test-ps-js prefixed-symbol-macro-obj1
144 (symbol-macrolet ((x (+ 1 2)))
146 "{ prefix_x : 1 + 2 };")
148 (cl:in-package
#:parenscript.tests
)
150 (fiveam:test compile-stream-in-package
153 (with-input-from-string (s "
154 (defun parenscript.tests.obfuscate-and-prefix::xfun (a parenscript.tests.obfuscate-and-prefix::b parenscript.tests.my-library::d)
156 (parenscript.tests.obfuscate-me::libfun2 parenscript.tests.obfuscate-and-prefix::b a)
157 (parenscript.tests.my-library::library-function parenscript.tests.my-library::d parenscript.tests.obfuscate-and-prefix::b)))
159 (in-package #:parenscript.tests.pststpkg)
161 (defun parenscript.tests:interface-function (baz)
162 (+ baz parenscript.tests.obfuscate-me::foo))
164 (ps-compile-stream s
))
165 "function __FOO___ygvo(a, __FOO___c, my_library_d) {
167 return a * mjcgvo3(__FOO___c, a) * my_library_libraryFunction(my_library_d, __FOO___c);
169 function interfaceFunction(prefix_baz) {
170 return prefix_baz + gpp;