2 ;; Other tests not in the reference
4 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
8 (test-ps-js plus-is-not-commutative
9 (setf x
(+ "before" x
"after"))
10 "x = 'before' + x + 'after'")
12 (test-ps-js plus-works-if-first
13 (setf x
(+ x
"middle" "after"))
14 "x += 'middle' + 'after'")
16 (test-ps-js setf-side-effects
22 (setf x
(+ 2 (side-effect) x
5))))
25 function sideEffect() {
29 x = 2 + sideEffect() + x + 5;")
30 ;; Parenscript used to optimize to much:
32 ;; function sideEffect() {
36 ;; x += 2 + sideEffect() + 5;
38 ;; Which is 20, not 14
41 (test-ps-js dot-notation-bug
42 (.match
(+ "" x
) "foo")
43 "('' + x).match('foo')")
45 (test-ps-js method-call-op-form
(.to-string
(+ "" x
)) "('' + x).toString()")
46 (test-ps-js method-call-number
(.to-string
10) "( 10 ).toString()")
47 (test-ps-js method-call-string
(.to-string
"hi") "'hi'.toString()")
48 (test-ps-js method-call-lit-object
49 (.to-string
(create :to-string
(lambda ()
50 (return "it works"))))
51 "( { toString : function () { return 'it works'; } } ).toString()")
53 (test-ps-js method-call-variable
57 (test-ps-js method-call-array
58 (.to-string
(list 10 20))
59 "[ 10, 20 ].toString()")
60 (test-ps-js method-call-fn-call
63 (test-ps-js method-call-lambda-fn
64 (.to-string
(lambda () (alert 10)))
65 "( function () { alert(10); } ).toString()")
66 (test-ps-js method-call-lambda-call
67 (.to-string
((lambda (x) (return x
)) 10))
68 "(function (x) { return x; }) (10).toString()")
70 (test no-whitespace-before-dot
71 (let* ((parenscript::*enable-package-system
* nil
)
72 (str (compile-script '(.to-string
((lambda (x) (return x
)) 10))))
73 (dot-pos (position #\. str
:test
#'char
=))
74 (char-before (elt str
(1- dot-pos
)))
76 (is (char= char-before a-parenthesis
))))
78 ;; A problem with long nested operator, when the statement spanned several rows
79 ;; the rows would not be joined together correctly.
80 (test-ps-js bug-dwim-join
81 (alert (html ((:div
:id
777
82 :style
(css-inline :border
"1pxsssssssssss"
87 ('<div id=\"777\" style=\"'
88 + ('border:1pxsssssssssss;font-size:x-small;height:' + 2 * 200 + ';width:'
90 + '\"></div>')") ;";This line should start with a plus character.
93 (test-ps-js simple-slot-value
94 (let ((foo (create :a
1)))
95 (alert (slot-value foo
'a
)))
101 (test-ps-js buggy-slot-value
102 (let ((foo (create :a
1))
104 (alert (slot-value foo slot-name
)))
108 alert(foo[slotName]);
109 }"); Last line was alert(foo.slotName) before bug-fix.
111 (test-ps-js buggy-slot-value-two
112 (slot-value foo
(get-slot-name))
113 "foo[getSlotName()]")
115 (test-ps-js old-case-is-now-switch
116 ;; Switch was "case" before, but that was very non-lispish.
117 ;; For example, this code makes three messages and not one
118 ;; which may have been expected. This is because a switch
119 ;; statment must have a break statement for it to return
120 ;; after the alert. Otherwise it continues on the next
122 (switch (aref blorg i
)
125 (default (alert "default clause")))
127 case 1: alert('one');
128 case 2: alert('two');
129 default: alert('default clause');
132 (test-ps-js lisp-like-case
136 (default (alert "default clause")))
144 default: alert('default clause');
148 (test-ps-js even-lispier-case
150 ((1 2) (alert "Below three"))
152 (t (alert "Something else")))
156 alert('Below three');
161 default: alert('Something else');
164 (test-ps-js otherwise-case
167 (otherwise (alert "default clause")))
172 default: alert('default clause');
175 (test escape-sequences-in-string
176 (let ((parenscript::*enable-package-system
* nil
)
177 (escapes `((#\\ .
#\\)
179 (#\f .
,(code-char 12))
180 ("u000B" .
,(code-char #x000b
));;Vertical tab, too uncommon to bother with
183 (#\' .
#\');;Double quote need not be quoted because parenscript strings are single quoted
185 ("u001F" .
,(code-char #x001f
));; character below 32
186 ("u0080" .
,(code-char 128)) ;;Character over 127. Actually valid, parenscript escapes them to be sure.
187 ("uABCD" .
,(code-char #xabcd
)))));; Really above ascii.
188 (loop for
(js-escape . lisp-char
) in escapes
189 for generated
= (compile-script `(let ((x , (format nil
"hello~ahi" lisp-char
)))))
190 for wanted
= (format nil
"{
191 var x = 'hello\\~ahi';
193 do
(is (string= generated wanted
)))))
195 (test-ps-js complicated-symbol-name1
199 (test-ps-js complicated-symbol-name2
203 (test-ps-js slot-value-setf
204 (setf (slot-value x 'y) (+ (+ a 3) 4))
207 (test-ps-js slot-value-conditional1
208 (slot-value (if zoo foo bar) 'x)
209 "(zoo ? foo : bar).x")
211 (test-ps-js slot-value-conditional2
212 (slot-value (if (not zoo) foo bar) 'x)
213 "(!zoo ? foo : bar).x")