|
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-002 |
|
9 * ECMA Section: |
|
10 * Description: while statement |
|
11 * |
|
12 * Verify that the while statement is not executed if the while expression is |
|
13 * false |
|
14 * |
|
15 * Author: christine@netscape.com |
|
16 * Date: 11 August 1998 |
|
17 */ |
|
18 var SECTION = "while-002"; |
|
19 var VERSION = "ECMA_2"; |
|
20 var TITLE = "while statement"; |
|
21 |
|
22 startTest(); |
|
23 writeHeaderToLog( SECTION + " "+ TITLE); |
|
24 |
|
25 DoWhile( new DoWhileObject( |
|
26 "while expression is null", |
|
27 null, |
|
28 "result = \"fail: should not have evaluated statements in while block;break" |
|
29 ) ); |
|
30 |
|
31 DoWhile( new DoWhileObject( |
|
32 "while expression is undefined", |
|
33 void 0, |
|
34 "result = \"fail: should not have evaluated statements in while block; break" |
|
35 )); |
|
36 |
|
37 DoWhile( new DoWhileObject( |
|
38 "while expression is 0", |
|
39 0, |
|
40 "result = \"fail: should not have evaluated statements in while block; break;" |
|
41 )); |
|
42 |
|
43 DoWhile( new DoWhileObject( |
|
44 "while expression is eval(\"\")", |
|
45 eval(""), |
|
46 "result = \"fail: should not have evaluated statements in while block; break" |
|
47 )); |
|
48 |
|
49 DoWhile( new DoWhileObject( |
|
50 "while expression is NaN", |
|
51 NaN, |
|
52 "result = \"fail: should not have evaluated statements in while block; break" |
|
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 = "pass"; |
|
65 |
|
66 while ( expression = object.whileExpression ) { |
|
67 eval( object.statements ); |
|
68 } |
|
69 |
|
70 // verify that the while expression was evaluated |
|
71 |
|
72 new TestCase( |
|
73 SECTION, |
|
74 "verify that while expression was evaluated (should be "+ |
|
75 object.whileExpression +")", |
|
76 "pass", |
|
77 (object.whileExpression == expression || |
|
78 ( isNaN(object.whileExpression) && isNaN(expression) ) |
|
79 ) ? "pass" : "fail" ); |
|
80 |
|
81 new TestCase( |
|
82 SECTION, |
|
83 object.description, |
|
84 "pass", |
|
85 result ); |
|
86 } |