1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * NASHORN-515 : Switch default handling was broken.
  26  *
  27  * @test
  28  * @run
  29  */
  30 
  31 function a() {
  32     var x = (3.14-2.14);
  33 
  34     switch (x) {
  35     case 1:
  36     print("--1");
  37     break;
  38     case 2:
  39     print("--2");
  40     break;
  41     default:
  42     print("default");
  43     break;
  44     }
  45 }
  46 
  47 //NASHORN-529 - original fix was incomplete for primitive types
  48 function b() {
  49     var index = 256.3;
  50     switch (index) {
  51     case 0x00:
  52     case 0x01:
  53     print("one zero");
  54     break;
  55     default:
  56     print("default");
  57     break;
  58     }
  59 }
  60 
  61 //NASHORN-529 - original fix was incomplete for primitive types
  62 function c() {
  63     var index = 0x1fffffffff;
  64     switch (index) {
  65     case 0x00:
  66     case 0x01:
  67     print("one zero");
  68     break;
  69     default:
  70     print("default");
  71     }
  72     --index;
  73 }
  74 
  75 function d() {
  76     var x = (3.14-1.14);
  77 
  78     switch(x) {
  79     case 1:
  80     print("--1"); break;
  81     case 2:
  82     print("--2"); break;
  83     case 3:
  84     print("--3"); break;
  85     case 4:
  86     print("--4"); break;
  87     default:
  88     print("default");
  89     }
  90 }
  91 
  92 function e() {
  93     var y = 2147483647;
  94 
  95     switch(y) {
  96     case -2147483648:
  97     print("MIN_INT"); break;
  98     case -2147483647:
  99     print("MIN_INT+1"); break;
 100     case 2147483647:
 101     print("MAX_INT"); break;
 102     case 1:
 103     print("--1"); break;
 104     case 2:
 105     print("--2"); break;
 106     case 3:
 107     print("--3"); break;
 108     case 4:
 109     print("--4"); break;
 110     default:
 111     print("default");
 112     }
 113 }
 114 
 115 function f() {
 116     var z = 2;
 117 
 118     switch(z) {
 119     case -2147483648:
 120     print("MIN_INT"); break;
 121     case -2147483647:
 122     print("MIN_INT+1"); break;
 123     case 2147483647:
 124     print("MAX_INT"); break;
 125     case 1:
 126     print("--1"); break;
 127     case 2:
 128     print("--2 first"); break;
 129     case 2:
 130     print("--2 second"); break;
 131     case 3:
 132     print("--3"); break;
 133     case 4:
 134     print("--4"); break;
 135     default:
 136     print("default");
 137     }
 138 }
 139 
 140 a();
 141 b();
 142 c();
 143 d();
 144 e();
 145 f();