michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: * File Name: while-002 michael@0: * ECMA Section: michael@0: * Description: while statement michael@0: * michael@0: * Verify that the while statement is not executed if the while expression is michael@0: * false michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: */ michael@0: var SECTION = "while-002"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "while statement"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is null", michael@0: null, michael@0: "result = \"fail: should not have evaluated statements in while block;break" michael@0: ) ); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is undefined", michael@0: void 0, michael@0: "result = \"fail: should not have evaluated statements in while block; break" michael@0: )); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is 0", michael@0: 0, michael@0: "result = \"fail: should not have evaluated statements in while block; break;" michael@0: )); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is eval(\"\")", michael@0: eval(""), michael@0: "result = \"fail: should not have evaluated statements in while block; break" michael@0: )); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is NaN", michael@0: NaN, michael@0: "result = \"fail: should not have evaluated statements in while block; break" michael@0: )); michael@0: michael@0: test(); michael@0: michael@0: function DoWhileObject( d, e, s ) { michael@0: this.description = d; michael@0: this.whileExpression = e; michael@0: this.statements = s; michael@0: } michael@0: michael@0: function DoWhile( object ) { michael@0: result = "pass"; michael@0: michael@0: while ( expression = object.whileExpression ) { michael@0: eval( object.statements ); michael@0: } michael@0: michael@0: // verify that the while expression was evaluated michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "verify that while expression was evaluated (should be "+ michael@0: object.whileExpression +")", michael@0: "pass", michael@0: (object.whileExpression == expression || michael@0: ( isNaN(object.whileExpression) && isNaN(expression) ) michael@0: ) ? "pass" : "fail" ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: object.description, michael@0: "pass", michael@0: result ); michael@0: }