Debian Codegraph @

rhino/testsrc/tests/ecma_3/Statements/switch-001.js

raw symbols SCIP
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 * Date: 07 May 2001
8 *
9 * SUMMARY: Testing the switch statement
10 *
11 * See ECMA3 Section 12.11, "The switch Statement"
12 */
13 //-----------------------------------------------------------------------------
14 var gTestfile = 'switch-001.js';
15 var UBound = 0;
16 var BUGNUMBER = '(none)';
17 var summary = 'Testing the switch statement';
18 var cnMatch = 'Match';
19 var cnNoMatch = 'NoMatch';
20 var status = '';
21 var statusitems = [ ];
22 var actual = '';
23 var actualvalues = [ ];
24 var expect= '';
25 var expectedvalues = [ ];
26
27
28 status = 'Section A of test';
29 actual = match(17, f(fInverse(17)), f, fInverse);
30 expect = cnMatch;
31 addThis();
32
33 status = 'Section B of test';
34 actual = match(17, 18, f, fInverse);
35 expect = cnNoMatch;
36 addThis();
37
38 status = 'Section C of test';
39 actual = match(1, 1, Math.exp, Math.log);
40 expect = cnMatch;
41 addThis();
42
43 status = 'Section D of test';
44 actual = match(1, 2, Math.exp, Math.log);
45 expect = cnNoMatch;
46 addThis();
47
48 status = 'Section E of test';
49 actual = match(1, 1, Math.sin, Math.cos);
50 expect = cnNoMatch;
51 addThis();
52
53
54
55 //---------------------------------------------------------------------------------
56 test();
57 //---------------------------------------------------------------------------------
58
59
60
61 /*
62 * If F,G are inverse functions and x==y, this should return cnMatch -
63 */
64 function match(x, y, F, G)
65 {
66 switch (x)
67 {
68 case F(G(y)):
69 return cnMatch;
70
71 default:
72 return cnNoMatch;
73 }
74 }
75
76
77 function addThis()
78 {
79 statusitems[UBound] = status;
80 actualvalues[UBound] = actual;
81 expectedvalues[UBound] = expect;
82 UBound++;
83 }
84
85
86 function test()
87 {
88 enterFunc ('test');
89 printBugNumber(BUGNUMBER);
90 printStatus (summary);
91
92 for (var i = 0; i < UBound; i++)
93 {
94 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
95 }
96
97 exitFunc ('test');
98 }
99
100
101 function f(m)
102 {
103 return 2*(m+1);
104 }
105
106
107 function fInverse(n)
108 {
109 return (n-2)/2;
110 }