jscript: Always use jsval-based to_number implementation.
[wine] / dlls / vbscript / tests / lang.vbs
1 '
2 ' Copyright 2011 Jacek Caban for CodeWeavers
3 '
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.
8 '
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.
13 '
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
17 '
18
19 Option Explicit
20
21 dim x, y, z
22
23 call ok(true, "true is not true?")
24 ok true, "true is not true?"
25 call ok((true), "true is not true?")
26
27 ok not false, "not false but not true?"
28 ok not not true, "not not true but not true?"
29
30 Call ok(true = true, "true = true is false")
31 Call ok(false = false, "false = false is false")
32 Call ok(not (true = false), "true = false is true")
33 Call ok("x" = "x", """x"" = ""x"" is false")
34 Call ok(empty = empty, "empty = empty is false")
35 Call ok(empty = "", "empty = """" is false")
36 Call ok(0 = 0.0, "0 <> 0.0")
37 Call ok(16 = &h10&, "16 <> &h10&")
38 Call ok(010 = 10, "010 <> 10")
39 Call ok(10. = 10, "10. <> 10")
40 Call ok(&hffFFffFF& = -1, "&hffFFffFF& <> -1")
41 Call ok(&hffFFffFF& = -1, "&hffFFffFF& <> -1")
42 Call ok(--1 = 1, "--1 = " & --1)
43 Call ok(-empty = 0, "-empty = " & (-empty))
44 Call ok(true = -1, "! true = -1")
45 Call ok(false = 0, "false <> 0")
46 Call ok(&hff = 255, "&hff <> 255")
47 Call ok(&Hff = 255, "&Hff <> 255")
48
49 x = "xx"
50 Call ok(x = "xx", "x = " & x & " expected ""xx""")
51
52 Call ok(true <> false, "true <> false is false")
53 Call ok(not (true <> true), "true <> true is true")
54 Call ok(not ("x" <> "x"), """x"" <> ""x"" is true")
55 Call ok(not (empty <> empty), "empty <> empty is true")
56 Call ok(x <> "x", "x = ""x""")
57 Call ok("true" <> true, """true"" = true is true")
58
59 Call ok("" = true = false, """"" = true = false is false")
60 Call ok(not(false = true = ""), "false = true = """" is true")
61 Call ok(not (false = false <> false = false), "false = false <> false = false is true")
62 Call ok(not ("" <> false = false), """"" <> false = false is true")
63
64 Call ok(getVT(false) = "VT_BOOL", "getVT(false) is not VT_BOOL")
65 Call ok(getVT(true) = "VT_BOOL", "getVT(true) is not VT_BOOL")
66 Call ok(getVT("") = "VT_BSTR", "getVT("""") is not VT_BSTR")
67 Call ok(getVT("test") = "VT_BSTR", "getVT(""test"") is not VT_BSTR")
68 Call ok(getVT(Empty) = "VT_EMPTY", "getVT(Empty) is not VT_EMPTY")
69 Call ok(getVT(null) = "VT_NULL", "getVT(null) is not VT_NULL")
70 Call ok(getVT(0) = "VT_I2", "getVT(0) is not VT_I2")
71 Call ok(getVT(1) = "VT_I2", "getVT(1) is not VT_I2")
72 Call ok(getVT(0.5) = "VT_R8", "getVT(0.5) is not VT_R8")
73 Call ok(getVT(0.0) = "VT_R8", "getVT(0.0) is not VT_R8")
74 Call ok(getVT(2147483647) = "VT_I4", "getVT(2147483647) is not VT_I4")
75 Call ok(getVT(2147483648) = "VT_R8", "getVT(2147483648) is not VT_R8")
76 Call ok(getVT(&h10&) = "VT_I2", "getVT(&h10&) is not VT_I2")
77 Call ok(getVT(&h10000&) = "VT_I4", "getVT(&h10000&) is not VT_I4")
78 Call ok(getVT(&H10000&) = "VT_I4", "getVT(&H10000&) is not VT_I4")
79 Call ok(getVT(&hffFFffFF&) = "VT_I2", "getVT(&hffFFffFF&) is not VT_I2")
80 Call ok(getVT(1 & 100000) = "VT_BSTR", "getVT(1 & 100000) is not VT_BSTR")
81 Call ok(getVT(-empty) = "VT_I2", "getVT(-empty) = " & getVT(-empty))
82 Call ok(getVT(-null) = "VT_NULL", "getVT(-null) = " & getVT(-null))
83 Call ok(getVT(y) = "VT_EMPTY*", "getVT(y) = " & getVT(y))
84 Call ok(getVT(nothing) = "VT_DISPATCH", "getVT(nothing) = " & getVT(nothing))
85 set x = nothing
86 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=nothing) = " & getVT(x))
87 x = true
88 Call ok(getVT(x) = "VT_BOOL*", "getVT(x) = " & getVT(x))
89 Call ok(getVT(false or true) = "VT_BOOL", "getVT(false) is not VT_BOOL")
90 x = "x"
91 Call ok(getVT(x) = "VT_BSTR*", "getVT(x) is not VT_BSTR*")
92 x = 0.0
93 Call ok(getVT(x) = "VT_R8*", "getVT(x) = " & getVT(x))
94
95 Call ok(isNullDisp(nothing), "nothing is not nulldisp?")
96
97 x = "xx"
98 Call ok("ab" & "cd" = "abcd", """ab"" & ""cd"" <> ""abcd""")
99 Call ok("ab " & null = "ab ", """ab"" & null = " & ("ab " & null))
100 Call ok("ab " & empty = "ab ", """ab"" & empty = " & ("ab " & empty))
101 Call ok(1 & 100000 = "1100000", "1 & 100000 = " & (1 & 100000))
102 Call ok("ab" & x = "abxx", """ab"" & x = " & ("ab"&x))
103
104 if(isEnglishLang) then
105     Call ok("" & true = "True", """"" & true = " & true)
106     Call ok(true & false = "TrueFalse", "true & false = " & (true & false))
107 end if
108
109 call ok(true and true, "true and true is not true")
110 call ok(true and not false, "true and not false is not true")
111 call ok(not (false and true), "not (false and true) is not true")
112 call ok(getVT(null and true) = "VT_NULL", "getVT(null and true) = " & getVT(null and true))
113
114 call ok(false or true, "false or uie is false?")
115 call ok(not (false or false), "false or false is not false?")
116 call ok(false and false or true, "false and false or true is false?")
117 call ok(true or false and false, "true or false and false is false?")
118 call ok(null or true, "null or true is false")
119
120 call ok(true xor false, "true xor false is false?")
121 call ok(not (false xor false), "false xor false is true?")
122 call ok(not (true or false xor true), "true or false xor true is true?")
123 call ok(not (true xor false or true), "true xor false or true is true?")
124
125 call ok(false eqv false, "false does not equal false?")
126 call ok(not (false eqv true), "false equals true?")
127 call ok(getVT(false eqv null) = "VT_NULL", "getVT(false eqv null) = " & getVT(false eqv null))
128
129 call ok(true imp true, "true does not imp true?")
130 call ok(false imp false, "false does not imp false?")
131 call ok(not (true imp false), "true imp false?")
132 call ok(false imp null, "false imp null is false?")
133
134 Call ok(2 >= 1, "! 2 >= 1")
135 Call ok(2 >= 2, "! 2 >= 2")
136 Call ok(not(true >= 2), "true >= 2 ?")
137 Call ok(2 > 1, "! 2 > 1")
138 Call ok(false > true, "! false < true")
139 Call ok(0 > true, "! 0 > true")
140 Call ok(not (true > 0), "true > 0")
141 Call ok(not (0 > 1 = 1), "0 > 1 = 1")
142 Call ok(1 < 2, "! 1 < 2")
143 Call ok(1 = 1 < 0, "! 1 = 1 < 0")
144 Call ok(1 <= 2, "! 1 <= 2")
145 Call ok(2 <= 2, "! 2 <= 2")
146
147 Call ok(isNull(0 = null), "'(0 = null)' is not null")
148 Call ok(isNull(null = 1), "'(null = 1)' is not null")
149 Call ok(isNull(0 > null), "'(0 > null)' is not null")
150 Call ok(isNull(null > 1), "'(null > 1)' is not null")
151 Call ok(isNull(0 < null), "'(0 < null)' is not null")
152 Call ok(isNull(null < 1), "'(null < 1)' is not null")
153 Call ok(isNull(0 <> null), "'(0 <> null)' is not null")
154 Call ok(isNull(null <> 1), "'(null <> 1)' is not null")
155 Call ok(isNull(0 >= null), "'(0 >= null)' is not null")
156 Call ok(isNull(null >= 1), "'(null >= 1)' is not null")
157 Call ok(isNull(0 <= null), "'(0 <= null)' is not null")
158 Call ok(isNull(null <= 1), "'(null <= 1)' is not null")
159
160 x = 3
161 Call ok(2+2 = 4, "2+2 = " & (2+2))
162 Call ok(false + 6 + true = 5, "false + 6 + true <> 5")
163 Call ok(getVT(2+null) = "VT_NULL", "getVT(2+null) = " & getVT(2+null))
164 Call ok(2+empty = 2, "2+empty = " & (2+empty))
165 Call ok(x+x = 6, "x+x = " & (x+x))
166
167 Call ok(5-1 = 4, "5-1 = " & (5-1))
168 Call ok(3+5-true = 9, "3+5-true <> 9")
169 Call ok(getVT(2-null) = "VT_NULL", "getVT(2-null) = " & getVT(2-null))
170 Call ok(2-empty = 2, "2-empty = " & (2-empty))
171 Call ok(2-x = -1, "2-x = " & (2-x))
172
173 Call ok(9 Mod 6 = 3, "9 Mod 6 = " & (9 Mod 6))
174 Call ok(11.6 Mod 5.5 = False, "11.6 Mod 5.5 = " & (11.6 Mod 5.5 = 0.6))
175 Call ok(7 Mod 4+2 = 5, "7 Mod 4+2 <> 5")
176 Call ok(getVT(2 mod null) = "VT_NULL", "getVT(2 mod null) = " & getVT(2 mod null))
177 Call ok(getVT(null mod 2) = "VT_NULL", "getVT(null mod 2) = " & getVT(null mod 2))
178 'FIXME: Call ok(empty mod 2 = 0, "empty mod 2 = " & (empty mod 2))
179
180 Call ok(5 \ 2 = 2, "5 \ 2 = " & (5\2))
181 Call ok(4.6 \ 1.5 = 2, "4.6 \ 1.5 = " & (4.6\1.5))
182 Call ok(4.6 \ 1.49 = 5, "4.6 \ 1.49 = " & (4.6\1.49))
183 Call ok(2+3\4 = 2, "2+3\4 = " & (2+3\4))
184
185 Call ok(2*3 = 6, "2*3 = " & (2*3))
186 Call ok(3/2 = 1.5, "3/2 = " & (3/2))
187 Call ok(5\4/2 = 2, "5\4/2 = " & (5\2/1))
188 Call ok(12/3\2 = 2, "12/3\2 = " & (12/3\2))
189
190 Call ok(2^3 = 8, "2^3 = " & (2^3))
191 Call ok(2^3^2 = 64, "2^3^2 = " & (2^3^2))
192 Call ok(-3^2 = 9, "-3^2 = " & (-3^2))
193 Call ok(2*3^2 = 18, "2*3^2 = " & (2*3^2))
194
195 x =_
196     3
197 x _
198     = 3
199
200 x = 3
201
202 if true then y = true : x = y
203 ok x, "x is false"
204
205 x = true : if false then x = false
206 ok x, "x is false, if false called?"
207
208 if not false then x = true
209 ok x, "x is false, if not false not called?"
210
211 if not false then x = "test" : x = true
212 ok x, "x is false, if not false not called?"
213
214 if false then x = y : call ok(false, "if false .. : called")
215
216 if false then x = y : call ok(false, "if false .. : called") else x = "else"
217 Call ok(x = "else", "else not called?")
218
219 if true then x = y else y = x : Call ok(false, "in else?")
220
221 if false then :
222
223 if false then x = y : if true then call ok(false, "embedded if called")
224
225 if false then x=1 else x=2 end if
226
227 if false then
228     ok false, "if false called"
229 end if
230
231 x = true
232 if x then
233     x = false
234 end if
235 Call ok(not x, "x is false, if not evaluated?")
236
237 x = false
238 If false Then
239    Call ok(false, "inside if false")
240 Else
241    x = true
242 End If
243 Call ok(x, "else not called?")
244
245 x = false
246 If false Then
247    Call ok(false, "inside if false")
248 ElseIf not True Then
249    Call ok(false, "inside elseif not true")
250 Else
251    x = true
252 End If
253 Call ok(x, "else not called?")
254
255 x = false
256 If false Then
257    Call ok(false, "inside if false")
258    x = 1
259    y = 10+x
260 ElseIf not False Then
261    x = true
262 Else
263    Call ok(false, "inside else not true")
264 End If
265 Call ok(x, "elseif not called?")
266
267 x = false
268 If false Then
269    Call ok(false, "inside if false")
270 ElseIf not False Then
271    x = true
272 End If
273 Call ok(x, "elseif not called?")
274
275 x = false
276 if 1 then x = true
277 Call ok(x, "if 1 not run?")
278
279 x = false
280 if &h10000& then x = true
281 Call ok(x, "if &h10000& not run?")
282
283 x = false
284 y = false
285 while not (x and y)
286     if x then
287         y = true
288     end if
289     x = true
290 wend
291 call ok((x and y), "x or y is false after while")
292
293 while false
294 wend
295
296 x = false
297 y = false
298 do while not (x and y)
299     if x then
300         y = true
301     end if
302     x = true
303 loop
304 call ok((x and y), "x or y is false after while")
305
306 do while false
307 loop
308
309 do while true
310     exit do
311     ok false, "exit do didn't work"
312 loop
313
314 x = false
315 y = false
316 do until x and y
317     if x then
318         y = true
319     end if
320     x = true
321 loop
322 call ok((x and y), "x or y is false after do until")
323
324 do until true
325 loop
326
327 do until false
328     exit do
329     ok false, "exit do didn't work"
330 loop
331
332 x = false
333 y = false
334 do
335     if x then
336         y = true
337     end if
338     x = true
339 loop until x and y
340 call ok((x and y), "x or y is false after while")
341
342 do
343 loop until true
344
345 do
346     exit do
347     ok false, "exit do didn't work"
348 loop until false
349
350 x = false
351 y = false
352 do
353     if x then
354         y = true
355     end if
356     x = true
357 loop while not (x and y)
358 call ok((x and y), "x or y is false after while")
359
360 do
361 loop while false
362
363 do
364     exit do
365     ok false, "exit do didn't work"
366 loop while true
367
368 y = "for1:"
369 for x = 5 to 8
370     y = y & " " & x
371 next
372 Call ok(y = "for1: 5 6 7 8", "y = " & y)
373
374 y = "for2:"
375 for x = 5 to 8 step 2
376     y = y & " " & x
377 next
378 Call ok(y = "for2: 5 7", "y = " & y)
379
380 y = "for3:"
381 x = 2
382 for x = x+3 to 8
383     y = y & " " & x
384 next
385 Call ok(y = "for3: 5 6 7 8", "y = " & y)
386
387 y = "for4:"
388 for x = 5 to 4
389     y = y & " " & x
390 next
391 Call ok(y = "for4:", "y = " & y)
392
393 y = "for5:"
394 for x = 5 to 3 step true
395     y = y & " " & x
396 next
397 Call ok(y = "for5: 5 4 3", "y = " & y)
398
399 y = "for6:"
400 z = 4
401 for x = 5 to z step 3-4
402     y = y & " " & x
403     z = 0
404 next
405 Call ok(y = "for6: 5 4", "y = " & y)
406
407 y = "for7:"
408 z = 1
409 for x = 5 to 8 step z
410     y = y & " " & x
411     z = 2
412 next
413 Call ok(y = "for7: 5 6 7 8", "y = " & y)
414
415 y = "for8:"
416 for x = 5 to 8
417     y = y & " " & x
418     x = x+1
419 next
420 Call ok(y = "for8: 5 7", "y = " & y)
421
422 for x = 1.5 to 1
423     Call ok(false, "for..to called when unexpected")
424 next
425
426 for x = 1 to 100
427     exit for
428     Call ok(false, "exit for not escaped the loop?")
429 next
430
431 do while true
432     for x = 1 to 100
433         exit do
434     next
435 loop
436
437 if null then call ok(false, "if null evaluated")
438
439 while null
440     call ok(false, "while null evaluated")
441 wend
442
443 Call collectionObj.reset()
444 y = 0
445 x = 10
446 for each x in collectionObj
447     y = y+1
448     Call ok(x = y, "x <> y")
449 next
450 Call ok(y = 3, "y = " & y)
451 Call ok(getVT(x) = "VT_EMPTY*", "getVT(x) = " & getVT(x))
452
453 Call collectionObj.reset()
454 y = false
455 for each x in collectionObj
456     if x = 2 then exit for
457     y = 1
458 next
459 Call ok(y = 1, "y = " & y)
460 Call ok(x = 2, "x = " & x)
461
462 x = false
463 select case 3
464     case 2
465         Call ok(false, "unexpected case")
466     case 2
467         Call ok(false, "unexpected case")
468     case 4
469         Call ok(false, "unexpected case")
470     case "test"
471     case "another case"
472         Call ok(false, "unexpected case")
473     case 0, false, 2+1, 10
474         x = true
475     case ok(false, "unexpected case")
476         Call ok(false, "unexpected case")
477     case else
478         Call ok(false, "unexpected case")
479 end select
480 Call ok(x, "wrong case")
481
482 x = false
483 select case 3
484     case 3
485         x = true
486 end select
487 Call ok(x, "wrong case")
488
489 x = false
490 select case 2+2
491     case 3
492         Call ok(false, "unexpected case")
493     case else
494         x = true
495 end select
496 Call ok(x, "wrong case")
497
498 y = "3"
499 x = false
500 select case y
501     case "3"
502         x = true
503     case 3
504         Call ok(false, "unexpected case")
505 end select
506 Call ok(x, "wrong case")
507
508 select case 0
509     case 1
510         Call ok(false, "unexpected case")
511     case "2"
512         Call ok(false, "unexpected case")
513 end select
514
515 select case 0
516 end select
517
518 if false then
519 Sub testsub
520     x = true
521 End Sub
522 end if
523
524 x = false
525 Call testsub
526 Call ok(x, "x is false, testsub not called?")
527
528 Sub SubSetTrue(v)
529     Call ok(not v, "v is not true")
530     v = true
531 End Sub
532
533 x = false
534 SubSetTrue x
535 Call ok(x, "x was not set by SubSetTrue")
536
537 SubSetTrue false
538 Call ok(not false, "false is no longer false?")
539
540 Sub SubSetTrue2(ByRef v)
541     Call ok(not v, "v is not true")
542     v = true
543 End Sub
544
545 x = false
546 SubSetTrue2 x
547 Call ok(x, "x was not set by SubSetTrue")
548
549 Sub TestSubArgVal(ByVal v)
550     Call ok(not v, "v is not false")
551     v = true
552     Call ok(v, "v is not true?")
553 End Sub
554
555 x = false
556 Call TestSubArgVal(x)
557 Call ok(not x, "x is true after TestSubArgVal call?")
558
559 Sub TestSubMultiArgs(a,b,c,d,e)
560     Call ok(a=1, "a = " & a)
561     Call ok(b=2, "b = " & b)
562     Call ok(c=3, "c = " & c)
563     Call ok(d=4, "d = " & d)
564     Call ok(e=5, "e = " & e)
565 End Sub
566
567 Sub TestSubExit(ByRef a)
568     If a Then
569         Exit Sub
570     End If
571     Call ok(false, "Exit Sub not called?")
572 End Sub
573
574 Call TestSubExit(true)
575
576 Sub TestSubExit2
577     for x = 1 to 100
578         Exit Sub
579     next
580 End Sub
581 Call TestSubExit2
582
583 TestSubMultiArgs 1, 2, 3, 4, 5
584 Call TestSubMultiArgs(1, 2, 3, 4, 5)
585
586 Sub TestSubLocalVal
587     x = false
588     Call ok(not x, "local x is not false?")
589     Dim x
590     Dim a,b, c
591 End Sub
592
593 x = true
594 y = true
595 Call TestSubLocalVal
596 Call ok(x, "global x is not true?")
597
598 Public Sub TestPublicSub
599 End Sub
600 Call TestPublicSub
601
602 Private Sub TestPrivateSub
603 End Sub
604 Call TestPrivateSub
605
606 if false then
607 Function testfunc
608     x = true
609 End Function
610 end if
611
612 x = false
613 Call TestFunc
614 Call ok(x, "x is false, testfunc not called?")
615
616 Function FuncSetTrue(v)
617     Call ok(not v, "v is not true")
618     v = true
619 End Function
620
621 x = false
622 FuncSetTrue x
623 Call ok(x, "x was not set by FuncSetTrue")
624
625 FuncSetTrue false
626 Call ok(not false, "false is no longer false?")
627
628 Function FuncSetTrue2(ByRef v)
629     Call ok(not v, "v is not true")
630     v = true
631 End Function
632
633 x = false
634 FuncSetTrue2 x
635 Call ok(x, "x was not set by FuncSetTrue")
636
637 Function TestFuncArgVal(ByVal v)
638     Call ok(not v, "v is not false")
639     v = true
640     Call ok(v, "v is not true?")
641 End Function
642
643 x = false
644 Call TestFuncArgVal(x)
645 Call ok(not x, "x is true after TestFuncArgVal call?")
646
647 Function TestFuncMultiArgs(a,b,c,d,e)
648     Call ok(a=1, "a = " & a)
649     Call ok(b=2, "b = " & b)
650     Call ok(c=3, "c = " & c)
651     Call ok(d=4, "d = " & d)
652     Call ok(e=5, "e = " & e)
653 End Function
654
655 TestFuncMultiArgs 1, 2, 3, 4, 5
656 Call TestFuncMultiArgs(1, 2, 3, 4, 5)
657
658 Function TestFuncLocalVal
659     x = false
660     Call ok(not x, "local x is not false?")
661     Dim x
662 End Function
663
664 x = true
665 y = true
666 Call TestFuncLocalVal
667 Call ok(x, "global x is not true?")
668
669 Function TestFuncExit(ByRef a)
670     If a Then
671         Exit Function
672     End If
673     Call ok(false, "Exit Function not called?")
674 End Function
675
676 Call TestFuncExit(true)
677
678 Function TestFuncExit2(ByRef a)
679     For x = 1 to 100
680         For y = 1 to 100
681             Exit Function
682         Next
683     Next
684     Call ok(false, "Exit Function not called?")
685 End Function
686
687 Call TestFuncExit2(true)
688
689 Sub SubParseTest
690 End Sub : x = false
691 Call SubParseTest
692
693 Function FuncParseTest
694 End Function : x = false
695
696 Function ReturnTrue
697      ReturnTrue = false
698      ReturnTrue = true
699 End Function
700
701 Call ok(ReturnTrue(), "ReturnTrue returned false?")
702
703 Function SetVal(ByRef x, ByVal v)
704     x = v
705     SetVal = x
706     Exit Function
707 End Function
708
709 x = false
710 ok SetVal(x, true), "SetVal returned false?"
711 Call ok(x, "x is not set to true by SetVal?")
712
713 Public Function TestPublicFunc
714 End Function
715 Call TestPublicFunc
716
717 Private Function TestPrivateFunc
718 End Function
719 Call TestPrivateFunc
720
721 ' Stop has an effect only in debugging mode
722 Stop
723
724 set x = testObj
725 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=testObj) = " & getVT(x))
726
727 Dim obj
728 Set obj = New EmptyClass
729 Call ok(getVT(obj) = "VT_DISPATCH*", "getVT(obj) = " & getVT(obj))
730
731 Class EmptyClass
732 End Class
733
734 Set x = obj
735 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x) = " & getVT(x))
736
737 Class TestClass
738     Public publicProp
739
740     Private privateProp
741
742     Public Function publicFunction()
743         privateSub()
744         publicFunction = 4
745     End Function
746
747     Public Property Get gsProp()
748         gsProp = privateProp
749         funcCalled = "gsProp get"
750         exit property
751         Call ok(false, "exit property not returned?")
752     End Property
753
754     Public Default Property Get DefValGet
755         DefValGet = privateProp
756         funcCalled = "GetDefVal"
757     End Property
758
759     Public Property Let DefValGet(x)
760     End Property
761
762     Public publicProp2
763
764     Public Sub publicSub
765     End Sub
766
767     Public Property Let gsProp(val)
768         privateProp = val
769         funcCalled = "gsProp let"
770         exit property
771         Call ok(false, "exit property not returned?")
772     End Property
773
774     Public Property Set gsProp(val)
775         funcCalled = "gsProp set"
776         exit property
777         Call ok(false, "exit property not returned?")
778     End Property
779
780     Public Sub setPrivateProp(x)
781         privateProp = x
782     End Sub
783
784     Function getPrivateProp
785         getPrivateProp = privateProp
786     End Function
787
788     Private Sub privateSub
789     End Sub
790
791     Public Sub Class_Initialize
792         publicProp2 = 2
793         privateProp = true
794     End Sub
795 End Class
796
797 Call testDisp(new testClass)
798
799 Set obj = New TestClass
800
801 Call ok(obj.publicFunction = 4, "obj.publicFunction = " & obj.publicFunction)
802 Call ok(obj.publicFunction() = 4, "obj.publicFunction() = " & obj.publicFunction())
803
804 obj.publicSub()
805 Call obj.publicSub
806 Call obj.publicFunction()
807
808 Call ok(getVT(obj.publicProp) = "VT_EMPTY", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
809 obj.publicProp = 3
810 Call ok(obj.publicProp = 3, "obj.publicProp = " & obj.publicProp)
811 obj.publicProp() = 3
812
813 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
814 Call obj.setPrivateProp(6)
815 Call ok(obj.getPrivateProp = 6, "obj.getPrivateProp = " & obj.getPrivateProp)
816
817 Dim funcCalled
818 funcCalled = ""
819 Call ok(obj.gsProp = 6, "obj.gsProp = " & obj.gsProp)
820 Call ok(funcCalled = "gsProp get", "funcCalled = " & funcCalled)
821 obj.gsProp = 3
822 Call ok(funcCalled = "gsProp let", "funcCalled = " & funcCalled)
823 Call ok(obj.getPrivateProp = 3, "obj.getPrivateProp = " & obj.getPrivateProp)
824 Set obj.gsProp = New testclass
825 Call ok(funcCalled = "gsProp set", "funcCalled = " & funcCalled)
826
827 x = obj
828 Call ok(x = 3, "(x = obj) = " & x)
829 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
830 funcCalled = ""
831 Call ok(obj = 3, "(x = obj) = " & obj)
832 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
833
834 Call obj.Class_Initialize
835 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
836
837 x = (New testclass).publicProp
838
839 Class TermTest
840     Public Sub Class_Terminate()
841         funcCalled = "terminate"
842     End Sub
843 End Class
844
845 Set obj = New TermTest
846 funcCalled = ""
847 Set obj = Nothing
848 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
849
850 Set obj = New TermTest
851 funcCalled = ""
852 Call obj.Class_Terminate
853 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
854 funcCalled = ""
855 Set obj = Nothing
856 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
857
858 Call (New testclass).publicSub()
859 Call (New testclass).publicSub
860
861 x = "following ':' is correct syntax" :
862 x = "following ':' is correct syntax" :: :
863 :: x = "also correct syntax"
864 rem another ugly way for comments
865 x = "rem as simplestatement" : rem rem comment
866 :
867
868 Set obj = new EmptyClass
869 Set x = obj
870 Set y = new EmptyClass
871
872 Call ok(obj is x, "obj is not x")
873 Call ok(x is obj, "x is not obj")
874 Call ok(not (obj is y), "obj is not y")
875 Call ok(not obj is y, "obj is not y")
876 Call ok(not (x is Nothing), "x is 1")
877 Call ok(Nothing is Nothing, "Nothing is not Nothing")
878 Call ok(x is obj and true, "x is obj and true is false")
879
880 Class TestMe
881     Public Sub Test(MyMe)
882         Call ok(Me is MyMe, "Me is not MyMe")
883     End Sub
884 End Class
885
886 Set obj = New TestMe
887 Call obj.test(obj)
888
889 Call ok(getVT(test) = "VT_DISPATCH", "getVT(test) = " & getVT(test))
890 Call ok(Me is Test, "Me is not Test")
891
892 Const c1 = 1, c2 = 2
893 Call ok(c1 = 1, "c1 = " & c1)
894 Call ok(getVT(c1) = "VT_I2", "getVT(c1) = " & getVT(c1))
895
896 if false then Const conststr = "str"
897 Call ok(conststr = "str", "conststr = " & conststr)
898 Call ok(getVT(conststr) = "VT_BSTR", "getVT(conststr) = " & getVT(conststr))
899 Call ok(conststr = "str", "conststr = " & conststr)
900
901 Sub ConstTestSub
902     Const funcconst = 1
903     Call ok(c1 = 1, "c1 = " & c1)
904     Call ok(funcconst = 1, "funcconst = " & funcconst)
905 End Sub
906
907 Call ConstTestSub
908 Dim funcconst
909
910 ' Property may be used as an identifier (although it's a keyword)
911 Sub TestProperty
912     Dim Property
913     PROPERTY = true
914     Call ok(property, "property = " & property)
915
916     for property = 1 to 2
917     next
918 End Sub
919
920 Call TestProperty
921
922 Class Property
923     Public Sub Property()
924     End Sub
925
926     Sub Test(byref property)
927     End Sub
928 End Class
929
930 Class Property2
931     Function Property()
932     End Function
933
934
935     Sub Test(property)
936     End Sub
937
938     Sub Test2(byval property)
939     End Sub
940 End Class
941
942 reportSuccess()