1/**
2 *  File Name:          while-002
3 *  ECMA Section:
4 *  Description:        while statement
5 *
6 *  Verify that the while statement is not executed if the while expression is
7 *  false
8 *
9 *  Author:             christine@netscape.com
10 *  Date:               11 August 1998
11 */
12    var SECTION = "while-002";
13    var VERSION = "ECMA_2";
14    var TITLE   = "while statement";
15
16    startTest();
17    writeHeaderToLog( SECTION + " "+ TITLE);
18
19    var tc = 0;
20    var testcases = new Array();
21
22    DoWhile( new DoWhileObject(
23                "while expression is null",
24                null,
25                "result = \"fail: should not have evaluated statements in while block;break"
26               ) );
27
28    DoWhile( new DoWhileObject(
29                "while expression is undefined",
30                void 0,
31                "result = \"fail: should not have evaluated statements in while block; break"
32             ));
33
34    DoWhile( new DoWhileObject(
35             "while expression is 0",
36             0,
37             "result = \"fail: should not have evaluated statements in while block; break;"
38             ));
39
40    DoWhile( new DoWhileObject(
41             "while expression is eval(\"\")",
42             eval(""),
43            "result = \"fail: should not have evaluated statements in while block; break"
44            ));
45
46    DoWhile( new DoWhileObject(
47            "while expression is NaN",
48            NaN,
49            "result = \"fail: should not have evaluated statements in while block; break"
50            ));
51
52    test();
53
54    function DoWhileObject( d, e, s ) {
55        this.description = d;
56        this.whileExpression = e;
57        this.statements = s;
58    }
59
60    function DoWhile( object ) {
61        result = "pass";
62
63        while ( expression = object.whileExpression ) {
64            eval( object.statements );
65        }
66
67        // verify that the while expression was evaluated
68
69        testcases[tc++] = new TestCase(
70            SECTION,
71            "verify that while expression was evaluated (should be "+
72                object.whileExpression +")",
73            "pass",
74            (object.whileExpression == expression ||
75               ( isNaN(object.whileExpression) && isNaN(expression) )
76             ) ? "pass" : "fail" );
77
78        testcases[tc++] = new TestCase(
79            SECTION,
80            object.description,
81            "pass",
82            result );
83    }