| 1 | (in-package "PARENSCRIPT-TEST") |
| 2 | |
| 3 | (eval-when (:compile-toplevel :load-toplevel :execute) |
| 4 | (def-suite package-system-tests)) |
| 5 | |
| 6 | (in-suite package-system-tests) |
| 7 | |
| 8 | (test-ps-js operator-packages1 |
| 9 | (#:new) |
| 10 | "new();") |
| 11 | |
| 12 | (defpackage "PS-TEST.MY-LIBRARY" |
| 13 | (:use "PARENSCRIPT")) |
| 14 | (setf (ps-package-prefix "PS-TEST.MY-LIBRARY") "my_library_") |
| 15 | |
| 16 | (test-ps-js lib-function1 |
| 17 | (defun ps-test.my-library::library-function (x y) |
| 18 | (return (+ x y))) |
| 19 | "function my_library_libraryFunction(x, y) { |
| 20 | return x + y; |
| 21 | };") |
| 22 | |
| 23 | (test-ps-js uniform-symbol-handling1 |
| 24 | (progn (create 'ps-test.my-library::foo 1) |
| 25 | (create ps-test.my-library::foo 1) |
| 26 | (slot-value foo 'ps-test.my-library::foo)) |
| 27 | "{ 'my_library_foo' : 1 }; |
| 28 | { my_library_foo : 1 }; |
| 29 | foo.my_library_foo;") |
| 30 | |
| 31 | (defpackage "PS-TEST.OBFUSCATE-ME") |
| 32 | (obfuscate-package "PS-TEST.OBFUSCATE-ME") |
| 33 | |
| 34 | (test-ps-js obfuscation1 |
| 35 | (defun ps-test.obfuscate-me::library-function2 (a b ps-test.obfuscate-me::foo) |
| 36 | (+ a (ps-test.my-library::library-function b ps-test.obfuscate-me::foo))) |
| 37 | "function g1(a, b, g2) { |
| 38 | a + my_library_libraryFunction(b, g2); |
| 39 | };") |
| 40 | |
| 41 | (defpackage "PS-TEST.OBFUSCATE-AND-PREFIX") |
| 42 | (obfuscate-package "PS-TEST.OBFUSCATE-AND-PREFIX") |
| 43 | (setf (ps-package-prefix "PS-TEST.OBFUSCATE-AND-PREFIX") "__FOO___") |
| 44 | |
| 45 | (test-ps-js obfuscate-and-prefix |
| 46 | (defun ps-test.obfuscate-and-prefix::some-function (a ps-test.obfuscate-and-prefix::b ps-test.my-library::d) |
| 47 | (* a |
| 48 | (ps-test.obfuscate-me::library-function2 ps-test.obfuscate-and-prefix::b a) |
| 49 | (ps-test.my-library::library-function ps-test.my-library::d ps-test.obfuscate-and-prefix::b))) |
| 50 | "function __FOO___g1(a, __FOO___g2, my_library_d) { |
| 51 | a * g1(__FOO___g2, a) * my_library_libraryFunction(my_library_d, __FOO___g2); |
| 52 | };") |
| 53 | |
| 54 | (defpackage "PS-TEST.PSTSTPKG" |
| 55 | (:use "PARENSCRIPT")) |
| 56 | |
| 57 | (test namespace1 () |
| 58 | (setf (ps-package-prefix "PS-TEST.PSTSTPKG") "prefix_") |
| 59 | (is (string= "prefix_foo;" (normalize-js-code (ps* 'ps-test.pststpkg::foo))))) |
| 60 | |
| 61 | (common-lisp:in-package "PS-TEST.PSTSTPKG") |
| 62 | |
| 63 | (ps-test::test-ps-js namespace-and-special-forms |
| 64 | (let ((foo (create bar 1 not-a-keyword something))) |
| 65 | (return (and (not foo) (+ (slot-value foo 'bar) some-other-var)))) |
| 66 | "var prefix_foo = { prefix_bar : 1, prefix_notAKeyword : prefix_something }; |
| 67 | return !prefix_foo && prefix_foo.prefix_bar + prefix_someOtherVar;") |