1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Expressions/11.4.6.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,265 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 11.4.6.js 1.12 + ECMA Section: 11.4.6 Unary + Operator 1.13 + Description: convert operand to Number type 1.14 + Author: christine@netscape.com 1.15 + Date: 7 july 1997 1.16 +*/ 1.17 + 1.18 +var SECTION = "11.4.6"; 1.19 +var VERSION = "ECMA_1"; 1.20 +var BUGNUMBER="77391"; 1.21 + 1.22 +startTest(); 1.23 + 1.24 +writeHeaderToLog( SECTION + " Unary + operator"); 1.25 + 1.26 +new TestCase( SECTION, "+('')", 0, +("") ); 1.27 +new TestCase( SECTION, "+(' ')", 0, +(" ") ); 1.28 +new TestCase( SECTION, "+(\\t)", 0, +("\t") ); 1.29 +new TestCase( SECTION, "+(\\n)", 0, +("\n") ); 1.30 +new TestCase( SECTION, "+(\\r)", 0, +("\r") ); 1.31 +new TestCase( SECTION, "+(\\f)", 0, +("\f") ); 1.32 + 1.33 +new TestCase( SECTION, "+(String.fromCharCode(0x0009)", 0, +(String.fromCharCode(0x0009)) ); 1.34 +new TestCase( SECTION, "+(String.fromCharCode(0x0020)", 0, +(String.fromCharCode(0x0020)) ); 1.35 +new TestCase( SECTION, "+(String.fromCharCode(0x000C)", 0, +(String.fromCharCode(0x000C)) ); 1.36 +new TestCase( SECTION, "+(String.fromCharCode(0x000B)", 0, +(String.fromCharCode(0x000B)) ); 1.37 +new TestCase( SECTION, "+(String.fromCharCode(0x000D)", 0, +(String.fromCharCode(0x000D)) ); 1.38 +new TestCase( SECTION, "+(String.fromCharCode(0x000A)", 0, +(String.fromCharCode(0x000A)) ); 1.39 + 1.40 +// a StringNumericLiteral may be preceeded or followed by whitespace and/or 1.41 +// line terminators 1.42 + 1.43 +new TestCase( SECTION, "+( ' ' + 999 )", 999, +( ' '+999) ); 1.44 +new TestCase( SECTION, "+( '\\n' + 999 )", 999, +( '\n' +999) ); 1.45 +new TestCase( SECTION, "+( '\\r' + 999 )", 999, +( '\r' +999) ); 1.46 +new TestCase( SECTION, "+( '\\t' + 999 )", 999, +( '\t' +999) ); 1.47 +new TestCase( SECTION, "+( '\\f' + 999 )", 999, +( '\f' +999) ); 1.48 + 1.49 +new TestCase( SECTION, "+( 999 + ' ' )", 999, +( 999+' ') ); 1.50 +new TestCase( SECTION, "+( 999 + '\\n' )", 999, +( 999+'\n' ) ); 1.51 +new TestCase( SECTION, "+( 999 + '\\r' )", 999, +( 999+'\r' ) ); 1.52 +new TestCase( SECTION, "+( 999 + '\\t' )", 999, +( 999+'\t' ) ); 1.53 +new TestCase( SECTION, "+( 999 + '\\f' )", 999, +( 999+'\f' ) ); 1.54 + 1.55 +new TestCase( SECTION, "+( '\\n' + 999 + '\\n' )", 999, +( '\n' +999+'\n' ) ); 1.56 +new TestCase( SECTION, "+( '\\r' + 999 + '\\r' )", 999, +( '\r' +999+'\r' ) ); 1.57 +new TestCase( SECTION, "+( '\\t' + 999 + '\\t' )", 999, +( '\t' +999+'\t' ) ); 1.58 +new TestCase( SECTION, "+( '\\f' + 999 + '\\f' )", 999, +( '\f' +999+'\f' ) ); 1.59 + 1.60 +new TestCase( SECTION, "+( ' ' + '999' )", 999, +( ' '+'999') ); 1.61 +new TestCase( SECTION, "+( '\\n' + '999' )", 999, +( '\n' +'999') ); 1.62 +new TestCase( SECTION, "+( '\\r' + '999' )", 999, +( '\r' +'999') ); 1.63 +new TestCase( SECTION, "+( '\\t' + '999' )", 999, +( '\t' +'999') ); 1.64 +new TestCase( SECTION, "+( '\\f' + '999' )", 999, +( '\f' +'999') ); 1.65 + 1.66 +new TestCase( SECTION, "+( '999' + ' ' )", 999, +( '999'+' ') ); 1.67 +new TestCase( SECTION, "+( '999' + '\\n' )", 999, +( '999'+'\n' ) ); 1.68 +new TestCase( SECTION, "+( '999' + '\\r' )", 999, +( '999'+'\r' ) ); 1.69 +new TestCase( SECTION, "+( '999' + '\\t' )", 999, +( '999'+'\t' ) ); 1.70 +new TestCase( SECTION, "+( '999' + '\\f' )", 999, +( '999'+'\f' ) ); 1.71 + 1.72 +new TestCase( SECTION, "+( '\\n' + '999' + '\\n' )", 999, +( '\n' +'999'+'\n' ) ); 1.73 +new TestCase( SECTION, "+( '\\r' + '999' + '\\r' )", 999, +( '\r' +'999'+'\r' ) ); 1.74 +new TestCase( SECTION, "+( '\\t' + '999' + '\\t' )", 999, +( '\t' +'999'+'\t' ) ); 1.75 +new TestCase( SECTION, "+( '\\f' + '999' + '\\f' )", 999, +( '\f' +'999'+'\f' ) ); 1.76 + 1.77 +new TestCase( SECTION, "+( String.fromCharCode(0x0009) + '99' )", 99, +( String.fromCharCode(0x0009) + '99' ) ); 1.78 +new TestCase( SECTION, "+( String.fromCharCode(0x0020) + '99' )", 99, +( String.fromCharCode(0x0020) + '99' ) ); 1.79 +new TestCase( SECTION, "+( String.fromCharCode(0x000C) + '99' )", 99, +( String.fromCharCode(0x000C) + '99' ) ); 1.80 +new TestCase( SECTION, "+( String.fromCharCode(0x000B) + '99' )", 99, +( String.fromCharCode(0x000B) + '99' ) ); 1.81 +new TestCase( SECTION, "+( String.fromCharCode(0x000D) + '99' )", 99, +( String.fromCharCode(0x000D) + '99' ) ); 1.82 +new TestCase( SECTION, "+( String.fromCharCode(0x000A) + '99' )", 99, +( String.fromCharCode(0x000A) + '99' ) ); 1.83 + 1.84 +new TestCase( SECTION, "+( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0009)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0009)) ); 1.85 +new TestCase( SECTION, "+( String.fromCharCode(0x0020) + '99' + String.fromCharCode(0x0020)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0020)) ); 1.86 +new TestCase( SECTION, "+( String.fromCharCode(0x000C) + '99' + String.fromCharCode(0x000C)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000C)) ); 1.87 +new TestCase( SECTION, "+( String.fromCharCode(0x000D) + '99' + String.fromCharCode(0x000D)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000D)) ); 1.88 +new TestCase( SECTION, "+( String.fromCharCode(0x000B) + '99' + String.fromCharCode(0x000B)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000B)) ); 1.89 +new TestCase( SECTION, "+( String.fromCharCode(0x000A) + '99' + String.fromCharCode(0x000A)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000A)) ); 1.90 + 1.91 +new TestCase( SECTION, "+( '99' + String.fromCharCode(0x0009)", 99, +( '99' + String.fromCharCode(0x0009)) ); 1.92 +new TestCase( SECTION, "+( '99' + String.fromCharCode(0x0020)", 99, +( '99' + String.fromCharCode(0x0020)) ); 1.93 +new TestCase( SECTION, "+( '99' + String.fromCharCode(0x000C)", 99, +( '99' + String.fromCharCode(0x000C)) ); 1.94 +new TestCase( SECTION, "+( '99' + String.fromCharCode(0x000D)", 99, +( '99' + String.fromCharCode(0x000D)) ); 1.95 +new TestCase( SECTION, "+( '99' + String.fromCharCode(0x000B)", 99, +( '99' + String.fromCharCode(0x000B)) ); 1.96 +new TestCase( SECTION, "+( '99' + String.fromCharCode(0x000A)", 99, +( '99' + String.fromCharCode(0x000A)) ); 1.97 + 1.98 +new TestCase( SECTION, "+( String.fromCharCode(0x0009) + 99 )", 99, +( String.fromCharCode(0x0009) + 99 ) ); 1.99 +new TestCase( SECTION, "+( String.fromCharCode(0x0020) + 99 )", 99, +( String.fromCharCode(0x0020) + 99 ) ); 1.100 +new TestCase( SECTION, "+( String.fromCharCode(0x000C) + 99 )", 99, +( String.fromCharCode(0x000C) + 99 ) ); 1.101 +new TestCase( SECTION, "+( String.fromCharCode(0x000B) + 99 )", 99, +( String.fromCharCode(0x000B) + 99 ) ); 1.102 +new TestCase( SECTION, "+( String.fromCharCode(0x000D) + 99 )", 99, +( String.fromCharCode(0x000D) + 99 ) ); 1.103 +new TestCase( SECTION, "+( String.fromCharCode(0x000A) + 99 )", 99, +( String.fromCharCode(0x000A) + 99 ) ); 1.104 + 1.105 +new TestCase( SECTION, "+( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0009)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0009)) ); 1.106 +new TestCase( SECTION, "+( String.fromCharCode(0x0020) + 99 + String.fromCharCode(0x0020)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0020)) ); 1.107 +new TestCase( SECTION, "+( String.fromCharCode(0x000C) + 99 + String.fromCharCode(0x000C)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000C)) ); 1.108 +new TestCase( SECTION, "+( String.fromCharCode(0x000D) + 99 + String.fromCharCode(0x000D)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000D)) ); 1.109 +new TestCase( SECTION, "+( String.fromCharCode(0x000B) + 99 + String.fromCharCode(0x000B)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000B)) ); 1.110 +new TestCase( SECTION, "+( String.fromCharCode(0x000A) + 99 + String.fromCharCode(0x000A)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000A)) ); 1.111 + 1.112 +new TestCase( SECTION, "+( 99 + String.fromCharCode(0x0009)", 99, +( 99 + String.fromCharCode(0x0009)) ); 1.113 +new TestCase( SECTION, "+( 99 + String.fromCharCode(0x0020)", 99, +( 99 + String.fromCharCode(0x0020)) ); 1.114 +new TestCase( SECTION, "+( 99 + String.fromCharCode(0x000C)", 99, +( 99 + String.fromCharCode(0x000C)) ); 1.115 +new TestCase( SECTION, "+( 99 + String.fromCharCode(0x000D)", 99, +( 99 + String.fromCharCode(0x000D)) ); 1.116 +new TestCase( SECTION, "+( 99 + String.fromCharCode(0x000B)", 99, +( 99 + String.fromCharCode(0x000B)) ); 1.117 +new TestCase( SECTION, "+( 99 + String.fromCharCode(0x000A)", 99, +( 99 + String.fromCharCode(0x000A)) ); 1.118 + 1.119 + 1.120 +// StrNumericLiteral:::StrDecimalLiteral:::Infinity 1.121 + 1.122 +new TestCase( SECTION, "+('Infinity')", Math.pow(10,10000), +("Infinity") ); 1.123 +new TestCase( SECTION, "+('-Infinity')", -Math.pow(10,10000), +("-Infinity") ); 1.124 +new TestCase( SECTION, "+('+Infinity')", Math.pow(10,10000), +("+Infinity") ); 1.125 + 1.126 +// StrNumericLiteral::: StrDecimalLiteral ::: DecimalDigits . DecimalDigits opt ExponentPart opt 1.127 + 1.128 +new TestCase( SECTION, "+('0')", 0, +("0") ); 1.129 +new TestCase( SECTION, "+('-0')", -0, +("-0") ); 1.130 +new TestCase( SECTION, "+('+0')", 0, +("+0") ); 1.131 + 1.132 +new TestCase( SECTION, "+('1')", 1, +("1") ); 1.133 +new TestCase( SECTION, "+('-1')", -1, +("-1") ); 1.134 +new TestCase( SECTION, "+('+1')", 1, +("+1") ); 1.135 + 1.136 +new TestCase( SECTION, "+('2')", 2, +("2") ); 1.137 +new TestCase( SECTION, "+('-2')", -2, +("-2") ); 1.138 +new TestCase( SECTION, "+('+2')", 2, +("+2") ); 1.139 + 1.140 +new TestCase( SECTION, "+('3')", 3, +("3") ); 1.141 +new TestCase( SECTION, "+('-3')", -3, +("-3") ); 1.142 +new TestCase( SECTION, "+('+3')", 3, +("+3") ); 1.143 + 1.144 +new TestCase( SECTION, "+('4')", 4, +("4") ); 1.145 +new TestCase( SECTION, "+('-4')", -4, +("-4") ); 1.146 +new TestCase( SECTION, "+('+4')", 4, +("+4") ); 1.147 + 1.148 +new TestCase( SECTION, "+('5')", 5, +("5") ); 1.149 +new TestCase( SECTION, "+('-5')", -5, +("-5") ); 1.150 +new TestCase( SECTION, "+('+5')", 5, +("+5") ); 1.151 + 1.152 +new TestCase( SECTION, "+('6')", 6, +("6") ); 1.153 +new TestCase( SECTION, "+('-6')", -6, +("-6") ); 1.154 +new TestCase( SECTION, "+('+6')", 6, +("+6") ); 1.155 + 1.156 +new TestCase( SECTION, "+('7')", 7, +("7") ); 1.157 +new TestCase( SECTION, "+('-7')", -7, +("-7") ); 1.158 +new TestCase( SECTION, "+('+7')", 7, +("+7") ); 1.159 + 1.160 +new TestCase( SECTION, "+('8')", 8, +("8") ); 1.161 +new TestCase( SECTION, "+('-8')", -8, +("-8") ); 1.162 +new TestCase( SECTION, "+('+8')", 8, +("+8") ); 1.163 + 1.164 +new TestCase( SECTION, "+('9')", 9, +("9") ); 1.165 +new TestCase( SECTION, "+('-9')", -9, +("-9") ); 1.166 +new TestCase( SECTION, "+('+9')", 9, +("+9") ); 1.167 + 1.168 +new TestCase( SECTION, "+('3.14159')", 3.14159, +("3.14159") ); 1.169 +new TestCase( SECTION, "+('-3.14159')", -3.14159, +("-3.14159") ); 1.170 +new TestCase( SECTION, "+('+3.14159')", 3.14159, +("+3.14159") ); 1.171 + 1.172 +new TestCase( SECTION, "+('3.')", 3, +("3.") ); 1.173 +new TestCase( SECTION, "+('-3.')", -3, +("-3.") ); 1.174 +new TestCase( SECTION, "+('+3.')", 3, +("+3.") ); 1.175 + 1.176 +new TestCase( SECTION, "+('3.e1')", 30, +("3.e1") ); 1.177 +new TestCase( SECTION, "+('-3.e1')", -30, +("-3.e1") ); 1.178 +new TestCase( SECTION, "+('+3.e1')", 30, +("+3.e1") ); 1.179 + 1.180 +new TestCase( SECTION, "+('3.e+1')", 30, +("3.e+1") ); 1.181 +new TestCase( SECTION, "+('-3.e+1')", -30, +("-3.e+1") ); 1.182 +new TestCase( SECTION, "+('+3.e+1')", 30, +("+3.e+1") ); 1.183 + 1.184 +new TestCase( SECTION, "+('3.e-1')", .30, +("3.e-1") ); 1.185 +new TestCase( SECTION, "+('-3.e-1')", -.30, +("-3.e-1") ); 1.186 +new TestCase( SECTION, "+('+3.e-1')", .30, +("+3.e-1") ); 1.187 + 1.188 +// StrDecimalLiteral::: .DecimalDigits ExponentPart opt 1.189 + 1.190 +new TestCase( SECTION, "+('.00001')", 0.00001, +(".00001") ); 1.191 +new TestCase( SECTION, "+('+.00001')", 0.00001, +("+.00001") ); 1.192 +new TestCase( SECTION, "+('-0.0001')", -0.00001, +("-.00001") ); 1.193 + 1.194 +new TestCase( SECTION, "+('.01e2')", 1, +(".01e2") ); 1.195 +new TestCase( SECTION, "+('+.01e2')", 1, +("+.01e2") ); 1.196 +new TestCase( SECTION, "+('-.01e2')", -1, +("-.01e2") ); 1.197 + 1.198 +new TestCase( SECTION, "+('.01e+2')", 1, +(".01e+2") ); 1.199 +new TestCase( SECTION, "+('+.01e+2')", 1, +("+.01e+2") ); 1.200 +new TestCase( SECTION, "+('-.01e+2')", -1, +("-.01e+2") ); 1.201 + 1.202 +new TestCase( SECTION, "+('.01e-2')", 0.0001, +(".01e-2") ); 1.203 +new TestCase( SECTION, "+('+.01e-2')", 0.0001, +("+.01e-2") ); 1.204 +new TestCase( SECTION, "+('-.01e-2')", -0.0001, +("-.01e-2") ); 1.205 + 1.206 +// StrDecimalLiteral::: DecimalDigits ExponentPart opt 1.207 + 1.208 +new TestCase( SECTION, "+('1234e5')", 123400000, +("1234e5") ); 1.209 +new TestCase( SECTION, "+('+1234e5')", 123400000, +("+1234e5") ); 1.210 +new TestCase( SECTION, "+('-1234e5')", -123400000, +("-1234e5") ); 1.211 + 1.212 +new TestCase( SECTION, "+('1234e+5')", 123400000, +("1234e+5") ); 1.213 +new TestCase( SECTION, "+('+1234e+5')", 123400000, +("+1234e+5") ); 1.214 +new TestCase( SECTION, "+('-1234e+5')", -123400000, +("-1234e+5") ); 1.215 + 1.216 +new TestCase( SECTION, "+('1234e-5')", 0.01234, +("1234e-5") ); 1.217 +new TestCase( SECTION, "+('+1234e-5')", 0.01234, +("+1234e-5") ); 1.218 +new TestCase( SECTION, "+('-1234e-5')", -0.01234, +("-1234e-5") ); 1.219 + 1.220 +// StrNumericLiteral::: HexIntegerLiteral 1.221 + 1.222 +new TestCase( SECTION, "+('0x0')", 0, +("0x0")); 1.223 +new TestCase( SECTION, "+('0x1')", 1, +("0x1")); 1.224 +new TestCase( SECTION, "+('0x2')", 2, +("0x2")); 1.225 +new TestCase( SECTION, "+('0x3')", 3, +("0x3")); 1.226 +new TestCase( SECTION, "+('0x4')", 4, +("0x4")); 1.227 +new TestCase( SECTION, "+('0x5')", 5, +("0x5")); 1.228 +new TestCase( SECTION, "+('0x6')", 6, +("0x6")); 1.229 +new TestCase( SECTION, "+('0x7')", 7, +("0x7")); 1.230 +new TestCase( SECTION, "+('0x8')", 8, +("0x8")); 1.231 +new TestCase( SECTION, "+('0x9')", 9, +("0x9")); 1.232 +new TestCase( SECTION, "+('0xa')", 10, +("0xa")); 1.233 +new TestCase( SECTION, "+('0xb')", 11, +("0xb")); 1.234 +new TestCase( SECTION, "+('0xc')", 12, +("0xc")); 1.235 +new TestCase( SECTION, "+('0xd')", 13, +("0xd")); 1.236 +new TestCase( SECTION, "+('0xe')", 14, +("0xe")); 1.237 +new TestCase( SECTION, "+('0xf')", 15, +("0xf")); 1.238 +new TestCase( SECTION, "+('0xA')", 10, +("0xA")); 1.239 +new TestCase( SECTION, "+('0xB')", 11, +("0xB")); 1.240 +new TestCase( SECTION, "+('0xC')", 12, +("0xC")); 1.241 +new TestCase( SECTION, "+('0xD')", 13, +("0xD")); 1.242 +new TestCase( SECTION, "+('0xE')", 14, +("0xE")); 1.243 +new TestCase( SECTION, "+('0xF')", 15, +("0xF")); 1.244 + 1.245 +new TestCase( SECTION, "+('0X0')", 0, +("0X0")); 1.246 +new TestCase( SECTION, "+('0X1')", 1, +("0X1")); 1.247 +new TestCase( SECTION, "+('0X2')", 2, +("0X2")); 1.248 +new TestCase( SECTION, "+('0X3')", 3, +("0X3")); 1.249 +new TestCase( SECTION, "+('0X4')", 4, +("0X4")); 1.250 +new TestCase( SECTION, "+('0X5')", 5, +("0X5")); 1.251 +new TestCase( SECTION, "+('0X6')", 6, +("0X6")); 1.252 +new TestCase( SECTION, "+('0X7')", 7, +("0X7")); 1.253 +new TestCase( SECTION, "+('0X8')", 8, +("0X8")); 1.254 +new TestCase( SECTION, "+('0X9')", 9, +("0X9")); 1.255 +new TestCase( SECTION, "+('0Xa')", 10, +("0Xa")); 1.256 +new TestCase( SECTION, "+('0Xb')", 11, +("0Xb")); 1.257 +new TestCase( SECTION, "+('0Xc')", 12, +("0Xc")); 1.258 +new TestCase( SECTION, "+('0Xd')", 13, +("0Xd")); 1.259 +new TestCase( SECTION, "+('0Xe')", 14, +("0Xe")); 1.260 +new TestCase( SECTION, "+('0Xf')", 15, +("0Xf")); 1.261 +new TestCase( SECTION, "+('0XA')", 10, +("0XA")); 1.262 +new TestCase( SECTION, "+('0XB')", 11, +("0XB")); 1.263 +new TestCase( SECTION, "+('0XC')", 12, +("0XC")); 1.264 +new TestCase( SECTION, "+('0XD')", 13, +("0XD")); 1.265 +new TestCase( SECTION, "+('0XE')", 14, +("0XE")); 1.266 +new TestCase( SECTION, "+('0XF')", 15, +("0XF")); 1.267 + 1.268 +test();