Debian Codegraph @

rhino/testsrc/tests/ecma_3/Statements/regress-74474-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: 01 May 2001
8 *
9 * SUMMARY: Regression test for Bugzilla bug 74474
10 *"switch() misbehaves with duplicated labels"
11 *
12 * See ECMA3 Section 12.11, "The switch Statement"
13 * See http://bugzilla.mozilla.org/show_bug.cgi?id=74474
14 */
15 //-----------------------------------------------------------------------------
16 var gTestfile = 'regress-74474-001.js';
17 var UBound = 0;
18 var BUGNUMBER = 74474;
19 var summary = 'Testing switch statements with duplicate labels';
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: the string literal "1" as a duplicate label';
29 actual = '';
30 switch ('1')
31 {
32 case '1':
33 actual += 'a';
34 case '1':
35 actual += 'b';
36 }
37 expect = 'ab';
38 addThis();
39
40
41 status = 'Section B of test: the numeric literal 1 as a duplicate label';
42 actual = '';
43 switch (1)
44 {
45 case 1:
46 actual += 'a';
47 case 1:
48 actual += 'b';
49 }
50 expect = 'ab';
51 addThis();
52
53
54 status = 'Section C of test: the numeric literal 1 as a duplicate label, via a function parameter';
55 tryThis(1);
56 function tryThis(x)
57 {
58 actual = '';
59
60 switch (x)
61 {
62 case x:
63 actual += 'a';
64 case x:
65 actual += 'b';
66 }
67 }
68 expect = 'ab';
69 addThis();
70
71
72
73 //---------------------------------------------------------------------------------
74 test();
75 //---------------------------------------------------------------------------------
76
77
78
79 function addThis()
80 {
81 statusitems[UBound] = status;
82 actualvalues[UBound] = actual;
83 expectedvalues[UBound] = expect;
84 UBound++;
85 }
86
87
88 function test()
89 {
90 enterFunc ('test');
91 printBugNumber(BUGNUMBER);
92 printStatus (summary);
93
94 for (var i = 0; i < UBound; i++)
95 {
96 reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
97 }
98
99 exitFunc ('test');
100 }
101
102
103 function getStatus(i)
104 {
105 return statusitems[i];
106 }