• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
5 *
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23	Filename:     break.js
24	Description:  'Tests the break statement'
25
26	Author:       Nick Lerissa
27	Date:         March 18, 1998
28*/
29
30	var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31	var VERSION = 'no version';
32    startTest();
33	var TITLE   = 'statements: break';
34
35	writeHeaderToLog("Executing script: break.js");
36	writeHeaderToLog( SECTION + " "+ TITLE);
37
38	var count = 0;
39	var testcases = new Array();
40
41	var i,j;
42
43	for (i = 0; i < 1000; i++)
44	{
45	    if (i == 100) break;
46	}
47
48    // 'breaking out of "for" loop'
49	testcases[count++] = new TestCase ( SECTION, 'breaking out of "for" loop',
50	                                    100, i);
51
52    j = 2000;
53
54    out1:
55	for (i = 0; i < 1000; i++)
56	{
57	    if (i == 100)
58	    {
59	        out2:
60	        for (j = 0; j < 1000; j++)
61	        {
62	            if (j == 500) break out1;
63	        }
64	        j = 2001;
65	    }
66	    j = 2002;
67	}
68
69    // 'breaking out of a "for" loop with a "label"'
70	testcases[count++] = new TestCase ( SECTION, 'breaking out of a "for" loop with a "label"',
71	                                    500, j);
72
73	i = 0;
74
75	while (i < 1000)
76	{
77	    if (i == 100) break;
78	    i++;
79	}
80
81	// 'breaking out of a "while" loop'
82	testcases[count++] = new TestCase ( SECTION, 'breaking out of a "while" loop',
83	                                    100, i );
84
85
86    j = 2000;
87    i = 0;
88
89    out3:
90	while (i < 1000)
91	{
92	    if (i == 100)
93	    {
94	        j = 0;
95	        out4:
96	        while (j < 1000)
97	        {
98	            if (j == 500) break out3;
99	            j++;
100	        }
101	        j = 2001;
102	    }
103	    j = 2002;
104	    i++;
105	}
106
107    // 'breaking out of a "while" loop with a "label"'
108	testcases[count++] = new TestCase ( SECTION, 'breaking out of a "while" loop with a "label"',
109	                                    500, j);
110
111	i = 0;
112
113	do
114	{
115	    if (i == 100) break;
116	    i++;
117	} while (i < 1000);
118
119	// 'breaking out of a "do" loop'
120	testcases[count++] = new TestCase ( SECTION, 'breaking out of a "do" loop',
121	                                    100, i );
122
123    j = 2000;
124    i = 0;
125
126    out5:
127	do
128	{
129	    if (i == 100)
130	    {
131	        j = 0;
132	        out6:
133	        do
134	        {
135	            if (j == 500) break out5;
136	            j++;
137	        }while (j < 1000);
138	        j = 2001;
139	    }
140	    j = 2002;
141	    i++;
142	}while (i < 1000);
143
144    // 'breaking out of a "do" loop with a "label"'
145	testcases[count++] = new TestCase ( SECTION, 'breaking out of a "do" loop with a "label"',
146	                                    500, j);
147
148	function test()
149	{
150	   for ( tc=0; tc < testcases.length; tc++ ) {
151	        testcases[tc].passed = writeTestCaseResult(
152	        testcases[tc].expect,
153	        testcases[tc].actual,
154	        testcases[tc].description +" = "+
155	        testcases[tc].actual );
156	        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
157	   }
158	   stopTest();
159	   return ( testcases );
160	}
161
162	test();
163