|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 * File Name: while-003 |
|
9 * ECMA Section: |
|
10 * Description: while statement |
|
11 * |
|
12 * The while expression evaluates to true, Statement returns abrupt completion. |
|
13 * |
|
14 * Author: christine@netscape.com |
|
15 * Date: 11 August 1998 |
|
16 */ |
|
17 var SECTION = "while-003"; |
|
18 var VERSION = "ECMA_2"; |
|
19 var TITLE = "while statement"; |
|
20 |
|
21 startTest(); |
|
22 writeHeaderToLog( SECTION + " "+ TITLE); |
|
23 |
|
24 DoWhile( new DoWhileObject( |
|
25 "while expression is true", |
|
26 true, |
|
27 "result = \"pass\";" )); |
|
28 |
|
29 DoWhile( new DoWhileObject( |
|
30 "while expression is 1", |
|
31 1, |
|
32 "result = \"pass\";" )); |
|
33 |
|
34 DoWhile( new DoWhileObject( |
|
35 "while expression is new Boolean(false)", |
|
36 new Boolean(false), |
|
37 "result = \"pass\";" )); |
|
38 |
|
39 DoWhile( new DoWhileObject( |
|
40 "while expression is new Object()", |
|
41 new Object(), |
|
42 "result = \"pass\";" )); |
|
43 |
|
44 DoWhile( new DoWhileObject( |
|
45 "while expression is \"hi\"", |
|
46 "hi", |
|
47 "result = \"pass\";" )); |
|
48 /* |
|
49 DoWhile( new DoWhileObject( |
|
50 "while expression has a continue in it", |
|
51 "true", |
|
52 "if ( i == void 0 ) i = 0; result=\"pass\"; if ( ++i == 1 ) {continue;} else {break;} result=\"fail\";" |
|
53 )); |
|
54 */ |
|
55 test(); |
|
56 |
|
57 function DoWhileObject( d, e, s ) { |
|
58 this.description = d; |
|
59 this.whileExpression = e; |
|
60 this.statements = s; |
|
61 } |
|
62 |
|
63 function DoWhile( object ) { |
|
64 result = "fail: statements in while block were not evaluated"; |
|
65 |
|
66 while ( expression = object.whileExpression ) { |
|
67 eval( object.statements ); |
|
68 break; |
|
69 } |
|
70 |
|
71 // verify that the while expression was evaluated |
|
72 |
|
73 new TestCase( |
|
74 SECTION, |
|
75 "verify that while expression was evaluated (should be "+ |
|
76 object.whileExpression +")", |
|
77 "pass", |
|
78 (object.whileExpression == expression || |
|
79 ( isNaN(object.whileExpression) && isNaN(expression) ) |
|
80 ) ? "pass" : "fail" ); |
|
81 |
|
82 new TestCase( |
|
83 SECTION, |
|
84 object.description, |
|
85 "pass", |
|
86 result ); |
|
87 } |