]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/Statements/switch-001.js
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma_3 / Statements / switch-001.js
1 /*
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
6 *
7 * Software distributed under the License is distributed on an "AS IS"
8 * basis, WITHOUT WARRANTY OF ANY KIND, either expressed
9 * or implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is mozilla.org code.
13 *
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s): pschwartau@netscape.com
20 * Date: 07 May 2001
21 *
22 * SUMMARY: Testing the switch statement
23 *
24 * See ECMA3 Section 12.11, "The switch Statement"
25 */
26 //-------------------------------------------------------------------------------------------------
27 var UBound = 0;
28 var bug = '(none)';
29 var summary = 'Testing the switch statement';
30 var cnMatch = 'Match';
31 var cnNoMatch = 'NoMatch';
32 var status = '';
33 var statusitems = [ ];
34 var actual = '';
35 var actualvalues = [ ];
36 var expect= '';
37 var expectedvalues = [ ];
38
39
40 status = 'Section A of test';
41 actual = match(17, f(fInverse(17)), f, fInverse);
42 expect = cnMatch;
43 addThis();
44
45 status = 'Section B of test';
46 actual = match(17, 18, f, fInverse);
47 expect = cnNoMatch;
48 addThis();
49
50 status = 'Section C of test';
51 actual = match(1, 1, Math.exp, Math.log);
52 expect = cnMatch;
53 addThis();
54
55 status = 'Section D of test';
56 actual = match(1, 2, Math.exp, Math.log);
57 expect = cnNoMatch;
58 addThis();
59
60 status = 'Section E of test';
61 actual = match(1, 1, Math.sin, Math.cos);
62 expect = cnNoMatch;
63 addThis();
64
65
66
67 //---------------------------------------------------------------------------------
68 test();
69 //---------------------------------------------------------------------------------
70
71
72
73 /*
74 * If F,G are inverse functions and x==y, this should return cnMatch -
75 */
76 function match(x, y, F, G)
77 {
78 switch (x)
79 {
80 case F(G(y)):
81 return cnMatch;
82
83 default:
84 return cnNoMatch;
85 }
86 }
87
88
89 function addThis()
90 {
91 statusitems[UBound] = status;
92 actualvalues[UBound] = actual;
93 expectedvalues[UBound] = expect;
94 UBound++;
95 }
96
97
98 function test()
99 {
100 enterFunc ('test');
101 printBugNumber (bug);
102 printStatus (summary);
103
104 for (var i = 0; i < UBound; i++)
105 {
106 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
107 }
108
109 exitFunc ('test');
110 }
111
112
113 function f(m)
114 {
115 return 2*(m+1);
116 }
117
118
119 function fInverse(n)
120 {
121 return (n-2)/2;
122 }