method trick was yanked in 79630c82ac03066ceb1dac50015eb6b7a2151bbe but the documenta...
[clinton/parenscript.git] / t / package-system-tests.lisp
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 (defpackage "PS-TEST.OBFUSCATE-ME")
24 (obfuscate-package "PS-TEST.OBFUSCATE-ME")
25
26 (test-ps-js obfuscation1
27 (defun ps-test.obfuscate-me::library-function2 (a b ps-test.obfuscate-me::foo)
28 (+ a (ps-test.my-library::library-function b ps-test.obfuscate-me::foo)))
29 "function g1(a, b, g2) {
30 a + my_library_libraryFunction(b, g2);
31 }")
32
33 (defpackage "PS-TEST.OBFUSCATE-AND-PREFIX")
34 (obfuscate-package "PS-TEST.OBFUSCATE-AND-PREFIX")
35 (setf (ps-package-prefix "PS-TEST.OBFUSCATE-AND-PREFIX") "__FOO___")
36
37 (test-ps-js obfuscate-and-prefix
38 (defun ps-test.obfuscate-and-prefix::some-function (a ps-test.obfuscate-and-prefix::b ps-test.my-library::d)
39 (* a
40 (ps-test.obfuscate-me::library-function2 ps-test.obfuscate-and-prefix::b a)
41 (ps-test.my-library::library-function ps-test.my-library::d ps-test.obfuscate-and-prefix::b)))
42 "function __FOO___g1(a, __FOO___g2, my_library_d) {
43 a * g1(__FOO___g2, a) * my_library_libraryFunction(my_library_d, __FOO___g2);
44 }")
45
46 (defpackage "PS-TEST.PSTSTPKG"
47 (:use "PARENSCRIPT"))
48
49 (test namespace1 ()
50 (setf (ps-package-prefix "PS-TEST.PSTSTPKG") "prefix_")
51 (is (string= "prefix_foo;" (normalize-js-code (ps* 'ps-test.pststpkg::foo)))))
52
53 (common-lisp:in-package "PS-TEST.PSTSTPKG")
54
55 (ps-test::test-ps-js namespace-and-special-forms
56 (let* ((foo (create :bar 1 not-a-keyword something)))
57 (return (and (not foo) (+ (slot-value foo bar) some-other-var))))
58 " var prefix_foo =
59 { bar : 1,
60 prefix_notAKeyword : prefix_something };
61 return !prefix_foo && prefix_foo[prefix_bar] + prefix_someOtherVar;")