diff options
Diffstat (limited to 'js/src/tests/ecma_6/Number')
-rw-r--r-- | js/src/tests/ecma_6/Number/15.7.3.7-EPSILON.js | 24 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/20.1.2.10-MIN_SAFE_INTEGER.js | 26 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/20.1.2.6-MAX_SAFE_INTEGER.js | 26 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/20.1.3.2-toExponential.js | 47 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/20.1.3.2-toPrecision.js | 47 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/20.1.3.3-toFixed.js | 17 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/ToNumber.js | 26 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/browser.js | 0 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/isSafeInteger-01.js | 40 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/parseFloat-01.js | 27 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/parseInt-01.js | 172 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/parseInt-default-to-decimal.js | 30 | ||||
-rw-r--r-- | js/src/tests/ecma_6/Number/shell.js | 0 |
13 files changed, 482 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Number/15.7.3.7-EPSILON.js b/js/src/tests/ecma_6/Number/15.7.3.7-EPSILON.js new file mode 100644 index 000000000..55e92ef1c --- /dev/null +++ b/js/src/tests/ecma_6/Number/15.7.3.7-EPSILON.js @@ -0,0 +1,24 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 885798; +var summary = "ES6 (draft May 2013) 15.7.3.7 Number.EPSILON"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// Test value +assertEq(Number.EPSILON, Math.pow(2, -52)); + +// Test property attributes +var descriptor = Object.getOwnPropertyDescriptor(Number, 'EPSILON'); +assertEq(descriptor.writable, false); +assertEq(descriptor.configurable, false); +assertEq(descriptor.enumerable, false); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Number/20.1.2.10-MIN_SAFE_INTEGER.js b/js/src/tests/ecma_6/Number/20.1.2.10-MIN_SAFE_INTEGER.js new file mode 100644 index 000000000..8b96651ff --- /dev/null +++ b/js/src/tests/ecma_6/Number/20.1.2.10-MIN_SAFE_INTEGER.js @@ -0,0 +1,26 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- + +var BUGNUMBER = 885798; +var summary = "ES6 (draft April 2014) 20.1.2.10 Number.MIN_SAFE_INTEGER"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// Test value +assertEq(Number.MIN_SAFE_INTEGER, -(Math.pow(2, 53) - 1)); + +//Test property attributes +var descriptor = Object.getOwnPropertyDescriptor(Number, 'MIN_SAFE_INTEGER'); + +assertEq(descriptor.writable, false); +assertEq(descriptor.configurable, false); +assertEq(descriptor.enumerable, false); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Number/20.1.2.6-MAX_SAFE_INTEGER.js b/js/src/tests/ecma_6/Number/20.1.2.6-MAX_SAFE_INTEGER.js new file mode 100644 index 000000000..e3a2ddff1 --- /dev/null +++ b/js/src/tests/ecma_6/Number/20.1.2.6-MAX_SAFE_INTEGER.js @@ -0,0 +1,26 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- + +var BUGNUMBER = 885798; +var summary = "ES6 (draft April 2014) 20.1.2.6 Number.MAX_SAFE_INTEGER"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// Test value +assertEq(Number.MAX_SAFE_INTEGER, Math.pow(2, 53) - 1); + +//Test property attributes +var descriptor = Object.getOwnPropertyDescriptor(Number, 'MAX_SAFE_INTEGER'); + +assertEq(descriptor.writable, false); +assertEq(descriptor.configurable, false); +assertEq(descriptor.enumerable, false); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Number/20.1.3.2-toExponential.js b/js/src/tests/ecma_6/Number/20.1.3.2-toExponential.js new file mode 100644 index 000000000..f87c750df --- /dev/null +++ b/js/src/tests/ecma_6/Number/20.1.3.2-toExponential.js @@ -0,0 +1,47 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- + +var BUGNUMBER = 818617; +var summary = "ECMAScript 2017 Draft ECMA-262 Section 20.1.3.2: Number.prototype.toExponential"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// With NaN, fractionDigits out of range. +assertEq(Number.prototype.toExponential.call(NaN, 555), 'NaN'); + +// With NaN fractionDigits in range. +assertEq(Number.prototype.toExponential.call(NaN, 5), 'NaN'); + +// With Infinity, fractionDigits out of range. +assertEq(Number.prototype.toExponential.call(Infinity, 555), 'Infinity'); + +// With Infinity, fractionDigits in range. +assertEq(Number.prototype.toExponential.call(Infinity, 5), 'Infinity'); + +// With -Infinity, fractionDigits out of range. +assertEq(Number.prototype.toExponential.call(-Infinity, 555), '-Infinity'); + +// With -Infinity, fractionDigits in range. +assertEq(Number.prototype.toExponential.call(-Infinity, 5), '-Infinity'); + +// With NaN, function assigning a value. +let x = 10; +assertEq(Number.prototype.toExponential.call(NaN, { valueOf() { x = 20; return 1; } }), 'NaN'); +assertEq(x, 20); + +// With NaN, function throwing an exception. +assertThrows(() => Number.prototype.toExponential.call(NaN, { valueOf() { throw "hello"; } })); + +// Not a number throws TypeError +assertThrowsInstanceOf(() => Number.prototype.toExponential.call("Hello"), TypeError); + +if (typeof reportCompare === "function") { + reportCompare(true, true); +} + diff --git a/js/src/tests/ecma_6/Number/20.1.3.2-toPrecision.js b/js/src/tests/ecma_6/Number/20.1.3.2-toPrecision.js new file mode 100644 index 000000000..5c9856044 --- /dev/null +++ b/js/src/tests/ecma_6/Number/20.1.3.2-toPrecision.js @@ -0,0 +1,47 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- + +var BUGNUMBER = 818617; +var summary = "ECMAScript 2017 Draft ECMA-262 Section 20.1.3.5: Number.prototype.toPrecision"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// With NaN, fractionDigits out of range. +assertEq(Number.prototype.toPrecision.call(NaN, 555), 'NaN'); + +// With NaN, fractionDigits in range. +assertEq(Number.prototype.toPrecision.call(NaN, 5), 'NaN'); + +// With Infinity, fractionDigits out of range. +assertEq(Number.prototype.toPrecision.call(Infinity, 555), 'Infinity'); + +// With Infinity, fractionDigits in range. +assertEq(Number.prototype.toPrecision.call(Infinity, 5), 'Infinity'); + +// With -Infinity, fractionDigits out of range. +assertEq(Number.prototype.toPrecision.call(-Infinity, 555), '-Infinity'); + +// With -Infinity, fractionDigits in range. +assertEq(Number.prototype.toPrecision.call(-Infinity, 5), '-Infinity'); + +// With NaN, function assigning a value. +let x = 10; +assertEq(Number.prototype.toPrecision.call(NaN, { valueOf() { x = 20; return 1; } }), 'NaN'); +assertEq(x, 20); + +// With NaN, function throwing an exception. +assertThrows(() => Number.prototype.toPrecision.call(NaN, { valueOf() { throw "hello"; } })); + +// Not a number throws TypeError +assertThrowsInstanceOf(() => Number.prototype.toPrecision.call("Hello"), TypeError); + +if (typeof reportCompare === "function") { + reportCompare(true, true); +} + diff --git a/js/src/tests/ecma_6/Number/20.1.3.3-toFixed.js b/js/src/tests/ecma_6/Number/20.1.3.3-toFixed.js new file mode 100644 index 000000000..28b57ddaa --- /dev/null +++ b/js/src/tests/ecma_6/Number/20.1.3.3-toFixed.js @@ -0,0 +1,17 @@ +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +assertEq(Number.prototype.toFixed.call(-Infinity), "-Infinity"); +assertEq(Number.prototype.toFixed.call(Infinity), "Infinity"); +assertEq(Number.prototype.toFixed.call(NaN), "NaN"); + +assertThrowsInstanceOf(() => Number.prototype.toFixed.call(-Infinity, 555), RangeError); +assertThrowsInstanceOf(() => Number.prototype.toFixed.call(Infinity, 555), RangeError); +assertThrowsInstanceOf(() => Number.prototype.toFixed.call(NaN, 555), RangeError); + +assertThrowsInstanceOf(() => Number.prototype.toFixed.call("Hello"), TypeError); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Number/ToNumber.js b/js/src/tests/ecma_6/Number/ToNumber.js new file mode 100644 index 000000000..5716c8a00 --- /dev/null +++ b/js/src/tests/ecma_6/Number/ToNumber.js @@ -0,0 +1,26 @@ +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +assertEq(Number("0b11"), 3); +assertEq(Number("0B11"), 3); +assertEq(Number(" 0b11 "), 3); +assertEq(Number("0b12"), NaN); +assertEq(Number("-0b11"), NaN); +assertEq(+"0b11", 3); + +assertEq(Number("0o66"), 54); +assertEq(Number("0O66"), 54); +assertEq(Number(" 0o66 "), 54); +assertEq(Number("0o88"), NaN); +assertEq(Number("-0o66"), NaN); +assertEq(+"0o66", 54); + +if(typeof getSelfHostedValue === "function"){ + assertEq(getSelfHostedValue("ToNumber")("0b11"), 3); + assertEq(getSelfHostedValue("ToNumber")("0o66"), 54); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Number/browser.js b/js/src/tests/ecma_6/Number/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_6/Number/browser.js diff --git a/js/src/tests/ecma_6/Number/isSafeInteger-01.js b/js/src/tests/ecma_6/Number/isSafeInteger-01.js new file mode 100644 index 000000000..d1a11cfe3 --- /dev/null +++ b/js/src/tests/ecma_6/Number/isSafeInteger-01.js @@ -0,0 +1,40 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 1003764; +var summary = "ES6 (draft Draft May 22, 2014) ES6 20.1.2.5 Number.isSafeInteger(number)"; + +print(BUGNUMBER + ": " + summary); + +assertEq(Number.isSafeInteger.length, 1); + +assertEq(Number.isSafeInteger({}), false); +assertEq(Number.isSafeInteger(NaN), false); +assertEq(Number.isSafeInteger(+Infinity), false); +assertEq(Number.isSafeInteger(-Infinity), false); + +assertEq(Number.isSafeInteger(-1), true); +assertEq(Number.isSafeInteger(+0), true); +assertEq(Number.isSafeInteger(-0), true); +assertEq(Number.isSafeInteger(1), true); + +assertEq(Number.isSafeInteger(3.2), false); + +assertEq(Number.isSafeInteger(Math.pow(2, 53) - 2), true); +assertEq(Number.isSafeInteger(Math.pow(2, 53) - 1), true); +assertEq(Number.isSafeInteger(Math.pow(2, 53)), false); +assertEq(Number.isSafeInteger(Math.pow(2, 53) + 1), false); +assertEq(Number.isSafeInteger(Math.pow(2, 53) + 2), false); + +assertEq(Number.isSafeInteger(-Math.pow(2, 53) - 2), false); +assertEq(Number.isSafeInteger(-Math.pow(2, 53) - 1), false); +assertEq(Number.isSafeInteger(-Math.pow(2, 53)), false); +assertEq(Number.isSafeInteger(-Math.pow(2, 53) + 1), true); +assertEq(Number.isSafeInteger(-Math.pow(2, 53) + 2), true); + + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/ecma_6/Number/parseFloat-01.js b/js/src/tests/ecma_6/Number/parseFloat-01.js new file mode 100644 index 000000000..8c57e4e12 --- /dev/null +++ b/js/src/tests/ecma_6/Number/parseFloat-01.js @@ -0,0 +1,27 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 886949; +var summary = "ES6 (draft May 2013) 15.7.3.10 Number.parseFloat(string)"; + +print(BUGNUMBER + ": " + summary); + +assertEq(Number.parseFloat("Infinity"), Infinity); +assertEq(Number.parseFloat("+Infinity"), Infinity); +assertEq(Number.parseFloat("-Infinity"), -Infinity); + +assertEq(Number.parseFloat("inf"), NaN); +assertEq(Number.parseFloat("Inf"), NaN); +assertEq(Number.parseFloat("infinity"), NaN); + +assertEq(Number.parseFloat("nan"), NaN); +assertEq(Number.parseFloat("NaN"), NaN); + +/* Number.parseFloat should be the same function object as global parseFloat. */ +assertEq(Number.parseFloat, parseFloat); + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/ecma_6/Number/parseInt-01.js b/js/src/tests/ecma_6/Number/parseInt-01.js new file mode 100644 index 000000000..20bda1872 --- /dev/null +++ b/js/src/tests/ecma_6/Number/parseInt-01.js @@ -0,0 +1,172 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 886949; +var summary = "ES6 (draft May 2013) 15.7.3.9 Number.parseInt(string, radix)"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +var str, radix; +var upvar; + +/* 1. Let inputString be ToString(string). */ + +assertEq(Number.parseInt({ toString: function() { return "17" } }, 10), 17); + +upvar = 0; +str = { get toString() { upvar++; return function() { upvar++; return "12345"; } } }; +assertEq(Number.parseInt(str, 10), 12345); +assertEq(upvar, 2); + + +/* + * 2. Let S be a newly created substring of inputString consisting of the first + * character that is not a StrWhiteSpaceChar and all characters following + * that character. (In other words, remove leading white space.) + */ + +var ws = + ["\t", "\v", "\f", " ", "\xA0", "\uFEFF", + "\u2004", "\u3000", // a few Unicode whitespaces + "\r", "\n", "\u2028", "\u2029"]; + +str = "8675309"; +for (var i = 0, sz = ws.length; i < sz; i++) +{ + assertEq(Number.parseInt(ws[i] + str, 10), 8675309); + for (var j = 0, sz = ws.length; j < sz; j++) + { + assertEq(Number.parseInt(ws[i] + ws[j] + str, 10), 8675309, + ws[i].charCodeAt(0).toString(16) + ", " + + ws[j].charCodeAt(0).toString(16)); + } +} + + +/* + * 3. Let sign be 1. + * 4. If S is not empty and the first character of S is a minus sign -, let + * sign be −1. + */ +str = "5552368"; +assertEq(Number.parseInt("-" + str, 10), -Number.parseInt(str, 10)); +assertEq(Number.parseInt(" -" + str, 10), -Number.parseInt(str, 10)); +assertEq(Number.parseInt("-", 10), NaN); +assertEq(Number.parseInt("", 10), NaN); +assertEq(Number.parseInt("-0", 10), -0); + + +/* + * 5. If S is not empty and the first character of S is a plus sign + or a + * minus sign -, then remove the first character from S. + */ +assertEq(Number.parseInt("+12345", 10), 12345); +assertEq(Number.parseInt(" +12345", 10), 12345); +assertEq(Number.parseInt("-12345", 10), -12345); +assertEq(Number.parseInt(" -12345", 10), -12345); + + +/* + * 6. Let R = ToInt32(radix). + */ + +upvar = ""; +str = + { toString: function() { if (!upvar) upvar = "string"; return "42"; } }; +radix = + { toString: function() { if (!upvar) upvar = "radix"; return "10"; } }; + +assertEq(Number.parseInt(str, radix), 42); +assertEq(upvar, "string"); + +assertEq(Number.parseInt("123", null), 123); +assertEq(Number.parseInt("123", undefined), 123); +assertEq(Number.parseInt("123", NaN), 123); +assertEq(Number.parseInt("123", -0), 123); +assertEq(Number.parseInt("10", 72057594037927950), 16); +assertEq(Number.parseInt("10", -4294967292), 4); +assertEq(Number.parseInt("0x10", 1e308), 16); +assertEq(Number.parseInt("10", 1e308), 10); +assertEq(Number.parseInt("10", { valueOf: function() { return 16; } }), 16); + + +/* + * 7. Let stripPrefix be true. + * 8. If R ≠ 0, then + * a. If R < 2 or R > 36, then return NaN. + * b. If R ≠ 16, let stripPrefix be false. + * 9. Else, R = 0 + * a. Let R = 10. + * 10. If stripPrefix is true, then + * a. If the length of S is at least 2 and the first two characters of S + * are either “0x” or “0X”, then remove the first two characters from S and + * let R = 16. + */ +var vs = ["1", "51", "917", "2343", "99963"]; +for (var i = 0, sz = vs.length; i < sz; i++) + assertEq(Number.parseInt(vs[i], 0), Number.parseInt(vs[i], 10), "bad " + vs[i]); + +assertEq(Number.parseInt("0x10"), 16); +assertEq(Number.parseInt("0x10", 0), 16); +assertEq(Number.parseInt("0x10", 16), 16); +assertEq(Number.parseInt("0x10", 8), 0); +assertEq(Number.parseInt("-0x10", 16), -16); + +assertEq(Number.parseInt("5", 1), NaN); +assertEq(Number.parseInt("5", 37), NaN); +assertEq(Number.parseInt("5", { valueOf: function() { return -1; } }), NaN); + + +/* + * 11. If S contains any character that is not a radix-R digit, then let Z be + * the substring of S consisting of all characters before the first such + * character; otherwise, let Z be S. + * 12. If Z is empty, return NaN. + */ +assertEq(Number.parseInt(""), NaN); +assertEq(Number.parseInt("ohai"), NaN); +assertEq(Number.parseInt("0xohai"), NaN); +assertEq(Number.parseInt("-ohai"), NaN); +assertEq(Number.parseInt("+ohai"), NaN); +assertEq(Number.parseInt(" ohai"), NaN); + +assertEq(Number.parseInt("0xaohai"), 10); +assertEq(Number.parseInt("hohai", 18), 17); + + +/* + * 13. Let mathInt be the mathematical integer value that is represented by Z + * in radix-R notation, using the letters A-Z and a-z for digits with + * values 10 through 35. (However, if R is 10 and Z contains more than 20 + * significant digits, every significant digit after the 20th may be + * replaced by a 0 digit, at the option of the implementation; and if R is + * not 2, 4, 8, 10, 16, or 32, then mathInt may be an implementation- + * dependent approximation to the mathematical integer value that is + * represented by Z in radix-R notation.) + * 14. Let number be the Number value for mathInt. + * 15. Return sign × number. + */ +assertEq(Number.parseInt("ohai", 36), 1142154); +assertEq(Number.parseInt("0ohai", 36), 1142154); +assertEq(Number.parseInt("00ohai", 36), 1142154); +assertEq(Number.parseInt("A", 16), 10); +assertEq(Number.parseInt("0A", 16), 10); +assertEq(Number.parseInt("00A", 16), 10); +assertEq(Number.parseInt("A", 17), 10); +assertEq(Number.parseInt("0A", 17), 10); +assertEq(Number.parseInt("00A", 17), 10); + +/* Number.parseInt should be the same function object as global parseInt. */ +assertEq(Number.parseInt, parseInt); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/ecma_6/Number/parseInt-default-to-decimal.js b/js/src/tests/ecma_6/Number/parseInt-default-to-decimal.js new file mode 100644 index 000000000..7049ef661 --- /dev/null +++ b/js/src/tests/ecma_6/Number/parseInt-default-to-decimal.js @@ -0,0 +1,30 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 886949; +var summary = "ES6 (draft May 2013) 15.7.3.9 Number.parseInt(string, radix)." + + " Verify that Number.parseInt defaults to decimal."; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +assertEq(Number.parseInt("08"), 8); +assertEq(Number.parseInt("09"), 9); +assertEq(Number.parseInt("014"), 14); + +function strictParseInt(s) { "use strict"; return Number.parseInt(s); } + +assertEq(strictParseInt("08"), 8); +assertEq(strictParseInt("09"), 9); +assertEq(strictParseInt("014"), 14); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/ecma_6/Number/shell.js b/js/src/tests/ecma_6/Number/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_6/Number/shell.js |