|
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-004 |
|
9 * ECMA Section: |
|
10 * Description: do...while statements |
|
11 * |
|
12 * Test a labeled do...while. Break out of the loop with no label |
|
13 * should break out of the loop, but not out of the label. |
|
14 * |
|
15 * Author: christine@netscape.com |
|
16 * Date: 11 August 1998 |
|
17 */ |
|
18 var SECTION = "dowhile-004"; |
|
19 var VERSION = "ECMA_2"; |
|
20 var TITLE = "do...while with a labeled continue statement"; |
|
21 |
|
22 startTest(); |
|
23 writeHeaderToLog( SECTION + " "+ TITLE); |
|
24 |
|
25 DoWhile( 0, 1 ); |
|
26 DoWhile( 1, 1 ); |
|
27 DoWhile( -1, 1 ); |
|
28 DoWhile( 5, 5 ); |
|
29 |
|
30 test(); |
|
31 |
|
32 function DoWhile( limit, expect ) { |
|
33 i = 0; |
|
34 result1 = "pass"; |
|
35 result2 = "failed: broke out of labeled statement unexpectedly"; |
|
36 |
|
37 foo: { |
|
38 do { |
|
39 i++; |
|
40 if ( ! (i < limit) ) { |
|
41 break; |
|
42 result1 = "fail: evaluated statement after a labeled break"; |
|
43 } |
|
44 } while ( true ); |
|
45 |
|
46 result2 = "pass"; |
|
47 } |
|
48 |
|
49 new TestCase( |
|
50 SECTION, |
|
51 "do while ( " + i +" < " + limit +" )", |
|
52 expect, |
|
53 i ); |
|
54 |
|
55 new TestCase( |
|
56 SECTION, |
|
57 "breaking out of a do... while loop", |
|
58 "pass", |
|
59 result1 ); |
|
60 |
|
61 |
|
62 new TestCase( |
|
63 SECTION, |
|
64 "breaking out of a labeled do...while loop", |
|
65 "pass", |
|
66 result2 ); |
|
67 } |