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-592: test all combos of field types and getters and setters
  26  *
  27  * @test
  28  * @run
  29  */
  30 
  31 //fortype undefined
  32 var a;
  33 
  34 print(a & 0xff);
  35 print(a >>> 1);
  36 print(a * 2);
  37 print(a + "hej!");
  38 
  39 var b;
  40 b = 17;   //set undefined->int
  41 
  42 print(b & 0xff);
  43 print(b >>> 1);
  44 print(b * 2);
  45 print(b + "hej!");
  46 
  47 var c;
  48 c = 17.4711 //set undefined->double
  49 
  50 print(c & 0xff);
  51 print(c >>> 1);
  52 print(c * 2);
  53 print(c + "hej!");
  54 
  55 var d; // set undefined->double
  56 d = "Fame and fortune Salamander Yahoo!";
  57 
  58 print(d & 0xff);
  59 print(d >>> 1);
  60 print(d * 2);
  61 print(d + "hej!");
  62 
  63 // now we have exhausted all getters and undefined->everything setters.
  64 
  65 
  66 var e = 23; // int to everything setters,
  67 e = 24;     //int to int
  68 print(e);
  69 e = (22222 >>> 1); //int to long;
  70 print(e);
  71 e = 23.23;  //int to double
  72 print(e);
  73 e = 23;     //double to int - still double
  74 print(e);
  75 print(e & 0xff);
  76 e = "Have some pie!" //double to string
  77 print(e);
  78 e = 4711.17;
  79 print(e); //still an object not a double
  80 
  81 
  82 var f = (23222 >>> 1); // long to everything setters,
  83 f = 34344 >>> 1;     //long to long
  84 print(f);
  85 f = 23; //long to int - still long
  86 print(f);
  87 f = 23.23;  //long to double
  88 print(f);
  89 f = 23;     //double to int - still double
  90 print(f);
  91 print(f & 0xff);
  92 f = "Have some pie!" //double to string
  93 print(f);
  94 f = 4711.17;
  95 print(f); //still an object not a double
  96 
  97 var g = 4811.16;
  98 g = 23; //still double
  99 print(g);
 100 g = (222 >>> 1); //still double
 101 print(g);
 102 g = 4711.16; //double->double
 103 print(g);
 104 g = "I like cake!";
 105 print(g);  //object to various
 106 print(g & 0xff);
 107 print(g * 2);
 108 print(g >>> 2);
 109 print(g);
 110 
 111 var h = {x:17, y:17.4711, z:"salamander"};
 112 print(h.x);
 113 print(h.y);
 114 print(h.z);
 115 h.x = 4711.17;
 116 h.y = "axolotl";
 117 h.z = "lizard";
 118 print(h.x);
 119 print(h.y);
 120 print(h.z);