|
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 |
|
7 /** |
|
8 * File Name: dowhile-002 |
|
9 * ECMA Section: |
|
10 * Description: do...while statements |
|
11 * |
|
12 * Verify that code after a labeled break is not executed. Verify that |
|
13 * a labeled break breaks you out of the whole labeled block, and not |
|
14 * just the current iteration statement. |
|
15 * |
|
16 * Author: christine@netscape.com |
|
17 * Date: 11 August 1998 |
|
18 */ |
|
19 var SECTION = "dowhile-002"; |
|
20 var VERSION = "ECMA_2"; |
|
21 var TITLE = "do...while with a labeled continue statement"; |
|
22 |
|
23 startTest(); |
|
24 writeHeaderToLog( SECTION + " "+ TITLE); |
|
25 |
|
26 LabeledContinue( 0, 1 ); |
|
27 LabeledContinue( 1, 1 ); |
|
28 LabeledContinue( -1, 1 ); |
|
29 LabeledContinue( 5, 5 ); |
|
30 |
|
31 test(); |
|
32 |
|
33 // The labeled statement contains statements after the labeled break. |
|
34 // Verify that the statements after the break are not executed. |
|
35 |
|
36 function LabeledContinue( limit, expect ) { |
|
37 i = 0; |
|
38 result1 = "pass"; |
|
39 result2 = "pass"; |
|
40 |
|
41 woohoo: { |
|
42 do { |
|
43 i++; |
|
44 if ( ! (i < limit) ) { |
|
45 break woohoo; |
|
46 result1 = "fail: evaluated statement after a labeled break"; |
|
47 } |
|
48 } while ( true ); |
|
49 |
|
50 result2 = "failed: broke out of loop, but not out of labeled block"; |
|
51 } |
|
52 |
|
53 new TestCase( |
|
54 SECTION, |
|
55 "do while ( " + i +" < " + limit +" )", |
|
56 expect, |
|
57 i ); |
|
58 |
|
59 new TestCase( |
|
60 SECTION, |
|
61 "breaking out of a do... while loop", |
|
62 "pass", |
|
63 result1 ); |
|
64 |
|
65 |
|
66 new TestCase( |
|
67 SECTION, |
|
68 "breaking out of a labeled do...while loop", |
|
69 "pass", |
|
70 result2 ); |
|
71 } |