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-004 michael@0: * ECMA Section: michael@0: * Description: while statement michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: */ michael@0: var SECTION = "while-004"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "while statement"; michael@0: var BUGNUMBER="316725"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: DoWhile_1(); michael@0: DoWhile_2(); michael@0: DoWhile_3(); michael@0: DoWhile_4(); michael@0: DoWhile_5(); michael@0: michael@0: test(); michael@0: michael@0: /** michael@0: * Break out of a while by calling return. michael@0: * michael@0: * Tests: 12.6.2 step 6. michael@0: */ michael@0: function dowhile() { michael@0: result = "pass"; michael@0: michael@0: while (true) { michael@0: return result; michael@0: result = "fail: hit code after return statement"; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: function DoWhile_1() { michael@0: description = "return statement in a while block"; michael@0: michael@0: result = dowhile(); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_1" + description, michael@0: "pass", michael@0: result ); michael@0: } michael@0: michael@0: /** michael@0: * While with a labeled continue statement. Verify that statements michael@0: * after the continue statement are not evaluated. michael@0: * michael@0: * Tests: 12.6.2 step 8. michael@0: * michael@0: */ michael@0: function DoWhile_2() { michael@0: var description = "while with a labeled continue statement"; michael@0: var result1 = "pass"; michael@0: var result2 = "fail: did not execute code after loop, but inside label"; michael@0: var i = 0; michael@0: var j = 0; michael@0: michael@0: theloop: michael@0: while( i++ < 10 ) { michael@0: j++; michael@0: continue theloop; michael@0: result1 = "failed: hit code after continue statement"; michael@0: } michael@0: result2 = "pass"; michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_2: " +description + " - code inside the loop, before the continue should be executed ("+j+")", michael@0: true, michael@0: j == 10 ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_2: " +description +" - code after labeled continue should not be executed", michael@0: "pass", michael@0: result1 ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_2: " +description +" - code after loop but inside label should be executed", michael@0: "pass", michael@0: result2 ); michael@0: } michael@0: michael@0: /** michael@0: * While with a labeled break. michael@0: * michael@0: */ michael@0: function DoWhile_3() { michael@0: var description = "while with a labeled break statement"; michael@0: var result1 = "pass"; michael@0: var result2 = "pass"; michael@0: var result3 = "fail: did not get to code after label"; michael@0: michael@0: woohoo: { michael@0: while( true ) { michael@0: break woohoo; michael@0: result1 = "fail: got to code after a break"; michael@0: } michael@0: result2 = "fail: got to code outside of loop but inside label"; michael@0: } michael@0: michael@0: result3 = "pass"; michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_3: " +description +" - verify break out of loop", michael@0: "pass", michael@0: result1 ); michael@0: michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_3: " +description +" - verify break out of label", michael@0: "pass", michael@0: result2 ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_3: " +description + " - verify correct exit from label", michael@0: "pass", michael@0: result3 ); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Labled while with an unlabeled break michael@0: * michael@0: */ michael@0: function DoWhile_4() { michael@0: var description = "labeled while with an unlabeled break"; michael@0: var result1 = "pass"; michael@0: var result2 = "pass"; michael@0: var result3 = "fail: did not evaluate statement after label"; michael@0: michael@0: woohooboy: { michael@0: while( true ) { michael@0: break woohooboy; michael@0: result1 = "fail: got to code after the break"; michael@0: } michael@0: result2 = "fail: broke out of while, but not out of label"; michael@0: } michael@0: result3 = "pass"; michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_4: " +description +" - verify break out of while loop", michael@0: "pass", michael@0: result1 ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_4: " +description + " - verify break out of label", michael@0: "pass", michael@0: result2 ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_4: " +description +" - verify that statements after label are evaluated", michael@0: "pass", michael@0: result3 ); michael@0: } michael@0: michael@0: /** michael@0: * in this case, should behave the same way as michael@0: * michael@0: * michael@0: */ michael@0: function DoWhile_5() { michael@0: var description = "while with a labeled continue statement"; michael@0: var result1 = "pass"; michael@0: var result2 = "fail: did not execute code after loop, but inside label"; michael@0: var i = 0; michael@0: var j = 0; michael@0: michael@0: theloop: { michael@0: j++; michael@0: while( i++ < 10 ) { michael@0: continue; michael@0: result1 = "failed: hit code after continue statement"; michael@0: } michael@0: result2 = "pass"; michael@0: } michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_5: " +description + " - continue should not execute statements above the loop", michael@0: true, michael@0: ( j == 1 ) ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_5: " +description +" - code after labeled continue should not be executed", michael@0: "pass", michael@0: result1 ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "DoWhile_5: " +description +" - code after loop but inside label should be executed", michael@0: "pass", michael@0: result2 ); michael@0: } michael@0: