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-003 michael@0: * ECMA Section: michael@0: * Description: while statement michael@0: * michael@0: * The while expression evaluates to true, Statement returns abrupt completion. michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: */ michael@0: var SECTION = "while-003"; 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 true", michael@0: true, michael@0: "result = \"pass\";" )); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is 1", michael@0: 1, michael@0: "result = \"pass\";" )); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is new Boolean(false)", michael@0: new Boolean(false), michael@0: "result = \"pass\";" )); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is new Object()", michael@0: new Object(), michael@0: "result = \"pass\";" )); michael@0: michael@0: DoWhile( new DoWhileObject( michael@0: "while expression is \"hi\"", michael@0: "hi", michael@0: "result = \"pass\";" )); michael@0: /* michael@0: DoWhile( new DoWhileObject( michael@0: "while expression has a continue in it", michael@0: "true", michael@0: "if ( i == void 0 ) i = 0; result=\"pass\"; if ( ++i == 1 ) {continue;} else {break;} result=\"fail\";" 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 = "fail: statements in while block were not evaluated"; michael@0: michael@0: while ( expression = object.whileExpression ) { michael@0: eval( object.statements ); michael@0: break; 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: }