1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16let testByte: Byte = new Byte(42 as byte); 17let testShort: Short = new Short(42 as short); 18let testInt: Int = new Int(42 as int); 19let testLong: Long = new Long(42 as long); 20let testFloat: Float = new Float(42 as float); 21let testDouble: Double = new Double(42 as double); 22let testChar: Char = new Char(42 as char); 23let testLongValue: Long = 9223372036854775807; 24 25function byte_test(): boolean { 26 27 let byte_byte = new Byte(42 as byte); 28 let byte_short = new Short(42 as short); 29 let byte_int = new Int(42 as int); 30 let byte_long = new Long(42 as long); 31 let byte_float = new Float(42 as float); 32 let byte_double = new Double(42 as double); 33 let byte_char = new Char(42 as char); 34 35 byte_byte = testByte; // Byte -> Byte 36 byte_short = testByte; // Byte -> Short 37 byte_int = testByte; // Byte -> Int 38 byte_long = testByte; // Byte -> Long 39 byte_float = testByte; // Byte -> Float 40 byte_double = testByte; // Byte -> Double 41 byte_char = testByte; // Byte -> Char 42 43 // true test Type speciefic operations 44 { 45 if (byte_double != testDouble || byte_double.toExponential() != testDouble.toExponential()) { 46 return false; 47 } 48 if (byte_char != testChar || byte_char.isBinDigit() != testChar.isBinDigit()) { 49 return false; 50 } 51 if (byte_float != testFloat || byte_float.isNaN() != testFloat.isNaN()) { 52 return false; 53 } 54 if (byte_long != testLong || (byte_long = testLongValue) != (testLongValue)) { 55 return false; // in fact CTE 56 } 57 58 // no int test 59 // no short test 60 // no byte test 61 } 62 return true; 63} 64 65function short_test(): boolean { 66 67 let short_byte = new Byte(42 as byte); 68 let short_short = new Short(42 as short); 69 let short_int = new Int(42 as int); 70 let short_long = new Long(42 as long); 71 let short_float = new Float(42 as float); 72 let short_double = new Double(42 as double); 73 let short_char = new Char(42 as char); 74 75 // short_byte = testShort; // Short -> Byte is not available according 6.5.2 widening table and CTE happens 76 short_short = testShort; // Short -> Short 77 short_int = testShort; // Short -> Int 78 short_long = testShort; // Short -> Long 79 short_float = testShort; // Short -> Float 80 short_double = testShort; // Short -> Double 81 // short_char = testShort; // Short -> Char is not available according 6.5.2 widening table and CTE happens 82 83 84 // true test Type speciefic operations 85 { 86 if (short_double.toExponential() != testDouble.toExponential()) { 87 return false; 88 } 89 // if (short_char != testChar || short_char.isBinDigit() != testChar.isBinDigit()) { 90 // return false; 91 // } // is not available according 6.5.2 widening table and CTE happens 92 if (short_float != testFloat || short_float.isNaN() != testFloat.isNaN()) { 93 return false; 94 } 95 if (short_long != testLong || (short_long = testLongValue) != (testLongValue)) { 96 return false; // in fact CTE 97 } 98 // no int test 99 // no short test 100 // no byte test 101 } 102 return true; 103} 104 105function char_test(): boolean { 106 107 let char_byte = new Byte(42 as byte); 108 let char_short = new Short(42 as short); 109 let char_int = new Int(42 as int); 110 let char_long = new Long(42 as long); 111 let char_float = new Float(42 as float); 112 let char_double = new Double(42 as double); 113 let char_char = new Char(42 as char); 114 115 // char_byte = testChar; // Char -> Byte is not available according 6.5.2 widening table and CTE happens 116 // char_short = testChar; // Char -> Short is not available according 6.5.2 widening table and CTE happens 117 char_int = testChar; // Char -> Int 118 char_long = testChar; // Char -> Long 119 char_float = testChar; // Char -> Float 120 char_double = testChar; // Char -> Double 121 char_char = testChar; // Char -> Char 122 123 // true test Type speciefic operations 124 { 125 if (char_double.toExponential() != testDouble.toExponential()) { 126 console.log("char 1") 127 return false; 128 } 129 if (char_char != testChar || char_char.isBinDigit() != testChar.isBinDigit()) { 130 console.log("char 2") 131 return false; 132 } 133 if (char_float != testFloat || char_float.isNaN() != testFloat.isNaN()) { 134 console.log("char 2") 135 return false; 136 } 137 //let tmpLong = testLong 138 if (char_long != testLong || (char_long = testLongValue) != (testLongValue)) { 139 console.log(char_long) 140 console.log(testLong) 141 console.log("char 4") 142 return false; // in fact CTE 143 } 144 //testLong = tmpLong 145 // no int test 146 // no short test 147 // no byte test 148 } 149 return true; 150} 151 152function int_test(): boolean { 153 154 let int_byte = new Byte(42 as byte); 155 let int_short = new Short(42 as short); 156 let int_int = new Int(42 as int); 157 let int_long = new Long(42 as long); 158 let int_float = new Float(42 as float); 159 let int_double = new Double(42 as double); 160 let int_char = new Char(42 as char); 161 162 // int_byte = testInt; // Int -> Byte is not available according 6.5.2 widening table and CTE happens 163 // int_short = testInt; // Int -> Short is not available according 6.5.2 widening table and CTE happens 164 int_int = testInt; // Int -> Int 165 int_long = testInt; // Int -> Long 166 int_float = testInt; // Int -> Float 167 int_double = testInt; // Int -> Double 168 // int_char = testInt; // Int -> Char is not available according 6.5.2 widening table and CTE happens 169 170 // true test Type speciefic operations 171 { 172 if (int_double.toExponential() != testDouble.toExponential()) { 173 return false; 174 } 175 // if (int_char != testChar || int_char.isBinDigit() != testChar.isBinDigit()) { 176 // return false; 177 // } is not available according 6.5.2 widening table and CTE happens 178 if (int_float != testFloat || int_float.isNaN() != testFloat.isNaN()) { 179 return false; 180 } 181 if (int_long != testLong || (int_long = testLongValue) != (testLongValue)) { 182 return false; // in fact CTE 183 } 184 // no int test 185 // no short test 186 // no byte test 187 } 188 return true; 189} 190 191function long_test(): boolean { 192 193 let long_byte = new Byte(42 as byte); 194 let long_short = new Short(42 as short); 195 let long_int = new Int(42 as int); 196 let long_long = new Long(42 as long); 197 let long_float = new Float(42 as float); 198 let long_double = new Double(42 as double); 199 let long_char = new Char(42 as char); 200 201 // long_byte = testLong; // Long -> Byte is not available according 6.5.2 widening table and CTE happens 202 // long_short = testLong; // Long -> Short is not available according 6.5.2 widening table and CTE happens 203 // long_int = testLong; // Long -> Int is not available according 6.5.2 widening table and CTE happens 204 long_long = testLong; // Long -> Long 205 long_float = testLong; // Long -> Float 206 long_double = testLong; // Long -> Double 207 // long_char = testLong; // Long -> Char is not available according 6.5.2 widening table and CTE happens 208 209 // true test Type speciefic operations 210 { 211 if (long_double.toExponential() != testDouble.toExponential()) { 212 return false; 213 } 214 // if (long_char != testChar || long_char.isBinDigit() != testChar.isBinDigit()) { 215 // return false; 216 // } // is not available according 6.5.2 widening table and CTE happens 217 if (long_float != testFloat || long_float.isNaN() != testFloat.isNaN()) { 218 return false; 219 } 220 if (long_long != testLong || (long_long = testLongValue) != (testLongValue)) { 221 return false; // in fact CTE 222 } 223 // no int test 224 // no short test 225 // no byte test 226 } 227 return true; 228} 229 230function float_test(): boolean { 231 232 let float_byte = new Byte(42 as byte); 233 let float_short = new Short(42 as short); 234 let float_int = new Int(42 as int); 235 let float_long = new Long(42 as long); 236 let float_float = new Float(42 as float); 237 let float_double = new Double(42 as double); 238 let float_char = new Char(42 as char); 239 240 // float_byte = testFloat; // Float -> Byte is not available according 6.5.2 widening table and CTE happens 241 // float_short = testFloat; // Float -> Short is not available according 6.5.2 widening table and CTE happens 242 // float_int = testFloat; // Float -> Int is not available according 6.5.2 widening table and CTE happens 243 // float_long = testFloat; // Float -> Long is not available according 6.5.2 widening table and CTE happens 244 float_float = testFloat; // Float -> Float 245 float_double = testFloat; // Float -> Double 246 // float_char = testFloat; // Float -> Char is not available according 6.5.2 widening table and CTE happens 247 248 // true test Type speciefic operations 249 { 250 if (float_double.toExponential() != testDouble.toExponential()) { 251 return false; 252 } 253 // if (float_char != testChar || float_char.isBinDigit() != testChar.isBinDigit()) { 254 // return false; 255 // } is not available according 6.5.2 widening table and CTE happens 256 if (float_float != testFloat || float_float.isNaN() != testFloat.isNaN()) { // better to find another way of checking 257 return false; 258 } 259 // if (float_long != testLong || (float_long = testLongValue) != (testLongValue)) { 260 // return false; // in fact CTE 261 // } is not available according 6.5.2 widening table and CTE happens 262 263 // no int test 264 // no short test 265 // no byte test 266 } 267 return true; 268} 269 270function double_test(): boolean { 271 272 let double_byte = new Byte(42 as byte); 273 let double_short = new Short(42 as short); 274 let double_int = new Int(42 as int); 275 let double_long = new Long(42 as long); 276 let double_float = new Float(42 as float); 277 let double_double = new Double(42 as double); 278 let double_char = new Char(42 as char); 279 280 // double_byte = testDouble; // Double -> Byte is not available according 6.5.2 widening table and CTE happens 281 // double_short = testDouble; // Double -> Short is not available according 6.5.2 widening table and CTE happens 282 // double_int = testDouble; // Double -> Int is not available according 6.5.2 widening table and CTE happens 283 // double_long = testDouble; // Double -> Long is not available according 6.5.2 widening table and CTE happens 284 // double_float = testDouble; // Double -> Float is not available according 6.5.2 widening table and CTE happens 285 double_double = testDouble; // Double -> Double 286 // double_char = testDouble; // Double -> Char is not available according 6.5.2 widening table and CTE happens 287 288 // true test Type speciefic operations 289 { 290 if (double_double.toExponential() != testDouble.toExponential()) { 291 return false; 292 } 293 // if (double_char != testChar || double_char.isBinDigit() != testChar.isBinDigit()) { 294 // return false; 295 // } // is not available according 6.5.2 widening table and CTE happens 296 // if (double_float != testFloat || double_float.isNaN() != testFloat.isNaN()) { // better to find another way of checking 297 // return false; 298 // } // is not available according 6.5.2 widening table and CTE happens 299 // if (double_long != testLong || (double_long = testLongValue) != (testLongValue)) { 300 // return false; // in fact CTE 301 // } // is not available according 6.5.2 widening table and CTE happens 302 303 // no int test 304 // no short test 305 // no byte test 306 } 307 return true; 308} 309 310function main(): int { 311 if (byte_test() && short_test() && char_test() && int_test() 312 && long_test() && float_test() && double_test()) { 313 return 0; 314 } 315 return 1; 316} 317