|
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-006 |
|
9 * ECMA Section: |
|
10 * Description: do...while statements |
|
11 * |
|
12 * A general do...while test. |
|
13 * |
|
14 * Author: christine@netscape.com |
|
15 * Date: 26 August 1998 |
|
16 */ |
|
17 var SECTION = "dowhile-006"; |
|
18 var VERSION = "ECMA_2"; |
|
19 var TITLE = "do...while"; |
|
20 |
|
21 startTest(); |
|
22 writeHeaderToLog( SECTION + " "+ TITLE); |
|
23 |
|
24 DoWhile( new DoWhileObject( false, false, 10 ) ); |
|
25 DoWhile( new DoWhileObject( true, false, 2 ) ); |
|
26 DoWhile( new DoWhileObject( false, true, 3 ) ); |
|
27 DoWhile( new DoWhileObject( true, true, 4 ) ); |
|
28 |
|
29 test(); |
|
30 |
|
31 function looping( object ) { |
|
32 object.iterations--; |
|
33 |
|
34 if ( object.iterations <= 0 ) { |
|
35 return false; |
|
36 } else { |
|
37 return true; |
|
38 } |
|
39 } |
|
40 function DoWhileObject( breakOut, breakIn, iterations, loops ) { |
|
41 this.iterations = iterations; |
|
42 this.loops = loops; |
|
43 this.breakOut = breakOut; |
|
44 this.breakIn = breakIn; |
|
45 this.looping = looping; |
|
46 } |
|
47 function DoWhile( object ) { |
|
48 var result1 = false; |
|
49 var result2 = false; |
|
50 |
|
51 outie: { |
|
52 innie: { |
|
53 do { |
|
54 if ( object.breakOut ) |
|
55 break outie; |
|
56 |
|
57 if ( object.breakIn ) |
|
58 break innie; |
|
59 |
|
60 } while ( looping(object) ); |
|
61 |
|
62 // statements should be executed if: |
|
63 // do...while exits normally |
|
64 // do...while exits abruptly with no label |
|
65 |
|
66 result1 = true; |
|
67 |
|
68 } |
|
69 |
|
70 // statements should be executed if: |
|
71 // do...while breaks out with label "innie" |
|
72 // do...while exits normally |
|
73 // do...while does not break out with "outie" |
|
74 |
|
75 result2 = true; |
|
76 } |
|
77 |
|
78 new TestCase( |
|
79 SECTION, |
|
80 "hit code after loop in inner loop", |
|
81 ( object.breakIn || object.breakOut ) ? false : true , |
|
82 result1 ); |
|
83 |
|
84 new TestCase( |
|
85 SECTION, |
|
86 "hit code after loop in outer loop", |
|
87 ( object.breakOut ) ? false : true, |
|
88 result2 ); |
|
89 } |