Debian Codegraph @

rhino/testsrc/tests/ecma_2/Statements/while-002.js

raw symbols SCIP
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 gTestfile = 'while-002.js';
7
8 /**
9 * File Name: while-002
10 * ECMA Section:
11 * Description: while statement
12 *
13 * Verify that the while statement is not executed if the while expression is
14 * false
15 *
16 * Author: [email protected]
17 * Date: 11 August 1998
18 */
19 var SECTION = "while-002";
20 var VERSION = "ECMA_2";
21 var TITLE = "while statement";
22
23 startTest();
24 writeHeaderToLog( SECTION + " "+ TITLE);
25
26 DoWhile( new DoWhileObject(
27 "while expression is null",
28 null,
29 "result = \"fail: should not have evaluated statements in while block;break"
30 ) );
31
32 DoWhile( new DoWhileObject(
33 "while expression is undefined",
34 void 0,
35 "result = \"fail: should not have evaluated statements in while block; break"
36 ));
37
38 DoWhile( new DoWhileObject(
39 "while expression is 0",
40 0,
41 "result = \"fail: should not have evaluated statements in while block; break;"
42 ));
43
44 DoWhile( new DoWhileObject(
45 "while expression is eval(\"\")",
46 eval(""),
47 "result = \"fail: should not have evaluated statements in while block; break"
48 ));
49
50 DoWhile( new DoWhileObject(
51 "while expression is NaN",
52 NaN,
53 "result = \"fail: should not have evaluated statements in while block; break"
54 ));
55
56 test();
57
58 function DoWhileObject( d, e, s ) {
59 this.description = d;
60 this.whileExpression = e;
61 this.statements = s;
62 }
63
64 function DoWhile( object ) {
65 result = "pass";
66
67 while ( expression = object.whileExpression ) {
68 eval( object.statements );
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 }