mfmediaengine: Remove unnecessary import library.
[wine.git] / dlls / vbscript / tests / lang.vbs
blobf147351b1af975f76e91e5747758542792070804
2 ' Copyright 2011 Jacek Caban for CodeWeavers
4 ' This library is free software; you can redistribute it and/or
5 ' modify it under the terms of the GNU Lesser General Public
6 ' License as published by the Free Software Foundation; either
7 ' version 2.1 of the License, or (at your option) any later version.
9 ' This library is distributed in the hope that it will be useful,
10 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ' Lesser General Public License for more details.
14 ' You should have received a copy of the GNU Lesser General Public
15 ' License along with this library; if not, write to the Free Software
16 ' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 OPTION EXPLICIT : : DIM W
21 dim x, y, z, e
22 Dim obj
24 call ok(true, "true is not true?")
25 ok true, "true is not true?"
26 call ok((true), "true is not true?")
28 ok not false, "not false but not true?"
29 ok not not true, "not not true but not true?"
31 Call ok(true = true, "true = true is false")
32 Call ok(false = false, "false = false is false")
33 Call ok(not (true = false), "true = false is true")
34 Call ok("x" = "x", """x"" = ""x"" is false")
35 Call ok(empty = empty, "empty = empty is false")
36 Call ok(empty = "", "empty = """" is false")
37 Call ok(0 = 0.0, "0 <> 0.0")
38 Call ok(16 = &h10&, "16 <> &h10&")
39 Call ok(010 = 10, "010 <> 10")
40 Call ok(10. = 10, "10. <> 10")
41 Call ok(&hffFFffFF& = -1, "&hffFFffFF& <> -1")
42 Call ok(&hffFFffFF& = -1, "&hffFFffFF& <> -1")
43 Call ok(34e5 = 3400000, "34e5 <> 3400000")
44 Call ok(34e+5 = 3400000, "34e+5 <> 3400000")
45 Call ok(56.789e5 = 5678900, "56.789e5 = 5678900")
46 Call ok(56.789e-2 = 0.56789, "56.789e-2 <> 0.56789")
47 Call ok(1e-94938484 = 0, "1e-... <> 0")
48 Call ok(34e0 = 34, "34e0 <> 34")
49 Call ok(34E1 = 340, "34E0 <> 340")
50 Call ok(.5 = 0.5, ".5 <> 0.5")
51 Call ok(.5e1 = 5, ".5e1 <> 5")
52 Call ok(--1 = 1, "--1 = " & --1)
53 Call ok(-empty = 0, "-empty = " & (-empty))
54 Call ok(true = -1, "! true = -1")
55 Call ok(false = 0, "false <> 0")
56 Call ok(&hff = 255, "&hff <> 255")
57 Call ok(&Hff = 255, "&Hff <> 255")
58 Call ok(&hffff = -1, "&hffff <> -1")
59 Call ok(&hfffe = -2, "&hfffe <> -2")
60 Call ok(&hffff& = 65535, "&hffff& <> -1")
61 Call ok(&hfffe& = 65534, "&hfffe& <> -2")
62 Call ok(&hffffffff& = -1, "&hffffffff& <> -1")
63 Call ok((&h01or&h02)=3,"&h01or&h02 <> 3")
65 W = 5
66 Call ok(W = 5, "W = " & W & " expected " & 5)
68 x = "xx"
69 Call ok(x = "xx", "x = " & x & " expected ""xx""")
71 Dim public1 : public1 = 42
72 Call ok(public1 = 42, "public1=" & public1 & " expected & " & 42)
73 Private priv1 : priv1 = 43
74 Call ok(priv1 = 43, "priv1=" & priv1 & " expected & " & 43)
75 Public pub1 : pub1 = 44
76 Call ok(pub1 = 44, "pub1=" & pub1 & " expected & " & 44)
78 Call ok(true <> false, "true <> false is false")
79 Call ok(not (true <> true), "true <> true is true")
80 Call ok(not ("x" <> "x"), """x"" <> ""x"" is true")
81 Call ok(not (empty <> empty), "empty <> empty is true")
82 Call ok(x <> "x", "x = ""x""")
83 Call ok("true" <> true, """true"" = true is true")
85 Call ok("" = true = false, """"" = true = false is false")
86 Call ok(not(false = true = ""), "false = true = """" is true")
87 Call ok(not (false = false <> false = false), "false = false <> false = false is true")
88 Call ok(not ("" <> false = false), """"" <> false = false is true")
90 Call ok(getVT(false) = "VT_BOOL", "getVT(false) is not VT_BOOL")
91 Call ok(getVT(true) = "VT_BOOL", "getVT(true) is not VT_BOOL")
92 Call ok(getVT("") = "VT_BSTR", "getVT("""") is not VT_BSTR")
93 Call ok(getVT("test") = "VT_BSTR", "getVT(""test"") is not VT_BSTR")
94 Call ok(getVT(Empty) = "VT_EMPTY", "getVT(Empty) is not VT_EMPTY")
95 Call ok(getVT(null) = "VT_NULL", "getVT(null) is not VT_NULL")
96 Call ok(getVT(0) = "VT_I2", "getVT(0) is not VT_I2")
97 Call ok(getVT(1) = "VT_I2", "getVT(1) is not VT_I2")
98 Call ok(getVT(0.5) = "VT_R8", "getVT(0.5) is not VT_R8")
99 Call ok(getVT(.5) = "VT_R8", "getVT(.5) is not VT_R8")
100 Call ok(getVT(0.0) = "VT_R8", "getVT(0.0) is not VT_R8")
101 Call ok(getVT(2147483647) = "VT_I4", "getVT(2147483647) is not VT_I4")
102 Call ok(getVT(2147483648) = "VT_R8", "getVT(2147483648) is not VT_R8")
103 Call ok(getVT(&h10&) = "VT_I2", "getVT(&h10&) is not VT_I2")
104 Call ok(getVT(&h10000&) = "VT_I4", "getVT(&h10000&) is not VT_I4")
105 Call ok(getVT(&H10000&) = "VT_I4", "getVT(&H10000&) is not VT_I4")
106 Call ok(getVT(&hffFFffFF&) = "VT_I2", "getVT(&hffFFffFF&) is not VT_I2")
107 Call ok(getVT(&hffFFffFE&) = "VT_I2", "getVT(&hffFFffFE &) is not VT_I2")
108 Call ok(getVT(&hffF&) = "VT_I2", "getVT(&hffFF&) is not VT_I2")
109 Call ok(getVT(&hffFF&) = "VT_I4", "getVT(&hffFF&) is not VT_I4")
110 Call ok(getVT(# 1/1/2011 #) = "VT_DATE", "getVT(# 1/1/2011 #) is not VT_DATE")
111 Call ok(getVT(1e2) = "VT_R8", "getVT(1e2) is not VT_R8")
112 Call ok(getVT(1e0) = "VT_R8", "getVT(1e0) is not VT_R8")
113 Call ok(getVT(0.1e2) = "VT_R8", "getVT(0.1e2) is not VT_R8")
114 Call ok(getVT(1 & 100000) = "VT_BSTR", "getVT(1 & 100000) is not VT_BSTR")
115 Call ok(getVT(-empty) = "VT_I2", "getVT(-empty) = " & getVT(-empty))
116 Call ok(getVT(-null) = "VT_NULL", "getVT(-null) = " & getVT(-null))
117 Call ok(getVT(y) = "VT_EMPTY*", "getVT(y) = " & getVT(y))
118 Call ok(getVT(nothing) = "VT_DISPATCH", "getVT(nothing) = " & getVT(nothing))
119 set x = nothing
120 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=nothing) = " & getVT(x))
121 x = true
122 Call ok(getVT(x) = "VT_BOOL*", "getVT(x) = " & getVT(x))
123 Call ok(getVT(false or true) = "VT_BOOL", "getVT(false) is not VT_BOOL")
124 x = "x"
125 Call ok(getVT(x) = "VT_BSTR*", "getVT(x) is not VT_BSTR*")
126 x = 0.0
127 Call ok(getVT(x) = "VT_R8*", "getVT(x) = " & getVT(x))
129 Call ok(isNullDisp(nothing), "nothing is not nulldisp?")
131 x = "xx"
132 Call ok("ab" & "cd" = "abcd", """ab"" & ""cd"" <> ""abcd""")
133 Call ok("ab " & null = "ab ", """ab"" & null = " & ("ab " & null))
134 Call ok("ab " & empty = "ab ", """ab"" & empty = " & ("ab " & empty))
135 Call ok(1 & 100000 = "1100000", "1 & 100000 = " & (1 & 100000))
136 Call ok("ab" & x = "abxx", """ab"" & x = " & ("ab"&x))
138 if(isEnglishLang) then
139 Call ok("" & true = "True", """"" & true = " & true)
140 Call ok(true & false = "TrueFalse", "true & false = " & (true & false))
141 end if
143 call ok(true and true, "true and true is not true")
144 call ok(true and not false, "true and not false is not true")
145 call ok(not (false and true), "not (false and true) is not true")
146 call ok(getVT(null and true) = "VT_NULL", "getVT(null and true) = " & getVT(null and true))
148 call ok(false or true, "false or uie is false?")
149 call ok(not (false or false), "false or false is not false?")
150 call ok(false and false or true, "false and false or true is false?")
151 call ok(true or false and false, "true or false and false is false?")
152 call ok(null or true, "null or true is false")
154 call ok(true xor false, "true xor false is false?")
155 call ok(not (false xor false), "false xor false is true?")
156 call ok(not (true or false xor true), "true or false xor true is true?")
157 call ok(not (true xor false or true), "true xor false or true is true?")
159 call ok(false eqv false, "false does not equal false?")
160 call ok(not (false eqv true), "false equals true?")
161 call ok(getVT(false eqv null) = "VT_NULL", "getVT(false eqv null) = " & getVT(false eqv null))
163 call ok(true imp true, "true does not imp true?")
164 call ok(false imp false, "false does not imp false?")
165 call ok(not (true imp false), "true imp false?")
166 call ok(false imp null, "false imp null is false?")
168 Call ok(2 >= 1, "! 2 >= 1")
169 Call ok(2 >= 2, "! 2 >= 2")
170 Call ok(not(true >= 2), "true >= 2 ?")
171 Call ok(2 > 1, "! 2 > 1")
172 Call ok(false > true, "! false < true")
173 Call ok(0 > true, "! 0 > true")
174 Call ok(not (true > 0), "true > 0")
175 Call ok(not (0 > 1 = 1), "0 > 1 = 1")
176 Call ok(1 < 2, "! 1 < 2")
177 Call ok(1 = 1 < 0, "! 1 = 1 < 0")
178 Call ok(1 <= 2, "! 1 <= 2")
179 Call ok(2 <= 2, "! 2 <= 2")
181 Call ok(isNull(0 = null), "'(0 = null)' is not null")
182 Call ok(isNull(null = 1), "'(null = 1)' is not null")
183 Call ok(isNull(0 > null), "'(0 > null)' is not null")
184 Call ok(isNull(null > 1), "'(null > 1)' is not null")
185 Call ok(isNull(0 < null), "'(0 < null)' is not null")
186 Call ok(isNull(null < 1), "'(null < 1)' is not null")
187 Call ok(isNull(0 <> null), "'(0 <> null)' is not null")
188 Call ok(isNull(null <> 1), "'(null <> 1)' is not null")
189 Call ok(isNull(0 >= null), "'(0 >= null)' is not null")
190 Call ok(isNull(null >= 1), "'(null >= 1)' is not null")
191 Call ok(isNull(0 <= null), "'(0 <= null)' is not null")
192 Call ok(isNull(null <= 1), "'(null <= 1)' is not null")
194 x = 3
195 Call ok(2+2 = 4, "2+2 = " & (2+2))
196 Call ok(false + 6 + true = 5, "false + 6 + true <> 5")
197 Call ok(getVT(2+null) = "VT_NULL", "getVT(2+null) = " & getVT(2+null))
198 Call ok(2+empty = 2, "2+empty = " & (2+empty))
199 Call ok(x+x = 6, "x+x = " & (x+x))
201 Call ok(5-1 = 4, "5-1 = " & (5-1))
202 Call ok(3+5-true = 9, "3+5-true <> 9")
203 Call ok(getVT(2-null) = "VT_NULL", "getVT(2-null) = " & getVT(2-null))
204 Call ok(2-empty = 2, "2-empty = " & (2-empty))
205 Call ok(2-x = -1, "2-x = " & (2-x))
207 Call ok(9 Mod 6 = 3, "9 Mod 6 = " & (9 Mod 6))
208 Call ok(11.6 Mod 5.5 = False, "11.6 Mod 5.5 = " & (11.6 Mod 5.5 = 0.6))
209 Call ok(7 Mod 4+2 = 5, "7 Mod 4+2 <> 5")
210 Call ok(getVT(2 mod null) = "VT_NULL", "getVT(2 mod null) = " & getVT(2 mod null))
211 Call ok(getVT(null mod 2) = "VT_NULL", "getVT(null mod 2) = " & getVT(null mod 2))
212 'FIXME: Call ok(empty mod 2 = 0, "empty mod 2 = " & (empty mod 2))
214 Call ok(5 \ 2 = 2, "5 \ 2 = " & (5\2))
215 Call ok(4.6 \ 1.5 = 2, "4.6 \ 1.5 = " & (4.6\1.5))
216 Call ok(4.6 \ 1.49 = 5, "4.6 \ 1.49 = " & (4.6\1.49))
217 Call ok(2+3\4 = 2, "2+3\4 = " & (2+3\4))
219 Call ok(2*3 = 6, "2*3 = " & (2*3))
220 Call ok(3/2 = 1.5, "3/2 = " & (3/2))
221 Call ok(5\4/2 = 2, "5\4/2 = " & (5\2/1))
222 Call ok(12/3\2 = 2, "12/3\2 = " & (12/3\2))
223 Call ok(5/1000000 = 0.000005, "5/1000000 = " & (5/1000000))
225 Call ok(2^3 = 8, "2^3 = " & (2^3))
226 Call ok(2^3^2 = 64, "2^3^2 = " & (2^3^2))
227 Call ok(-3^2 = 9, "-3^2 = " & (-3^2))
228 Call ok(2*3^2 = 18, "2*3^2 = " & (2*3^2))
230 x =_
235 x = 3
237 if true then y = true : x = y
238 ok x, "x is false"
240 x = true : if false then x = false
241 ok x, "x is false, if false called?"
243 if not false then x = true
244 ok x, "x is false, if not false not called?"
246 if not false then x = "test" : x = true
247 ok x, "x is false, if not false not called?"
249 if false then x = y : call ok(false, "if false .. : called")
251 if false then x = y : call ok(false, "if false .. : called") else x = "else"
252 Call ok(x = "else", "else not called?")
254 if true then x = y else y = x : Call ok(false, "in else?")
256 if false then :
258 if false then x = y : if true then call ok(false, "embedded if called")
260 if false then x=1 else x=2 end if
261 if true then x=1 end if
263 x = false
264 if false then x = true : x = true
265 Call ok(x = false, "x <> false")
267 if false then
268 ok false, "if false called"
269 end if
271 x = true
272 if x then
273 x = false
274 end if
275 Call ok(not x, "x is false, if not evaluated?")
277 x = false
278 If false Then
279 Call ok(false, "inside if false")
280 Else
281 x = true
282 End If
283 Call ok(x, "else not called?")
285 x = false
286 If false Then
287 Call ok(false, "inside if false")
288 ElseIf not True Then
289 Call ok(false, "inside elseif not true")
290 Else
291 x = true
292 End If
293 Call ok(x, "else not called?")
295 x = false
296 If false Then
297 Call ok(false, "inside if false")
298 x = 1
299 y = 10+x
300 ElseIf not False Then
301 x = true
302 Else
303 Call ok(false, "inside else not true")
304 End If
305 Call ok(x, "elseif not called?")
307 x = false
308 If false Then
309 Call ok(false, "inside if false")
310 ElseIf not False Then
311 x = true
312 End If
313 Call ok(x, "elseif not called?")
315 x = false
316 if 1 then x = true
317 Call ok(x, "if 1 not run?")
319 x = false
320 if &h10000& then x = true
321 Call ok(x, "if &h10000& not run?")
323 x = false
324 y = false
325 while not (x and y)
326 if x then
327 y = true
328 end if
329 x = true
330 wend
331 call ok((x and y), "x or y is false after while")
333 if false then
334 ' empty body
335 end if
337 if false then
338 x = false
339 elseif true then
340 ' empty body
341 end if
343 if false then
344 x = false
345 else
346 ' empty body
347 end if
349 while false
350 wend
352 if empty then
353 ok false, "if empty executed"
354 end if
356 while empty
357 ok false, "while empty executed"
358 wend
360 x = 0
361 if "0" then
362 ok false, "if ""0"" executed"
363 else
364 x = 1
365 end if
366 Call ok(x = 1, "if ""0"" else not executed")
368 x = 0
369 if "-1" then
370 x = 1
371 else
372 ok false, "if ""-1"" else executed"
373 end if
374 Call ok(x = 1, "if ""-1"" not executed")
376 x = 0
377 WHILE x < 3 : x = x + 1 : Wend
378 Call ok(x = 3, "x not equal to 3")
380 x = 0
381 WHILE x < 3 : x = x + 1
382 Wend
383 Call ok(x = 3, "x not equal to 3")
385 z = 2
386 while z > -4 :
389 z = z -2
390 wend
392 x = false
393 y = false
394 do while not (x and y)
395 if x then
396 y = true
397 end if
398 x = true
399 loop
400 call ok((x and y), "x or y is false after while")
402 do while false
403 loop
405 do while false : loop
407 do while true
408 exit do
409 ok false, "exit do didn't work"
410 loop
412 x = 0
413 Do While x < 2 : x = x + 1
414 Loop
415 Call ok(x = 2, "x not equal to 2")
417 x = 0
418 Do While x < 2 : x = x + 1: Loop
419 Call ok(x = 2, "x not equal to 2")
421 x = 0
422 Do While x >= -2 :
423 x = x - 1
424 Loop
425 Call ok(x = -3, "x not equal to -3")
427 x = false
428 y = false
429 do until x and y
430 if x then
431 y = true
432 end if
433 x = true
434 loop
435 call ok((x and y), "x or y is false after do until")
437 do until true
438 loop
440 do until false
441 exit do
442 ok false, "exit do didn't work"
443 loop
445 x = 0
446 Do: :: x = x + 2
447 Loop Until x = 4
448 Call ok(x = 4, "x not equal to 4")
450 x = 0
451 Do: :: x = x + 2 ::: : Loop Until x = 4
452 Call ok(x = 4, "x not equal to 4")
454 x = 5
455 Do: :
457 : x = x * 2
458 Loop Until x = 40
459 Call ok(x = 40, "x not equal to 40")
462 x = false
464 if x then exit do
465 x = true
466 loop
467 call ok(x, "x is false after do..loop?")
469 x = 0
470 Do :If x = 6 Then
471 Exit Do
472 End If
473 x = x + 3
474 Loop
475 Call ok(x = 6, "x not equal to 6")
477 x = false
478 y = false
480 if x then
481 y = true
482 end if
483 x = true
484 loop until x and y
485 call ok((x and y), "x or y is false after while")
488 loop until true
491 exit do
492 ok false, "exit do didn't work"
493 loop until false
495 x = false
496 y = false
498 if x then
499 y = true
500 end if
501 x = true
502 loop while not (x and y)
503 call ok((x and y), "x or y is false after while")
506 loop while false
509 exit do
510 ok false, "exit do didn't work"
511 loop while true
513 y = "for1:"
514 for x = 5 to 8
515 y = y & " " & x
516 next
517 Call ok(y = "for1: 5 6 7 8", "y = " & y)
519 y = "for2:"
520 for x = 5 to 8 step 2
521 y = y & " " & x
522 next
523 Call ok(y = "for2: 5 7", "y = " & y)
525 y = "for3:"
526 x = 2
527 for x = x+3 to 8
528 y = y & " " & x
529 next
530 Call ok(y = "for3: 5 6 7 8", "y = " & y)
532 y = "for4:"
533 for x = 5 to 4
534 y = y & " " & x
535 next
536 Call ok(y = "for4:", "y = " & y)
538 y = "for5:"
539 for x = 5 to 3 step true
540 y = y & " " & x
541 next
542 Call ok(y = "for5: 5 4 3", "y = " & y)
544 y = "for6:"
545 z = 4
546 for x = 5 to z step 3-4
547 y = y & " " & x
548 z = 0
549 next
550 Call ok(y = "for6: 5 4", "y = " & y)
552 y = "for7:"
553 z = 1
554 for x = 5 to 8 step z
555 y = y & " " & x
556 z = 2
557 next
558 Call ok(y = "for7: 5 6 7 8", "y = " & y)
560 z = 0
561 For x = 10 To 18 Step 2 : : z = z + 1
562 Next
563 Call ok(z = 5, "z not equal to 5")
565 y = "for8:"
566 for x = 5 to 8
567 y = y & " " & x
568 x = x+1
569 next
570 Call ok(y = "for8: 5 7", "y = " & y)
572 for x = 1.5 to 1
573 Call ok(false, "for..to called when unexpected")
574 next
576 for x = 1 to 100
577 exit for
578 Call ok(false, "exit for not escaped the loop?")
579 next
581 for x = 1 to 5 :
583 : :exit for
584 Call ok(false, "exit for not escaped the loop?")
585 next
587 dim a1(8)
588 a1(6)=8
589 for x=1 to 8:a1(x)=x-1:next
590 Call ok(a1(6) = 5, "colon used in for loop")
592 a1(6)=8
593 for x=1 to 8:y=1
594 a1(x)=x-2:next
595 Call ok(a1(6) = 4, "colon used in for loop")
597 do while true
598 for x = 1 to 100
599 exit do
600 next
601 loop
603 if null then call ok(false, "if null evaluated")
605 while null
606 call ok(false, "while null evaluated")
607 wend
609 Call collectionObj.reset()
610 y = 0
611 for each x in collectionObj :
613 :y = y + 3
614 next
615 Call ok(y = 9, "y = " & y)
617 Call collectionObj.reset()
618 y = 0
619 x = 10
620 z = 0
621 for each x in collectionObj : z = z + 2
622 y = y+1
623 Call ok(x = y, "x <> y")
624 next
625 Call ok(y = 3, "y = " & y)
626 Call ok(z = 6, "z = " & z)
627 Call ok(getVT(x) = "VT_EMPTY*", "getVT(x) = " & getVT(x))
629 Call collectionObj.reset()
630 y = 0
631 x = 10
632 z = 0
633 for each x in collectionObj : z = z + 2 : y = y+1 ::
634 Call ok(x = y, "x <> y") : next
635 Call ok(y = 3, "y = " & y)
636 Call ok(z = 6, "z = " & z)
638 Call collectionObj.reset()
639 y = false
640 for each x in collectionObj
641 if x = 2 then exit for
642 y = 1
643 next
644 Call ok(y = 1, "y = " & y)
645 Call ok(x = 2, "x = " & x)
647 Set obj = collectionObj
648 Call obj.reset()
649 y = 0
650 x = 10
651 for each x in obj
652 y = y+1
653 Call ok(x = y, "x <> y")
654 next
655 Call ok(y = 3, "y = " & y)
656 Call ok(getVT(x) = "VT_EMPTY*", "getVT(x) = " & getVT(x))
658 x = false
659 select case 3
660 case 2
661 Call ok(false, "unexpected case")
662 case 2
663 Call ok(false, "unexpected case")
664 case 4
665 Call ok(false, "unexpected case")
666 case "test"
667 case "another case"
668 Call ok(false, "unexpected case")
669 case 0, false, 2+1, 10
670 x = true
671 case ok(false, "unexpected case")
672 Call ok(false, "unexpected case")
673 case else
674 Call ok(false, "unexpected case")
675 end select
676 Call ok(x, "wrong case")
678 x = false
679 select case 3
680 case 3
681 x = true
682 end select
683 Call ok(x, "wrong case")
685 x = false
686 select case 2+2
687 case 3
688 Call ok(false, "unexpected case")
689 case else
690 x = true
691 end select
692 Call ok(x, "wrong case")
694 y = "3"
695 x = false
696 select case y
697 case "3"
698 x = true
699 case 3
700 Call ok(false, "unexpected case")
701 end select
702 Call ok(x, "wrong case")
704 select case 0
705 case 1
706 Call ok(false, "unexpected case")
707 case "2"
708 Call ok(false, "unexpected case")
709 end select
711 select case 0
712 end select
714 x = false
715 select case 2
716 case 3,1,2,4: x = true
717 case 5,6,7
718 Call ok(false, "unexpected case")
719 end select
720 Call ok(x, "wrong case")
722 x = false
723 select case 2: case 5,6,7: Call ok(false, "unexpected case")
724 case 2,1,2,4
725 x = true
726 case else: Call ok(false, "unexpected case else")
727 end select
728 Call ok(x, "wrong case")
730 x = False
731 select case 1 :
733 :case 3, 4 :
736 case 5
738 Call ok(false, "unexpected case") :
739 Case Else:
741 x = True
742 end select
743 Call ok(x, "wrong case")
745 select case 0
746 case 1
747 case else
748 'empty else with comment test
749 end select
751 select case 0 : case 1 : case else : end select
753 if false then
754 Sub testsub
755 x = true
756 End Sub
757 end if
759 x = false
760 Call testsub
761 Call ok(x, "x is false, testsub not called?")
763 Sub SubSetTrue(v)
764 Call ok(not v, "v is not true")
765 v = true
766 End Sub
768 x = false
769 SubSetTrue x
770 Call ok(x, "x was not set by SubSetTrue")
772 SubSetTrue false
773 Call ok(not false, "false is no longer false?")
775 Sub SubSetTrue2(ByRef v)
776 Call ok(not v, "v is not true")
777 v = true
778 End Sub
780 x = false
781 SubSetTrue2 x
782 Call ok(x, "x was not set by SubSetTrue")
784 Sub TestSubArgVal(ByVal v)
785 Call ok(not v, "v is not false")
786 v = true
787 Call ok(v, "v is not true?")
788 End Sub
790 x = false
791 Call TestSubArgVal(x)
792 Call ok(not x, "x is true after TestSubArgVal call?")
794 Sub TestSubMultiArgs(a,b,c,d,e)
795 Call ok(a=1, "a = " & a)
796 Call ok(b=2, "b = " & b)
797 Call ok(c=3, "c = " & c)
798 Call ok(d=4, "d = " & d)
799 Call ok(e=5, "e = " & e)
800 End Sub
802 Sub TestSubExit(ByRef a)
803 If a Then
804 Exit Sub
805 End If
806 Call ok(false, "Exit Sub not called?")
807 End Sub
809 Call TestSubExit(true)
811 Sub TestSubExit2
812 for x = 1 to 100
813 Exit Sub
814 next
815 End Sub
816 Call TestSubExit2
818 TestSubMultiArgs 1, 2, 3, 4, 5
819 Call TestSubMultiArgs(1, 2, 3, 4, 5)
821 Sub TestSubLocalVal
822 x = false
823 Call ok(not x, "local x is not false?")
824 Dim x
825 Dim a,b, c
826 End Sub
828 x = true
829 y = true
830 Call TestSubLocalVal
831 Call ok(x, "global x is not true?")
833 Public Sub TestPublicSub
834 End Sub
835 Call TestPublicSub
837 Private Sub TestPrivateSub
838 End Sub
839 Call TestPrivateSub
841 Public Sub TestSeparatorSub : :
843 End Sub
844 Call TestSeparatorSub
846 if false then
847 Function testfunc
848 x = true
849 End Function
850 end if
852 x = false
853 Call TestFunc
854 Call ok(x, "x is false, testfunc not called?")
856 Function FuncSetTrue(v)
857 Call ok(not v, "v is not true")
858 v = true
859 End Function
861 x = false
862 FuncSetTrue x
863 Call ok(x, "x was not set by FuncSetTrue")
865 FuncSetTrue false
866 Call ok(not false, "false is no longer false?")
868 Function FuncSetTrue2(ByRef v)
869 Call ok(not v, "v is not true")
870 v = true
871 End Function
873 x = false
874 FuncSetTrue2 x
875 Call ok(x, "x was not set by FuncSetTrue")
877 Function TestFuncArgVal(ByVal v)
878 Call ok(not v, "v is not false")
879 v = true
880 Call ok(v, "v is not true?")
881 End Function
883 x = false
884 Call TestFuncArgVal(x)
885 Call ok(not x, "x is true after TestFuncArgVal call?")
887 Function TestFuncMultiArgs(a,b,c,d,e)
888 Call ok(a=1, "a = " & a)
889 Call ok(b=2, "b = " & b)
890 Call ok(c=3, "c = " & c)
891 Call ok(d=4, "d = " & d)
892 Call ok(e=5, "e = " & e)
893 End Function
895 TestFuncMultiArgs 1, 2, 3, 4, 5
896 Call TestFuncMultiArgs(1, 2, 3, 4, 5)
898 Function TestFuncLocalVal
899 x = false
900 Call ok(not x, "local x is not false?")
901 Dim x
902 End Function
904 x = true
905 y = true
906 Call TestFuncLocalVal
907 Call ok(x, "global x is not true?")
909 Function TestFuncExit(ByRef a)
910 If a Then
911 Exit Function
912 End If
913 Call ok(false, "Exit Function not called?")
914 End Function
916 Call TestFuncExit(true)
918 Function TestFuncExit2(ByRef a)
919 For x = 1 to 100
920 For y = 1 to 100
921 Exit Function
922 Next
923 Next
924 Call ok(false, "Exit Function not called?")
925 End Function
927 Call TestFuncExit2(true)
929 Sub SubParseTest
930 End Sub : x = false
931 Call SubParseTest
933 Function FuncParseTest
934 End Function : x = false
936 Function ReturnTrue
937 ReturnTrue = false
938 ReturnTrue = true
939 End Function
941 Call ok(ReturnTrue(), "ReturnTrue returned false?")
943 Function SetVal(ByRef x, ByVal v)
944 x = v
945 SetVal = x
946 Exit Function
947 End Function
949 x = false
950 ok SetVal(x, true), "SetVal returned false?"
951 Call ok(x, "x is not set to true by SetVal?")
953 Public Function TestPublicFunc
954 End Function
955 Call TestPublicFunc
957 Private Function TestPrivateFunc
958 End Function
959 Call TestPrivateFunc
961 Public Function TestSepFunc(ByVal a) : :
962 : TestSepFunc = a
963 End Function
964 Call ok(TestSepFunc(1) = 1, "Function did not return 1")
966 ok duplicatedfunc() = 2, "duplicatedfunc = " & duplicatedfunc()
968 function duplicatedfunc
969 ok false, "duplicatedfunc called"
970 end function
972 sub duplicatedfunc
973 ok false, "duplicatedfunc called"
974 end sub
976 function duplicatedfunc
977 duplicatedfunc = 2
978 end function
980 ok duplicatedfunc() = 2, "duplicatedfunc = " & duplicatedfunc()
982 ' Stop has an effect only in debugging mode
983 Stop
985 set x = testObj
986 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=testObj) = " & getVT(x))
988 Set obj = New EmptyClass
989 Call ok(getVT(obj) = "VT_DISPATCH*", "getVT(obj) = " & getVT(obj))
991 Class EmptyClass
992 End Class
994 Set x = obj
995 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x) = " & getVT(x))
997 Class TestClass
998 Public publicProp
1000 Private privateProp
1002 Public Function publicFunction()
1003 privateSub()
1004 publicFunction = 4
1005 End Function
1007 Public Property Get gsProp()
1008 gsProp = privateProp
1009 funcCalled = "gsProp get"
1010 exit property
1011 Call ok(false, "exit property not returned?")
1012 End Property
1014 Public Default Property Get DefValGet
1015 DefValGet = privateProp
1016 funcCalled = "GetDefVal"
1017 End Property
1019 Public Property Let DefValGet(x)
1020 End Property
1022 Public publicProp2
1024 Public Sub publicSub
1025 End Sub
1027 Public Property Let gsProp(val)
1028 privateProp = val
1029 funcCalled = "gsProp let"
1030 exit property
1031 Call ok(false, "exit property not returned?")
1032 End Property
1034 Public Property Set gsProp(val)
1035 funcCalled = "gsProp set"
1036 exit property
1037 Call ok(false, "exit property not returned?")
1038 End Property
1040 Public Sub setPrivateProp(x)
1041 privateProp = x
1042 End Sub
1044 Function getPrivateProp
1045 getPrivateProp = privateProp
1046 End Function
1048 Private Sub privateSub
1049 End Sub
1051 Public Sub Class_Initialize
1052 publicProp2 = 2
1053 privateProp = true
1054 Call ok(getVT(privateProp) = "VT_BOOL*", "getVT(privateProp) = " & getVT(privateProp))
1055 Call ok(getVT(publicProp2) = "VT_I2*", "getVT(publicProp2) = " & getVT(publicProp2))
1056 Call ok(getVT(Me.publicProp2) = "VT_I2", "getVT(Me.publicProp2) = " & getVT(Me.publicProp2))
1057 End Sub
1059 Property Get gsGetProp(x)
1060 gsGetProp = x
1061 End Property
1062 End Class
1064 Call testDisp(new testClass)
1066 Set obj = New TestClass
1068 Call ok(obj.publicFunction = 4, "obj.publicFunction = " & obj.publicFunction)
1069 Call ok(obj.publicFunction() = 4, "obj.publicFunction() = " & obj.publicFunction())
1071 obj.publicSub()
1072 Call obj.publicSub
1073 Call obj.publicFunction()
1075 Call ok(getVT(obj.publicProp) = "VT_EMPTY", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
1076 obj.publicProp = 3
1077 Call ok(getVT(obj.publicProp) = "VT_I2", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
1078 Call ok(obj.publicProp = 3, "obj.publicProp = " & obj.publicProp)
1079 obj.publicProp() = 3
1081 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
1082 Call obj.setPrivateProp(6)
1083 Call ok(obj.getPrivateProp = 6, "obj.getPrivateProp = " & obj.getPrivateProp)
1085 Dim funcCalled
1086 funcCalled = ""
1087 Call ok(obj.gsProp = 6, "obj.gsProp = " & obj.gsProp)
1088 Call ok(funcCalled = "gsProp get", "funcCalled = " & funcCalled)
1089 obj.gsProp = 3
1090 Call ok(funcCalled = "gsProp let", "funcCalled = " & funcCalled)
1091 Call ok(obj.getPrivateProp = 3, "obj.getPrivateProp = " & obj.getPrivateProp)
1092 Set obj.gsProp = New testclass
1093 Call ok(funcCalled = "gsProp set", "funcCalled = " & funcCalled)
1095 x = obj
1096 Call ok(x = 3, "(x = obj) = " & x)
1097 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
1098 funcCalled = ""
1099 Call ok(obj = 3, "(x = obj) = " & obj)
1100 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
1102 Call obj.Class_Initialize
1103 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
1105 x = (New testclass).publicProp
1107 Class TermTest
1108 Public Sub Class_Terminate()
1109 funcCalled = "terminate"
1110 End Sub
1111 End Class
1113 Set obj = New TermTest
1114 funcCalled = ""
1115 Set obj = Nothing
1116 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
1118 Set obj = New TermTest
1119 funcCalled = ""
1120 Call obj.Class_Terminate
1121 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
1122 funcCalled = ""
1123 Set obj = Nothing
1124 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
1126 Call (New testclass).publicSub()
1127 Call (New testclass).publicSub
1129 class PropTest
1130 property get prop0()
1131 prop0 = 1
1132 end property
1134 property get prop1(x)
1135 prop1 = x+1
1136 end property
1138 property get prop2(x, y)
1139 prop2 = x+y
1140 end property
1141 end class
1143 set obj = new PropTest
1145 call ok(obj.prop0 = 1, "obj.prop0 = " & obj.prop0)
1146 call ok(obj.prop1(3) = 4, "obj.prop1(3) = " & obj.prop1(3))
1147 call ok(obj.prop2(3,4) = 7, "obj.prop2(3,4) = " & obj.prop2(3,4))
1148 call obj.prop0()
1149 call obj.prop1(2)
1150 call obj.prop2(3,4)
1152 x = "following ':' is correct syntax" :
1153 x = "following ':' is correct syntax" :: :
1154 :: x = "also correct syntax"
1155 rem another ugly way for comments
1156 x = "rem as simplestatement" : rem rem comment
1159 Set obj = new EmptyClass
1160 Set x = obj
1161 Set y = new EmptyClass
1163 Call ok(obj is x, "obj is not x")
1164 Call ok(x is obj, "x is not obj")
1165 Call ok(not (obj is y), "obj is not y")
1166 Call ok(not obj is y, "obj is not y")
1167 Call ok(not (x is Nothing), "x is 1")
1168 Call ok(Nothing is Nothing, "Nothing is not Nothing")
1169 Call ok(x is obj and true, "x is obj and true is false")
1171 Class TestMe
1172 Public Sub Test(MyMe)
1173 Call ok(Me is MyMe, "Me is not MyMe")
1174 End Sub
1175 End Class
1177 Set obj = New TestMe
1178 Call obj.test(obj)
1180 Call ok(getVT(test) = "VT_DISPATCH", "getVT(test) = " & getVT(test))
1181 Call ok(Me is Test, "Me is not Test")
1183 Const c1 = 1, c2 = 2, c3 = -3
1184 Call ok(c1 = 1, "c1 = " & c1)
1185 Call ok(getVT(c1) = "VT_I2", "getVT(c1) = " & getVT(c1))
1186 Call ok(c3 = -3, "c3 = " & c3)
1187 Call ok(getVT(c3) = "VT_I2", "getVT(c3) = " & getVT(c3))
1189 Const cb = True, cs = "test", cnull = null
1190 Call ok(cb, "cb = " & cb)
1191 Call ok(getVT(cb) = "VT_BOOL", "getVT(cb) = " & getVT(cb))
1192 Call ok(cs = "test", "cs = " & cs)
1193 Call ok(getVT(cs) = "VT_BSTR", "getVT(cs) = " & getVT(cs))
1194 Call ok(isNull(cnull), "cnull = " & cnull)
1195 Call ok(getVT(cnull) = "VT_NULL", "getVT(cnull) = " & getVT(cnull))
1197 Call ok(+1 = 1, "+1 != 1")
1198 Call ok(+true = true, "+1 != 1")
1199 Call ok(getVT(+true) = "VT_BOOL", "getVT(+true) = " & getVT(+true))
1200 Call ok(+"true" = "true", """+true"" != true")
1201 Call ok(getVT(+"true") = "VT_BSTR", "getVT(+""true"") = " & getVT(+"true"))
1202 Call ok(+obj is obj, "+obj != obj")
1203 Call ok(+--+-+1 = -1, "+--+-+1 != -1")
1205 if false then Const conststr = "str"
1206 Call ok(conststr = "str", "conststr = " & conststr)
1207 Call ok(getVT(conststr) = "VT_BSTR", "getVT(conststr) = " & getVT(conststr))
1208 Call ok(conststr = "str", "conststr = " & conststr)
1210 Sub ConstTestSub
1211 Const funcconst = 1
1212 Call ok(c1 = 1, "c1 = " & c1)
1213 Call ok(funcconst = 1, "funcconst = " & funcconst)
1214 End Sub
1216 Call ConstTestSub
1217 Dim funcconst
1219 ' Property may be used as an identifier (although it's a keyword)
1220 Sub TestProperty
1221 Dim Property
1222 PROPERTY = true
1223 Call ok(property, "property = " & property)
1225 for property = 1 to 2
1226 next
1227 End Sub
1229 Call TestProperty
1231 Class Property
1232 Public Sub Property()
1233 End Sub
1235 Sub Test(byref property)
1236 End Sub
1237 End Class
1239 Class Property2
1240 Function Property()
1241 End Function
1243 Sub Test(property)
1244 End Sub
1246 Sub Test2(byval property)
1247 End Sub
1248 End Class
1250 Class SeparatorTest : : Dim varTest1
1252 Private Sub Class_Initialize : varTest1 = 1
1253 End Sub ::
1255 Property Get Test1() :
1256 Test1 = varTest1
1257 End Property ::
1259 Property Let Test1(a) :
1260 varTest1 = a
1261 End Property :
1263 Public Function AddToTest1(ByVal a) :: :
1264 varTest1 = varTest1 + a
1265 AddToTest1 = varTest1
1266 End Function : End Class : :: Set obj = New SeparatorTest
1268 Call ok(obj.Test1 = 1, "obj.Test1 is not 1")
1269 obj.Test1 = 6
1270 Call ok(obj.Test1 = 6, "obj.Test1 is not 6")
1271 obj.AddToTest1(5)
1272 Call ok(obj.Test1 = 11, "obj.Test1 is not 11")
1274 set obj = unkObj
1275 set x = obj
1276 call ok(getVT(obj) = "VT_UNKNOWN*", "getVT(obj) = " & getVT(obj))
1277 call ok(getVT(x) = "VT_UNKNOWN*", "getVT(x) = " & getVT(x))
1278 call ok(getVT(unkObj) = "VT_UNKNOWN", "getVT(unkObj) = " & getVT(unkObj))
1279 call ok(obj is unkObj, "obj is not unkObj")
1281 ' Array tests
1283 Call ok(getVT(arr) = "VT_EMPTY*", "getVT(arr) = " & getVT(arr))
1285 Dim arr(3)
1286 Dim arr2(4,3), arr3(5,4,3), arr0(0), noarr()
1288 Call ok(getVT(arr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr) = " & getVT(arr))
1289 Call ok(getVT(arr2) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr2) = " & getVT(arr2))
1290 Call ok(getVT(arr0) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr0) = " & getVT(arr0))
1291 Call ok(getVT(noarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(noarr) = " & getVT(noarr))
1293 Call testArray(1, arr)
1294 Call testArray(2, arr2)
1295 Call testArray(3, arr3)
1296 Call testArray(0, arr0)
1297 Call testArray(-1, noarr)
1299 Call ok(getVT(arr(1)) = "VT_EMPTY*", "getVT(arr(1)) = " & getVT(arr(1)))
1300 Call ok(getVT(arr2(1,2)) = "VT_EMPTY*", "getVT(arr2(1,2)) = " & getVT(arr2(1,2)))
1301 Call ok(getVT(arr3(1,2,2)) = "VT_EMPTY*", "getVT(arr3(1,2,3)) = " & getVT(arr3(1,2,2)))
1302 Call ok(getVT(arr(0)) = "VT_EMPTY*", "getVT(arr(0)) = " & getVT(arr(0)))
1303 Call ok(getVT(arr(3)) = "VT_EMPTY*", "getVT(arr(3)) = " & getVT(arr(3)))
1304 Call ok(getVT(arr0(0)) = "VT_EMPTY*", "getVT(arr0(0)) = " & getVT(arr0(0)))
1306 arr(2) = 3
1307 Call ok(arr(2) = 3, "arr(2) = " & arr(2))
1308 Call ok(getVT(arr(2)) = "VT_I2*", "getVT(arr(2)) = " & getVT(arr(2)))
1310 arr3(3,2,1) = 1
1311 arr3(1,2,3) = 2
1312 Call ok(arr3(3,2,1) = 1, "arr3(3,2,1) = " & arr3(3,2,1))
1313 Call ok(arr3(1,2,3) = 2, "arr3(1,2,3) = " & arr3(1,2,3))
1314 arr2(4,3) = 1
1315 Call ok(arr2(4,3) = 1, "arr2(4,3) = " & arr2(4,3))
1317 x = arr3
1318 Call ok(x(3,2,1) = 1, "x(3,2,1) = " & x(3,2,1))
1320 Function getarr()
1321 Dim arr(3)
1322 arr(2) = 2
1323 getarr = arr
1324 arr(3) = 3
1325 End Function
1327 x = getarr()
1328 Call ok(getVT(x) = "VT_ARRAY|VT_VARIANT*", "getVT(x) = " & getVT(x))
1329 Call ok(x(2) = 2, "x(2) = " & x(2))
1330 Call ok(getVT(x(3)) = "VT_EMPTY*", "getVT(x(3)) = " & getVT(x(3)))
1332 x(1) = 1
1333 Call ok(x(1) = 1, "x(1) = " & x(1))
1334 x = getarr()
1335 Call ok(getVT(x(1)) = "VT_EMPTY*", "getVT(x(1)) = " & getVT(x(1)))
1336 Call ok(x(2) = 2, "x(2) = " & x(2))
1338 x(1) = 1
1339 y = x
1340 x(1) = 2
1341 Call ok(y(1) = 1, "y(1) = " & y(1))
1343 for x=1 to 1
1344 Dim forarr(3)
1345 if x=1 then
1346 Call ok(getVT(forarr(1)) = "VT_EMPTY*", "getVT(forarr(1)) = " & getVT(forarr(1)))
1347 else
1348 Call ok(forarr(1) = x, "forarr(1) = " & forarr(1))
1349 end if
1350 forarr(1) = x+1
1351 next
1354 Call ok(forarr(x) = 2, "forarr(x) = " & forarr(x))
1356 sub accessArr()
1357 ok arr(1) = 1, "arr(1) = " & arr(1)
1358 arr(1) = 2
1359 end sub
1360 arr(1) = 1
1361 call accessArr
1362 ok arr(1) = 2, "arr(1) = " & arr(1)
1364 sub accessArr2(x,y)
1365 ok arr2(x,y) = 1, "arr2(x,y) = " & arr2(x,y)
1366 x = arr2(x,y)
1367 arr2(x,y) = 2
1368 end sub
1369 arr2(1,2) = 1
1370 call accessArr2(1, 2)
1371 ok arr2(1,2) = 2, "arr2(1,2) = " & arr2(1,2)
1373 x = Array(Array(3))
1374 call ok(x(0)(0) = 3, "x(0)(0) = " & x(0)(0))
1376 function seta0(arr)
1377 arr(0) = 2
1378 seta0 = 1
1379 end function
1381 x = Array(1)
1382 seta0 x
1383 ok x(0) = 2, "x(0) = " & x(0)
1385 x = Array(1)
1386 seta0 (x)
1387 ok x(0) = 1, "x(0) = " & x(0)
1389 x = Array(1)
1390 call (((seta0))) ((x))
1391 ok x(0) = 1, "x(0) = " & x(0)
1393 x = Array(1)
1394 call (((seta0))) (x)
1395 ok x(0) = 2, "x(0) = " & x(0)
1397 x = Array(Array(3))
1398 seta0 x(0)
1399 call ok(x(0)(0) = 2, "x(0)(0) = " & x(0)(0))
1401 x = Array(Array(3))
1402 seta0 (x(0))
1403 call ok(x(0)(0) = 3, "x(0)(0) = " & x(0)(0))
1405 y = (seta0)(x)
1406 ok y = 1, "y = " & y
1408 y = ((x))(0)
1409 ok y = 2, "y = " & y
1411 sub changearg(x)
1412 x = 2
1413 end sub
1415 x = Array(1)
1416 changearg x(0)
1417 ok x(0) = 2, "x(0) = " & x(0)
1418 ok getVT(x) = "VT_ARRAY|VT_VARIANT*", "getVT(x) after redim = " & getVT(x)
1420 x = Array(1)
1421 changearg (x(0))
1422 ok x(0) = 1, "x(0) = " & x(0)
1424 x = Array(1)
1425 redim x(4)
1426 ok ubound(x) = 4, "ubound(x) = " & ubound(x)
1427 ok x(0) = empty, "x(0) = " & x(0)
1429 x = 1
1430 redim x(3)
1431 ok ubound(x) = 3, "ubound(x) = " & ubound(x)
1433 x(0) = 1
1434 x(1) = 2
1435 x(2) = 3
1436 x(2) = 4
1438 redim preserve x(1)
1439 ok ubound(x) = 1, "ubound(x) = " & ubound(x)
1440 ok x(0) = 1, "x(0) = " & x(1)
1441 ok x(1) = 2, "x(1) = " & x(1)
1443 redim preserve x(2)
1444 ok ubound(x) = 2, "ubound(x) = " & ubound(x)
1445 ok x(0) = 1, "x(0) = " & x(0)
1446 ok x(1) = 2, "x(1) = " & x(1)
1447 ok x(2) = vbEmpty, "x(2) = " & x(2)
1449 on error resume next
1450 redim preserve x(2,2)
1451 e = err.number
1452 on error goto 0
1453 ok e = 9, "e = " & e ' VBSE_OUT_OF_BOUNDS, cannot change cDims
1455 x = Array(1, 2)
1456 redim x(-1)
1457 ok lbound(x) = 0, "lbound(x) = " & lbound(x)
1458 ok ubound(x) = -1, "ubound(x) = " & ubound(x)
1460 redim x(3, 2)
1461 ok ubound(x) = 3, "ubound(x) = " & ubound(x)
1462 ok ubound(x, 1) = 3, "ubound(x, 1) = " & ubound(x, 1)
1463 ok ubound(x, 2) = 2, "ubound(x, 2) = " & ubound(x, 2) & " expected 2"
1465 redim x(1, 3)
1466 x(0,0) = 1.1
1467 x(0,1) = 1.2
1468 x(0,2) = 1.3
1469 x(0,3) = 1.4
1470 x(1,0) = 2.1
1471 x(1,1) = 2.2
1472 x(1,2) = 2.3
1473 x(1,3) = 2.4
1475 redim preserve x(1,1)
1476 ok ubound(x, 1) = 1, "ubound(x, 1) = " & ubound(x, 1)
1477 ok ubound(x, 2) = 1, "ubound(x, 2) = " & ubound(x, 2)
1478 ok x(0,0) = 1.1, "x(0,0) = " & x(0,0)
1479 ok x(0,1) = 1.2, "x(0,1) = " & x(0,1)
1480 ok x(1,0) = 2.1, "x(1,0) = " & x(1,0)
1481 ok x(1,1) = 2.2, "x(1,1) = " & x(1,1)
1483 redim preserve x(1,2)
1484 ok ubound(x, 1) = 1, "ubound(x, 1) = " & ubound(x, 1)
1485 ok ubound(x, 2) = 2, "ubound(x, 2) = " & ubound(x, 2)
1486 ok x(0,0) = 1.1, "x(0,0) = " & x(0,0)
1487 ok x(0,1) = 1.2, "x(0,1) = " & x(0,1)
1488 ok x(1,0) = 2.1, "x(1,0) = " & x(1,0)
1489 ok x(1,1) = 2.2, "x(1,1) = " & x(1,1)
1490 ok x(0,2) = vbEmpty, "x(0,2) = " & x(0,2)
1491 ok x(1,2) = vbEmpty, "x(1,2) = " & x(1,1)
1493 on error resume next
1494 redim preserve x(2,2)
1495 e = err.number
1496 on error goto 0
1497 ok e = 9, "e = " & e ' VBSE_OUT_OF_BOUNDS, can only change rightmost dimension
1499 dim staticarray(4)
1500 on error resume next
1501 redim staticarray(3)
1502 e = err.number
1503 on error goto 0
1504 todo_wine_ok e = 10, "e = " & e
1506 Class ArrClass
1507 Dim classarr(3)
1508 Dim classnoarr()
1509 Dim var
1511 Private Sub Class_Initialize
1512 Call ok(getVT(classarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(classarr) = " & getVT(classarr))
1513 Call testArray(-1, classnoarr)
1514 classarr(0) = 1
1515 classarr(1) = 2
1516 classarr(2) = 3
1517 classarr(3) = 4
1518 End Sub
1520 Public Sub testVarVT
1521 Call ok(getVT(var) = "VT_ARRAY|VT_VARIANT*", "getVT(var) = " & getVT(var))
1522 End Sub
1523 End Class
1525 Set obj = new ArrClass
1526 Call ok(getVT(obj.classarr) = "VT_ARRAY|VT_VARIANT", "getVT(obj.classarr) = " & getVT(obj.classarr))
1527 'todo_wine Call ok(obj.classarr(1) = 2, "obj.classarr(1) = " & obj.classarr(1))
1529 obj.var = arr
1530 Call ok(getVT(obj.var) = "VT_ARRAY|VT_VARIANT", "getVT(obj.var) = " & getVT(obj.var))
1531 Call obj.testVarVT
1533 Sub arrarg(byref refarr, byval valarr, byref refarr2, byval valarr2)
1534 Call ok(getVT(refarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(refarr) = " & getVT(refarr))
1535 Call ok(getVT(valarr) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr) = " & getVT(valarr))
1536 Call ok(getVT(refarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(refarr2) = " & getVT(refarr2))
1537 Call ok(getVT(valarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr2) = " & getVT(valarr2))
1538 End Sub
1540 Call arrarg(arr, arr, obj.classarr, obj.classarr)
1542 Sub arrarg2(byref refarr(), byval valarr(), byref refarr2(), byval valarr2())
1543 Call ok(getVT(refarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(refarr) = " & getVT(refarr))
1544 Call ok(getVT(valarr) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr) = " & getVT(valarr))
1545 Call ok(getVT(refarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(refarr2) = " & getVT(refarr2))
1546 Call ok(getVT(valarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr2) = " & getVT(valarr2))
1547 End Sub
1549 Call arrarg2(arr, arr, obj.classarr, obj.classarr)
1551 Sub testarrarg(arg(), vt)
1552 Call ok(getVT(arg) = vt, "getVT() = " & getVT(arg) & " expected " & vt)
1553 End Sub
1555 Call testarrarg(1, "VT_I2*")
1556 Call testarrarg(false, "VT_BOOL*")
1557 Call testarrarg(Empty, "VT_EMPTY*")
1559 Sub modifyarr(arr)
1560 Call ok(arr(0) = "not modified", "arr(0) = " & arr(0))
1561 arr(0) = "modified"
1562 End Sub
1564 arr(0) = "not modified"
1565 Call modifyarr(arr)
1566 Call ok(arr(0) = "modified", "arr(0) = " & arr(0))
1568 arr(0) = "not modified"
1569 modifyarr(arr)
1570 Call ok(arr(0) = "not modified", "arr(0) = " & arr(0))
1572 for x = 0 to UBound(arr)
1573 arr(x) = x
1574 next
1575 y = 0
1576 for each x in arr
1577 Call ok(x = y, "x = " & x & ", expected " & y)
1578 Call ok(arr(y) = y, "arr(" & y & ") = " & arr(y))
1579 arr(y) = 1
1580 x = 1
1581 y = y+1
1582 next
1583 Call ok(y = 4, "y = " & y & " after array enumeration")
1585 for x=0 to UBound(arr2, 1)
1586 for y=0 to UBound(arr2, 2)
1587 arr2(x, y) = x + y*(UBound(arr2, 1)+1)
1588 next
1589 next
1590 y = 0
1591 for each x in arr2
1592 Call ok(x = y, "x = " & x & ", expected " & y)
1593 y = y+1
1594 next
1595 Call ok(y = 20, "y = " & y & " after array enumeration")
1597 for each x in noarr
1598 Call ok(false, "Empty array contains: " & x)
1599 next
1601 ' It's allowed to declare non-builtin RegExp class...
1602 class RegExp
1603 public property get Global()
1604 Call ok(false, "Global called")
1605 Global = "fail"
1606 end property
1607 end class
1609 ' ...but there is no way to use it because builtin instance is always created
1610 set x = new RegExp
1611 Call ok(x.Global = false, "x.Global = " & x.Global)
1613 sub test_nothing_errors
1614 dim x
1615 on error resume next
1617 x = 1
1618 err.clear
1619 x = nothing
1620 call ok(err.number = 91, "err.number = " & err.number)
1621 call ok(x = 1, "x = " & x)
1623 err.clear
1624 x = not nothing
1625 call ok(err.number = 91, "err.number = " & err.number)
1626 call ok(x = 1, "x = " & x)
1628 err.clear
1629 x = "" & nothing
1630 call ok(err.number = 91, "err.number = " & err.number)
1631 call ok(x = 1, "x = " & x)
1632 end sub
1633 call test_nothing_errors()
1635 sub test_identifiers
1636 ' test keywords that can also be a declared identifier
1637 Dim default
1638 default = "xx"
1639 Call ok(default = "xx", "default = " & default & " expected ""xx""")
1641 Dim error
1642 error = "xx"
1643 Call ok(error = "xx", "error = " & error & " expected ""xx""")
1645 Dim explicit
1646 explicit = "xx"
1647 Call ok(explicit = "xx", "explicit = " & explicit & " expected ""xx""")
1649 Dim step
1650 step = "xx"
1651 Call ok(step = "xx", "step = " & step & " expected ""xx""")
1653 Dim property
1654 property = "xx"
1655 Call ok(property = "xx", "property = " & property & " expected ""xx""")
1656 end sub
1657 call test_identifiers()
1659 Class class_test_identifiers_as_function_name
1660 Sub Property ( par )
1661 End Sub
1663 Function Error( par )
1664 End Function
1666 Sub Default ()
1667 End Sub
1669 Function Explicit (par)
1670 Explicit = par
1671 End Function
1673 Sub Step ( default )
1674 End Sub
1675 End Class
1677 Class class_test_identifiers_as_property_name
1678 Public Property Get Property()
1679 End Property
1681 Public Property Let Error(par)
1682 Error = par
1683 End Property
1685 Public Property Set Default(par)
1686 Set Default = par
1687 End Property
1688 End Class
1690 sub test_dotIdentifiers
1691 ' test keywords that can also be an identifier after a dot
1692 Call ok(testObj.rem = 10, "testObj.rem = " & testObj.rem & " expected 10")
1693 Call ok(testObj.true = 10, "testObj.true = " & testObj.true & " expected 10")
1694 Call ok(testObj.false = 10, "testObj.false = " & testObj.false & " expected 10")
1695 Call ok(testObj.not = 10, "testObj.not = " & testObj.not & " expected 10")
1696 Call ok(testObj.and = 10, "testObj.and = " & testObj.and & " expected 10")
1697 Call ok(testObj.or = 10, "testObj.or = " & testObj.or & " expected 10")
1698 Call ok(testObj.xor = 10, "testObj.xor = " & testObj.xor & " expected 10")
1699 Call ok(testObj.eqv = 10, "testObj.eqv = " & testObj.eqv & " expected 10")
1700 Call ok(testObj.imp = 10, "testObj.imp = " & testObj.imp & " expected 10")
1701 Call ok(testObj.is = 10, "testObj.is = " & testObj.is & " expected 10")
1702 Call ok(testObj.mod = 10, "testObj.mod = " & testObj.mod & " expected 10")
1703 Call ok(testObj.call = 10, "testObj.call = " & testObj.call & " expected 10")
1704 Call ok(testObj.dim = 10, "testObj.dim = " & testObj.dim & " expected 10")
1705 Call ok(testObj.sub = 10, "testObj.sub = " & testObj.sub & " expected 10")
1706 Call ok(testObj.function = 10, "testObj.function = " & testObj.function & " expected 10")
1707 Call ok(testObj.get = 10, "testObj.get = " & testObj.get & " expected 10")
1708 Call ok(testObj.let = 10, "testObj.let = " & testObj.let & " expected 10")
1709 Call ok(testObj.const = 10, "testObj.const = " & testObj.const & " expected 10")
1710 Call ok(testObj.if = 10, "testObj.if = " & testObj.if & " expected 10")
1711 Call ok(testObj.else = 10, "testObj.else = " & testObj.else & " expected 10")
1712 Call ok(testObj.elseif = 10, "testObj.elseif = " & testObj.elseif & " expected 10")
1713 Call ok(testObj.end = 10, "testObj.end = " & testObj.end & " expected 10")
1714 Call ok(testObj.then = 10, "testObj.then = " & testObj.then & " expected 10")
1715 Call ok(testObj.exit = 10, "testObj.exit = " & testObj.exit & " expected 10")
1716 Call ok(testObj.while = 10, "testObj.while = " & testObj.while & " expected 10")
1717 Call ok(testObj.wend = 10, "testObj.wend = " & testObj.wend & " expected 10")
1718 Call ok(testObj.do = 10, "testObj.do = " & testObj.do & " expected 10")
1719 Call ok(testObj.loop = 10, "testObj.loop = " & testObj.loop & " expected 10")
1720 Call ok(testObj.until = 10, "testObj.until = " & testObj.until & " expected 10")
1721 Call ok(testObj.for = 10, "testObj.for = " & testObj.for & " expected 10")
1722 Call ok(testObj.to = 10, "testObj.to = " & testObj.to & " expected 10")
1723 Call ok(testObj.each = 10, "testObj.each = " & testObj.each & " expected 10")
1724 Call ok(testObj.in = 10, "testObj.in = " & testObj.in & " expected 10")
1725 Call ok(testObj.select = 10, "testObj.select = " & testObj.select & " expected 10")
1726 Call ok(testObj.case = 10, "testObj.case = " & testObj.case & " expected 10")
1727 Call ok(testObj.byref = 10, "testObj.byref = " & testObj.byref & " expected 10")
1728 Call ok(testObj.byval = 10, "testObj.byval = " & testObj.byval & " expected 10")
1729 Call ok(testObj.option = 10, "testObj.option = " & testObj.option & " expected 10")
1730 Call ok(testObj.nothing = 10, "testObj.nothing = " & testObj.nothing & " expected 10")
1731 Call ok(testObj.empty = 10, "testObj.empty = " & testObj.empty & " expected 10")
1732 Call ok(testObj.null = 10, "testObj.null = " & testObj.null & " expected 10")
1733 Call ok(testObj.class = 10, "testObj.class = " & testObj.class & " expected 10")
1734 Call ok(testObj.set = 10, "testObj.set = " & testObj.set & " expected 10")
1735 Call ok(testObj.new = 10, "testObj.new = " & testObj.new & " expected 10")
1736 Call ok(testObj.public = 10, "testObj.public = " & testObj.public & " expected 10")
1737 Call ok(testObj.private = 10, "testObj.private = " & testObj.private & " expected 10")
1738 Call ok(testObj.next = 10, "testObj.next = " & testObj.next & " expected 10")
1739 Call ok(testObj.on = 10, "testObj.on = " & testObj.on & " expected 10")
1740 Call ok(testObj.resume = 10, "testObj.resume = " & testObj.resume & " expected 10")
1741 Call ok(testObj.goto = 10, "testObj.goto = " & testObj.goto & " expected 10")
1742 Call ok(testObj.with = 10, "testObj.with = " & testObj.with & " expected 10")
1743 Call ok(testObj.redim = 10, "testObj.redim = " & testObj.redim & " expected 10")
1744 Call ok(testObj.preserve = 10, "testObj.preserve = " & testObj.preserve & " expected 10")
1745 Call ok(testObj.property = 10, "testObj.property = " & testObj.property & " expected 10")
1746 Call ok(testObj.me = 10, "testObj.me = " & testObj.me & " expected 10")
1747 Call ok(testObj.stop = 10, "testObj.stop = " & testObj.stop & " expected 10")
1748 end sub
1749 call test_dotIdentifiers
1751 ' Test End statements not required to be preceded by a newline or separator
1752 Sub EndTestSub
1753 x = 1 End Sub
1755 Sub EndTestSubWithCall
1756 x = 1
1757 Call ok(x = 1, "x = " & x)End Sub
1758 Call EndTestSubWithCall()
1760 Function EndTestFunc(x)
1761 Call ok(x > 0, "x = " & x)End Function
1762 EndTestFunc(1)
1764 Class EndTestClassWithStorageId
1765 Public x End Class
1767 Class EndTestClassWithDim
1768 Dim x End Class
1770 Class EndTestClassWithFunc
1771 Function test(ByVal x)
1772 x = 0 End Function End Class
1774 Class EndTestClassWithProperty
1775 Public x
1776 Public default Property Get defprop
1777 defprop = x End Property End Class
1779 class TestPropSyntax
1780 public prop
1782 function getProp()
1783 set getProp = prop
1784 end function
1786 public default property get def()
1787 def = ""
1788 end property
1789 end class
1791 Class TestPropParam
1792 Public oDict
1793 Public gotNothing
1794 Public m_obj
1796 Public Property Set bar(obj)
1797 Set m_obj = obj
1798 End Property
1799 Public Property Set foo(par,obj)
1800 Set m_obj = obj
1801 if obj is Nothing Then gotNothing = True
1802 oDict = par
1803 End Property
1804 Public Property Let Key(oldKey,newKey)
1805 oDict = oldKey & newKey
1806 End Property
1807 Public Property Let three(uno,due,tre)
1808 oDict = uno & due & tre
1809 End Property
1810 Public Property Let ten(a,b,c,d,e,f,g,h,i,j)
1811 oDict = a & b & c & d & e & f & g & h & i & j
1812 End Property
1813 End Class
1815 Set x = new TestPropParam
1816 x.key("old") = "new"
1817 call ok(x.oDict = "oldnew","x.oDict = " & x.oDict & " expected oldnew")
1818 x.three(1,2) = 3
1819 call ok(x.oDict = "123","x.oDict = " & x.oDict & " expected 123")
1820 x.ten(1,2,3,4,5,6,7,8,9) = 0
1821 call ok(x.oDict = "1234567890","x.oDict = " & x.oDict & " expected 1234567890")
1822 Set x.bar = Nothing
1823 call ok(x.gotNothing=Empty,"x.gotNothing = " & x.gotNothing & " expected Empty")
1824 Set x.foo("123") = Nothing
1825 call ok(x.oDict = "123","x.oDict = " & x.oDict & " expected 123")
1826 call ok(x.gotNothing=True,"x.gotNothing = " & x.gotNothing & " expected true")
1828 set x = new TestPropSyntax
1829 set x.prop = new TestPropSyntax
1830 set x.prop.prop = new TestPropSyntax
1831 x.prop.prop.prop = 2
1832 call ok(x.getProp().getProp.prop = 2, "x.getProp().getProp.prop = " & x.getProp().getProp.prop)
1833 x.getprop.getprop().prop = 3
1834 call ok(x.getProp.prop.prop = 3, "x.getProp.prop.prop = " & x.getProp.prop.prop)
1835 set x.getprop.getprop().prop = new emptyclass
1836 set obj = new emptyclass
1837 set x.getprop.getprop().prop = obj
1838 call ok(x.getprop.getprop().prop is obj, "x.getprop.getprop().prop is not obj (emptyclass)")
1840 ok getVT(x) = "VT_DISPATCH*", "getVT(x) = " & getVT(x)
1841 todo_wine_ok getVT(x()) = "VT_BSTR", "getVT(x()) = " & getVT(x())
1843 funcCalled = ""
1844 class DefaultSubTest1
1845 Public default Sub init(a)
1846 funcCalled = "init" & a
1847 end sub
1848 end class
1850 Set obj = New DefaultSubTest1
1851 obj.init(1)
1852 call ok(funcCalled = "init1","funcCalled=" & funcCalled)
1853 funcCalled = ""
1854 obj(2)
1855 call ok(funcCalled = "init2","funcCalled=" & funcCalled)
1857 class DefaultSubTest2
1858 Public Default Function init
1859 funcCalled = "init"
1860 end function
1861 end class
1863 Set obj = New DefaultSubTest2
1864 funcCalled = ""
1865 obj.init()
1866 call ok(funcCalled = "init","funcCalled=" & funcCalled)
1867 funcCalled = ""
1868 ' todo this is not yet supported
1869 'funcCalled = ""
1870 'obj()
1871 'call ok(funcCalled = "init","funcCalled=" & funcCalled)
1873 with nothing
1874 end with
1876 set x = new TestPropSyntax
1877 with x
1878 .prop = 1
1879 ok .prop = 1, ".prop = "&.prop
1880 end with
1881 ok x.prop = 1, "x.prop = " & x.prop
1883 with new TestPropSyntax
1884 .prop = 1
1885 ok .prop = 1, ".prop = "&.prop
1886 end with
1888 function testsetresult(x, y)
1889 set testsetresult = new TestPropSyntax
1890 testsetresult.prop = x
1891 y = testsetresult.prop + 1
1892 end function
1894 set x = testsetresult(1, 2)
1895 ok x.prop = 1, "x.prop = " & x.prop
1897 set arr(0) = new TestPropSyntax
1898 arr(0).prop = 1
1899 ok arr(0).prop = 1, "arr(0) = " & arr(0).prop
1901 function recursingfunction(x)
1902 if (x) then exit function
1903 recursingfunction = 2
1904 dim y
1905 y = recursingfunction
1906 call ok(y = 2, "y = " & y)
1907 recursingfunction = 1
1908 call recursingfunction(True)
1909 end function
1910 call ok(recursingfunction(False) = 1, "unexpected return value " & recursingfunction(False))
1912 x = false
1913 function recursingfunction2
1914 if (x) then exit function
1915 recursingfunction2 = 2
1916 dim y
1917 y = recursingfunction2
1918 call ok(y = 2, "y = " & y)
1919 recursingfunction2 = 1
1920 x = true
1921 recursingfunction2()
1922 end function
1923 call ok(recursingfunction2() = 1, "unexpected return value " & recursingfunction2())
1925 function f2(x,y)
1926 end function
1928 f2 1 = 1, 2
1930 function f1(x)
1931 ok x = true, "x = " & x
1932 end function
1934 f1 1 = 1
1935 f1 1 = (1)
1936 f1 not 1 = 0
1938 arr (0) = 2 xor -2
1940 reportSuccess()