diff --git a/test/built-ins/BigInt/parseInt/all-decimal-digits.js b/test/built-ins/BigInt/parseInt/all-decimal-digits.js new file mode 100644 index 0000000000..83c3547b8e --- /dev/null +++ b/test/built-ins/BigInt/parseInt/all-decimal-digits.js @@ -0,0 +1,49 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: 01234567890 parsed in different radices +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. + + [...] + + NOTE: parseInt may interpret only a leading portion of string as an + integer value; it ignores any code units that cannot be interpreted as + part of the notation of an integer, and no indication is given that + any such code units were ignored. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("01234567890", 2), 1n); +assert.sameValue(BigInt.parseInt("01234567890", 3), 5n); +assert.sameValue(BigInt.parseInt("01234567890", 4), 27n); +assert.sameValue(BigInt.parseInt("01234567890", 5), 194n); +assert.sameValue(BigInt.parseInt("01234567890", 6), 1865n); +assert.sameValue(BigInt.parseInt("01234567890", 7), 22875n); +assert.sameValue(BigInt.parseInt("01234567890", 8), 342391n); +assert.sameValue(BigInt.parseInt("01234567890", 9), 6053444n); +assert.sameValue(BigInt.parseInt("01234567890", 10), 1234567890n); diff --git a/test/built-ins/BigInt/parseInt/arg-boolean.js b/test/built-ins/BigInt/parseInt/arg-boolean.js new file mode 100644 index 0000000000..d9588e0a5b --- /dev/null +++ b/test/built-ins/BigInt/parseInt/arg-boolean.js @@ -0,0 +1,41 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Boolean argument +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + 1. Let inputString be ? ToString(string). + 2. Let S be a newly created substring of inputString consisting of + the first code unit that is not a StrWhiteSpaceChar and all code + units following that code unit. (In other words, remove leading + white space.) If inputString does not contain any such code unit, + let S be the empty string. + [...] + 11. If S contains a code unit that is not a radix-R digit, let Z be + the substring of S consisting of all code units before the first + such code unit; otherwise, let Z be S. + 12. If Z is empty, return NaN. +features: [BigInt, arrow-function] +---*/ + +assert.throws(SyntaxError, () => BigInt.parseInt(true)); +assert.throws(SyntaxError, () => BigInt.parseInt(false)); +assert.throws(SyntaxError, () => BigInt.parseInt(new Boolean(true))); +assert.throws(SyntaxError, () => BigInt.parseInt(new Boolean(false))); diff --git a/test/built-ins/BigInt/parseInt/arg-number.js b/test/built-ins/BigInt/parseInt/arg-number.js new file mode 100644 index 0000000000..5a5b379d68 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/arg-number.js @@ -0,0 +1,35 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Number argument +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + 1. Let inputString be ? ToString(string). +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt(-1), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt(Infinity)); +assert.throws(SyntaxError, () => BigInt.parseInt(NaN)); +assert.sameValue(BigInt.parseInt(-0), 0n); +assert.sameValue(BigInt.parseInt(new Number(-1)), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt(new Number(Infinity))); +assert.throws(SyntaxError, () => BigInt.parseInt(new Number(NaN))); +assert.sameValue(BigInt.parseInt(new Number(-0)), 0n); diff --git a/test/built-ins/BigInt/parseInt/arg-primitive-coercion.js b/test/built-ins/BigInt/parseInt/arg-primitive-coercion.js new file mode 100644 index 0000000000..3027092601 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/arg-primitive-coercion.js @@ -0,0 +1,50 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Argument converted using ToPrimitive with hint Number +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + 1. Let inputString be ? ToString(string). +features: [BigInt, arrow-function] +---*/ + +var object = {valueOf() {return 1}}; +assert.throws(SyntaxError, () => BigInt.parseInt(object)); + +var object = {valueOf() {return 1}, toString() {return 0}}; +assert.sameValue(BigInt.parseInt(object), 0n); + +var object = {valueOf() {return 1}, toString() {return {}}}; +assert.sameValue(BigInt.parseInt(object), 1n); + +var object = {valueOf() {throw new Test262Error()}, toString() {return 1}}; +assert.sameValue(BigInt.parseInt(object), 1n); + +var object = {toString() {return 1}}; +assert.sameValue(BigInt.parseInt(object), 1n); + +var object = {valueOf() {return {}}, toString() {return 1}}; +assert.sameValue(BigInt.parseInt(object), 1n); + +var object = {valueOf() {return 1}, toString() {throw new Test262Error()}}; +assert.throws(Test262Error, () => BigInt.parseInt(object)); + +var object = {valueOf() {return {}}, toString() {return {}}}; +assert.throws(TypeError, () => BigInt.parseInt(object)); diff --git a/test/built-ins/BigInt/parseInt/arg-string-obj.js b/test/built-ins/BigInt/parseInt/arg-string-obj.js new file mode 100644 index 0000000000..3e81edefdc --- /dev/null +++ b/test/built-ins/BigInt/parseInt/arg-string-obj.js @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: String object argument +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + 1. Let inputString be ? ToString(string). +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt(new String("-1")), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt(new String("Infinity"))); +assert.throws(SyntaxError, () => BigInt.parseInt(new String("NaN"))); +assert.throws(SyntaxError, () => BigInt.parseInt(new String("true"))); +assert.throws(SyntaxError, () => BigInt.parseInt(new String("false"))); diff --git a/test/built-ins/BigInt/parseInt/arg-undefined-null.js b/test/built-ins/BigInt/parseInt/arg-undefined-null.js new file mode 100644 index 0000000000..094e554e75 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/arg-undefined-null.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Undefined or null argument +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 2. Let S be a newly created substring of inputString consisting of + the first code unit that is not a StrWhiteSpaceChar and all code + units following that code unit. (In other words, remove leading + white space.) If inputString does not contain any such code unit, + let S be the empty string. + [...] + 11. If S contains a code unit that is not a radix-R digit, let Z be + the substring of S consisting of all code units before the first + such code unit; otherwise, let Z be S. + 12. If Z is empty, return NaN. +features: [BigInt, arrow-function] +---*/ + +assert.throws(SyntaxError, () => BigInt.parseInt(undefined)); +assert.throws(SyntaxError, () => BigInt.parseInt(null)); diff --git a/test/built-ins/BigInt/parseInt/binary-negative.js b/test/built-ins/BigInt/parseInt/binary-negative.js new file mode 100644 index 0000000000..728743d200 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/binary-negative.js @@ -0,0 +1,62 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Negative binary argument with radix 2 +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. + + The parseInt function is the %parseInt% intrinsic object. When the + parseInt function is called, the following steps are taken: + + [...] + 4. If S is not empty and the first code unit of S is the code unit + 0x002D (HYPHEN-MINUS), let sign be -1. + [...] + 16. Return sign × number. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("-1", 2), -1n); +assert.sameValue(BigInt.parseInt("-11", 2), -3n); +assert.sameValue(BigInt.parseInt("-111", 2), -7n); +assert.sameValue(BigInt.parseInt("-1111", 2), -15n); +assert.sameValue(BigInt.parseInt("-11111", 2), -31n); +assert.sameValue(BigInt.parseInt("-111111", 2), -63n); +assert.sameValue(BigInt.parseInt("-1111111", 2), -127n); +assert.sameValue(BigInt.parseInt("-11111111", 2), -255n); +assert.sameValue(BigInt.parseInt("-111111111", 2), -511n); +assert.sameValue(BigInt.parseInt("-1111111111", 2), -1023n); +assert.sameValue(BigInt.parseInt("-11111111111", 2), -2047n); +assert.sameValue(BigInt.parseInt("-111111111111", 2), -4095n); +assert.sameValue(BigInt.parseInt("-1111111111111", 2), -8191n); +assert.sameValue(BigInt.parseInt("-11111111111111", 2), -16383n); +assert.sameValue(BigInt.parseInt("-111111111111111", 2), -32767n); +assert.sameValue(BigInt.parseInt("-1111111111111111", 2), -65535n); +assert.sameValue(BigInt.parseInt("-11111111111111111", 2), -131071n); +assert.sameValue(BigInt.parseInt("-111111111111111111", 2), -262143n); +assert.sameValue(BigInt.parseInt("-1111111111111111111", 2), -524287n); +assert.sameValue(BigInt.parseInt("-11111111111111111111", 2), -1048575n); diff --git a/test/built-ins/BigInt/parseInt/binary.js b/test/built-ins/BigInt/parseInt/binary.js new file mode 100644 index 0000000000..5d2e8df023 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/binary.js @@ -0,0 +1,53 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Binary string argument with radix 2 +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("1", 2), 1n); +assert.sameValue(BigInt.parseInt("11", 2), 3n); +assert.sameValue(BigInt.parseInt("111", 2), 7n); +assert.sameValue(BigInt.parseInt("1111", 2), 15n); +assert.sameValue(BigInt.parseInt("11111", 2), 31n); +assert.sameValue(BigInt.parseInt("111111", 2), 63n); +assert.sameValue(BigInt.parseInt("1111111", 2), 127n); +assert.sameValue(BigInt.parseInt("11111111", 2), 255n); +assert.sameValue(BigInt.parseInt("111111111", 2), 511n); +assert.sameValue(BigInt.parseInt("1111111111", 2), 1023n); +assert.sameValue(BigInt.parseInt("11111111111", 2), 2047n); +assert.sameValue(BigInt.parseInt("111111111111", 2), 4095n); +assert.sameValue(BigInt.parseInt("1111111111111", 2), 8191n); +assert.sameValue(BigInt.parseInt("11111111111111", 2), 16383n); +assert.sameValue(BigInt.parseInt("111111111111111", 2), 32767n); +assert.sameValue(BigInt.parseInt("1111111111111111", 2), 65535n); +assert.sameValue(BigInt.parseInt("11111111111111111", 2), 131071n); +assert.sameValue(BigInt.parseInt("111111111111111111", 2), 262143n); +assert.sameValue(BigInt.parseInt("1111111111111111111", 2), 524287n); +assert.sameValue(BigInt.parseInt("11111111111111111111", 2), 1048575n); diff --git a/test/built-ins/BigInt/parseInt/decimal-negative.js b/test/built-ins/BigInt/parseInt/decimal-negative.js new file mode 100644 index 0000000000..b0857afc2a --- /dev/null +++ b/test/built-ins/BigInt/parseInt/decimal-negative.js @@ -0,0 +1,51 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Negative decimal string argument with radix 10 +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 4. If S is not empty and the first code unit of S is the code unit + 0x002D (HYPHEN-MINUS), let sign be -1. + [...] + 16. Return sign × number. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("-1", 10), -1n); +assert.sameValue(BigInt.parseInt("-10", 10), -10n); +assert.sameValue(BigInt.parseInt("-100", 10), -100n); +assert.sameValue(BigInt.parseInt("-1000", 10), -1000n); +assert.sameValue(BigInt.parseInt("-10000", 10), -10000n); +assert.sameValue(BigInt.parseInt("-100000", 10), -100000n); +assert.sameValue(BigInt.parseInt("-1000000", 10), -1000000n); +assert.sameValue(BigInt.parseInt("-10000000", 10), -10000000n); +assert.sameValue(BigInt.parseInt("-100000000", 10), -100000000n); +assert.sameValue(BigInt.parseInt("-1000000000", 10), -1000000000n); +assert.sameValue(BigInt.parseInt("-10000000000", 10), -10000000000n); +assert.sameValue(BigInt.parseInt("-100000000000", 10), -100000000000n); +assert.sameValue(BigInt.parseInt("-1000000000000", 10), -1000000000000n); +assert.sameValue(BigInt.parseInt("-10000000000000", 10), -10000000000000n); +assert.sameValue(BigInt.parseInt("-100000000000000", 10), -100000000000000n); +assert.sameValue(BigInt.parseInt("-1000000000000000", 10), -1000000000000000n); +assert.sameValue(BigInt.parseInt("-10000000000000000", 10), -10000000000000000n); +assert.sameValue(BigInt.parseInt("-100000000000000000", 10), -100000000000000000n); +assert.sameValue(BigInt.parseInt("-1000000000000000000", 10), -1000000000000000000n); +assert.sameValue(BigInt.parseInt("-10000000000000000000", 10), -10000000000000000000n); diff --git a/test/built-ins/BigInt/parseInt/empty-with-radix.js b/test/built-ins/BigInt/parseInt/empty-with-radix.js new file mode 100644 index 0000000000..9c5ac378bb --- /dev/null +++ b/test/built-ins/BigInt/parseInt/empty-with-radix.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: SyntaxError thrown for invalid strings +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 2. Let S be a newly created substring of inputString consisting of + the first code unit that is not a StrWhiteSpaceChar and all code + units following that code unit. (In other words, remove leading + white space.) If inputString does not contain any such code unit, + let S be the empty string. + [...] + 11. If S contains a code unit that is not a radix-R digit, let Z be + the substring of S consisting of all code units before the first + such code unit; otherwise, let Z be S. + 12. If Z is empty, return NaN. +features: [BigInt, arrow-function] +---*/ + +for (var i = 2; i <= 36; i++) { + assert.throws(SyntaxError, () => BigInt.parseInt("$0x", i), "$0x radix " + i); + assert.throws(SyntaxError, () => BigInt.parseInt("$0X", i), "$0X radix " + i); + assert.throws(SyntaxError, () => BigInt.parseInt("$$$", i), "$$$ radix " + i); + assert.throws(SyntaxError, () => BigInt.parseInt("", i), "the empty string, radix " + i); + assert.throws(SyntaxError, () => BigInt.parseInt(" ", i), "a string with a single space, radix " + i); +} diff --git a/test/built-ins/BigInt/parseInt/empty.js b/test/built-ins/BigInt/parseInt/empty.js new file mode 100644 index 0000000000..409495b663 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/empty.js @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: SyntaxError thrown for invalid strings +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 2. Let S be a newly created substring of inputString consisting of + the first code unit that is not a StrWhiteSpaceChar and all code + units following that code unit. (In other words, remove leading + white space.) If inputString does not contain any such code unit, + let S be the empty string. + [...] + 11. If S contains a code unit that is not a radix-R digit, let Z be + the substring of S consisting of all code units before the first + such code unit; otherwise, let Z be S. + 12. If Z is empty, return NaN. +features: [BigInt, arrow-function] +---*/ + +assert.throws(SyntaxError, () => BigInt.parseInt("$0x"), "$0x"); +assert.throws(SyntaxError, () => BigInt.parseInt("$0X"), "$0X"); +assert.throws(SyntaxError, () => BigInt.parseInt("$$$"), "$$$"); +assert.throws(SyntaxError, () => BigInt.parseInt(""), "the empty string"); +assert.throws(SyntaxError, () => BigInt.parseInt(" "), "a string with a single space"); diff --git a/test/built-ins/BigInt/parseInt/hex-prefix-lc.js b/test/built-ins/BigInt/parseInt/hex-prefix-lc.js new file mode 100644 index 0000000000..294412c7fe --- /dev/null +++ b/test/built-ins/BigInt/parseInt/hex-prefix-lc.js @@ -0,0 +1,68 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: String argument with hexadecimal prefix and zero radix +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("0x0", 0), 0x0n); + +assert.sameValue(BigInt.parseInt("0x1", 0), 0x1n); + +assert.sameValue(BigInt.parseInt("0x2", 0), 0x2n); + +assert.sameValue(BigInt.parseInt("0x3", 0), 0x3n); + +assert.sameValue(BigInt.parseInt("0x4", 0), 0x4n); + +assert.sameValue(BigInt.parseInt("0x5", 0), 0x5n); + +assert.sameValue(BigInt.parseInt("0x6", 0), 0x6n); + +assert.sameValue(BigInt.parseInt("0x7", 0), 0x7n); + +assert.sameValue(BigInt.parseInt("0x8", 0), 0x8n); + +assert.sameValue(BigInt.parseInt("0x9", 0), 0x9n); + +assert.sameValue(BigInt.parseInt("0xA", 0), 0xAn); + +assert.sameValue(BigInt.parseInt("0xB", 0), 0xBn); + +assert.sameValue(BigInt.parseInt("0xC", 0), 0xCn); + +assert.sameValue(BigInt.parseInt("0xD", 0), 0xDn); + +assert.sameValue(BigInt.parseInt("0xE", 0), 0xEn); + +assert.sameValue(BigInt.parseInt("0xF", 0), 0xFn); + +assert.sameValue(BigInt.parseInt("0xE", 0), 0xEn); + +assert.sameValue(BigInt.parseInt("0xABCDEF", 0), 0xABCDEFn); diff --git a/test/built-ins/BigInt/parseInt/hex-prefix-uc.js b/test/built-ins/BigInt/parseInt/hex-prefix-uc.js new file mode 100644 index 0000000000..e14e4582da --- /dev/null +++ b/test/built-ins/BigInt/parseInt/hex-prefix-uc.js @@ -0,0 +1,68 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: String argument with hexadecimal prefix and zero radix +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("0X0", 0), 0x0n); + +assert.sameValue(BigInt.parseInt("0X1"), 0x1n); + +assert.sameValue(BigInt.parseInt("0X2"), 0x2n); + +assert.sameValue(BigInt.parseInt("0X3"), 0x3n); + +assert.sameValue(BigInt.parseInt("0X4"), 0x4n); + +assert.sameValue(BigInt.parseInt("0X5"), 0x5n); + +assert.sameValue(BigInt.parseInt("0X6"), 0x6n); + +assert.sameValue(BigInt.parseInt("0X7"), 0x7n); + +assert.sameValue(BigInt.parseInt("0X8"), 0x8n); + +assert.sameValue(BigInt.parseInt("0X9"), 0x9n); + +assert.sameValue(BigInt.parseInt("0XA"), 0xAn); + +assert.sameValue(BigInt.parseInt("0XB"), 0xBn); + +assert.sameValue(BigInt.parseInt("0XC"), 0xCn); + +assert.sameValue(BigInt.parseInt("0XD"), 0xDn); + +assert.sameValue(BigInt.parseInt("0XE"), 0xEn); + +assert.sameValue(BigInt.parseInt("0XF"), 0xFn); + +assert.sameValue(BigInt.parseInt("0XE"), 0xEn); + +assert.sameValue(BigInt.parseInt("0XABCDEF"), 0xABCDEFn); diff --git a/test/built-ins/BigInt/parseInt/hex.js b/test/built-ins/BigInt/parseInt/hex.js new file mode 100644 index 0000000000..172437c8df --- /dev/null +++ b/test/built-ins/BigInt/parseInt/hex.js @@ -0,0 +1,53 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Hexadecimal string argument with radix 16 +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("0x1", 16), 1n); +assert.sameValue(BigInt.parseInt("0X10", 16), 16n); +assert.sameValue(BigInt.parseInt("0x100", 16), 256n); +assert.sameValue(BigInt.parseInt("0X1000", 16), 4096n); +assert.sameValue(BigInt.parseInt("0x10000", 16), 65536n); +assert.sameValue(BigInt.parseInt("0X100000", 16), 1048576n); +assert.sameValue(BigInt.parseInt("0x1000000", 16), 16777216n); +assert.sameValue(BigInt.parseInt("0x10000000", 16), 268435456n); +assert.sameValue(BigInt.parseInt("0x100000000", 16), 4294967296n); +assert.sameValue(BigInt.parseInt("0x1000000000", 16), 68719476736n); +assert.sameValue(BigInt.parseInt("0x10000000000", 16), 1099511627776n); +assert.sameValue(BigInt.parseInt("0x100000000000", 16), 17592186044416n); +assert.sameValue(BigInt.parseInt("0x1000000000000", 16), 281474976710656n); +assert.sameValue(BigInt.parseInt("0x10000000000000", 16), 4503599627370496n); +assert.sameValue(BigInt.parseInt("0x100000000000000", 16), 72057594037927936n); +assert.sameValue(BigInt.parseInt("0x1000000000000000", 16), 1152921504606846976n); +assert.sameValue(BigInt.parseInt("0x10000000000000000", 16), 18446744073709551616n); +assert.sameValue(BigInt.parseInt("0x100000000000000000", 16), 295147905179352825856n); +assert.sameValue(BigInt.parseInt("0x1000000000000000000", 16), 4722366482869645213696n); +assert.sameValue(BigInt.parseInt("0x10000000000000000000", 16), 75557863725914323419136n); diff --git a/test/built-ins/BigInt/parseInt/leading-cr.js b/test/built-ins/BigInt/parseInt/leading-cr.js new file mode 100644 index 0000000000..a3fa1eb8aa --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-cr.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+000D) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u000D1"), 1n); +assert.sameValue(BigInt.parseInt("\u000D\u000D-1"), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt("\u000D")); diff --git a/test/built-ins/BigInt/parseInt/leading-ff.js b/test/built-ins/BigInt/parseInt/leading-ff.js new file mode 100644 index 0000000000..496db236d7 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-ff.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+000C) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u000C1"), 1n); +assert.sameValue(BigInt.parseInt("\u000C\u000C-1"), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt("\u000C")); diff --git a/test/built-ins/BigInt/parseInt/leading-lf.js b/test/built-ins/BigInt/parseInt/leading-lf.js new file mode 100644 index 0000000000..7ecdf521ed --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-lf.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+000A) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u000A1"), 1n); +assert.sameValue(BigInt.parseInt("\u000A\u000A-1"), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt("\u000A")); diff --git a/test/built-ins/BigInt/parseInt/leading-ls.js b/test/built-ins/BigInt/parseInt/leading-ls.js new file mode 100644 index 0000000000..42fcca4e11 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-ls.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+2028) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u20281"), 1n); +assert.sameValue(BigInt.parseInt("\u2028\u2028-1"), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt("\u2028")); diff --git a/test/built-ins/BigInt/parseInt/leading-nbsp.js b/test/built-ins/BigInt/parseInt/leading-nbsp.js new file mode 100644 index 0000000000..95150877e4 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-nbsp.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+00A0) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u00A01"), 1n); +assert.sameValue(BigInt.parseInt("\u00A0\u00A0-1"), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt("\u00A0")); diff --git a/test/built-ins/BigInt/parseInt/leading-ps.js b/test/built-ins/BigInt/parseInt/leading-ps.js new file mode 100644 index 0000000000..beed606535 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-ps.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+2029) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u20291"), 1n); +assert.sameValue(BigInt.parseInt("\u2029\u2029-1"), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt("\u2029")); diff --git a/test/built-ins/BigInt/parseInt/leading-space.js b/test/built-ins/BigInt/parseInt/leading-space.js new file mode 100644 index 0000000000..fce9909443 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-space.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+0020) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u00201"), 1n); +assert.sameValue(BigInt.parseInt("\u0020\u0020-1"), -1n); +assert.sameValue(BigInt.parseInt(" 1"), 1n); +assert.sameValue(BigInt.parseInt(" 1"), 1n); +assert.sameValue(BigInt.parseInt(" \u0020 \u0020-1"), -1n) +assert.throws(SyntaxError, () => BigInt.parseInt("\u0020")); diff --git a/test/built-ins/BigInt/parseInt/leading-tab.js b/test/built-ins/BigInt/parseInt/leading-tab.js new file mode 100644 index 0000000000..6a5937045a --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-tab.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+0009) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u00091"), 1n); +assert.sameValue(BigInt.parseInt("\u0009\u0009-1"), -1n); +assert.sameValue(BigInt.parseInt(" 1"), 1n); +assert.sameValue(BigInt.parseInt(" 1"), 1n); +assert.sameValue(BigInt.parseInt(" \u0009 \u0009-1"), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt("\u0009")); diff --git a/test/built-ins/BigInt/parseInt/leading-u180e.js b/test/built-ins/BigInt/parseInt/leading-u180e.js new file mode 100644 index 0000000000..d23a700638 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-u180e.js @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading non-whitespace (U+180E) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + 1. Let inputString be ? ToString(string). + 2. Let S be a newly created substring of inputString consisting of + the first code unit that is not a StrWhiteSpaceChar and all code + units following that code unit. (In other words, remove leading + white space.) If inputString does not contain any such code unit, + let S be the empty string. + [...] + 11. If S contains a code unit that is not a radix-R digit, let Z be + the substring of S consisting of all code units before the first + such code unit; otherwise, let Z be S. + 12. If Z is empty, return NaN. +features: [BigInt, arrow-function] +---*/ + +var mongolianVowelSeparator = "\u180E"; + +assert.throws(SyntaxError, () => BigInt.parseInt(mongolianVowelSeparator + "1"), "Single leading U+180E"); +assert.throws(SyntaxError, () => BigInt.parseInt(mongolianVowelSeparator + mongolianVowelSeparator + mongolianVowelSeparator + "1"), "Multiple leading U+180E"); +assert.throws(SyntaxError, () => BigInt.parseInt(mongolianVowelSeparator), "Only U+180E"); diff --git a/test/built-ins/BigInt/parseInt/leading-vt.js b/test/built-ins/BigInt/parseInt/leading-vt.js new file mode 100644 index 0000000000..84cbb8eb4b --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-vt.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace (U+000B) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("\u000B1"), 1n); +assert.sameValue(BigInt.parseInt("\u000B\u000B-1"), -1n); +assert.throws(SyntaxError, () => BigInt.parseInt("\u000B")); diff --git a/test/built-ins/BigInt/parseInt/leading-ws.js b/test/built-ins/BigInt/parseInt/leading-ws.js new file mode 100644 index 0000000000..efd47037b2 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/leading-ws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Leading whitespace +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt, arrow-function] +---*/ + +var uspU = ["\u1680", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u202F", "\u205F", "\u3000"]; + +for (var index = 0; index < uspU.length; index++) { + assert.sameValue(BigInt.parseInt(uspU[index] + "1"), 1n); + assert.sameValue(BigInt.parseInt(uspU[index] + uspU[index] + uspU[index] + "1"), 1n); + assert.throws(SyntaxError, () => BigInt.parseInt(uspU[index])); +} diff --git a/test/built-ins/BigInt/parseInt/length.js b/test/built-ins/BigInt/parseInt/length.js new file mode 100644 index 0000000000..d937521ee4 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: BigInt.parseInt.length property descriptor +info: > + BigInt.parseInt ( string , radix ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in + function object has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.parseInt, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/BigInt/parseInt/mixed-case-signed.js b/test/built-ins/BigInt/parseInt/mixed-case-signed.js new file mode 100644 index 0000000000..b70efb49a3 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/mixed-case-signed.js @@ -0,0 +1,67 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Mixed-case digits and sign +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. + + The parseInt function is the %parseInt% intrinsic object. When the + parseInt function is called, the following steps are taken: + + [...] + 4. If S is not empty and the first code unit of S is the code unit + 0x002D (HYPHEN-MINUS), let sign be -1. + [...] + 16. Return sign × number. +features: [BigInt] +---*/ + +var R_digit1 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; +var R_digit2 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; +for (var i = 2; i <= 36; i++) { + for (var j = 0; j < 10; j++) { + var str = "+"; + var sign = 1; + if (j % 2 !== 0) { + str = "-"; + sign= -1; + } + var num = 0; + var pow = 1; + var k0 = Math.max(2, i - j); + for (var k = k0; k <= i; k++) { + if (k % 2 === 0) { + str = str + R_digit1[k - 2]; + } else { + str = str + R_digit2[k - 2]; + } + num = num + (i + (k0 - k) - 1) * pow; + pow = pow * i; + } + assert.sameValue(BigInt.parseInt(str, i), BigInt(num * sign)); + } +} diff --git a/test/built-ins/BigInt/parseInt/mixed-case-unsigned.js b/test/built-ins/BigInt/parseInt/mixed-case-unsigned.js new file mode 100644 index 0000000000..eca2758acb --- /dev/null +++ b/test/built-ins/BigInt/parseInt/mixed-case-unsigned.js @@ -0,0 +1,53 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Mixed-case digits +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. +features: [BigInt] +---*/ + +var R_digit1 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; +var R_digit2 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; +for (var i = 2; i <= 36; i++) { + for (var j = 0; j < 10; j++) { + var str = ""; + var num = 0; + var pow = 1; + var k0 = Math.max(2, i - j); + for (var k = k0; k <= i; k++) { + if (k % 2 === 0) { + str = str + R_digit1[k - 2]; + } else { + str = str + R_digit2[k - 2]; + } + num = num + (i + (k0 - k) - 1) * pow; + pow = pow * i; + } + assert.sameValue(BigInt.parseInt(str, i), BigInt(num)); + } +} diff --git a/test/built-ins/BigInt/parseInt/name.js b/test/built-ins/BigInt/parseInt/name.js new file mode 100644 index 0000000000..7b7952b309 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/name.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: BigInt.parseInt.name property descriptor +info: > + BigInt.parseInt ( string , radix ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. Unless otherwise specified, this value is the name that + is given to the function in this specification. For functions that + are specified as properties of objects, the name value is the + property name string used to access the function. [...] + + Unless otherwise specified, the name property of a built-in function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.parseInt, "name", { + value: "parseInt", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/BigInt/parseInt/no-prototype.js b/test/built-ins/BigInt/parseInt/no-prototype.js new file mode 100644 index 0000000000..690ccecb61 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/no-prototype.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: BigInt.parseInt.prototype is undefined + BigInt.parseInt ( string , radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + 9.3 Built-in Function Objects + + Built-in functions that are not constructors do not have a prototype + property unless otherwise specified in the description of a + particular function. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt.prototype, undefined); diff --git a/test/built-ins/BigInt/parseInt/not-constructor.js b/test/built-ins/BigInt/parseInt/not-constructor.js new file mode 100644 index 0000000000..87322a0410 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/not-constructor.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: BigInt.parseInt is not a constructor +info: > + BigInt.parseInt ( string , radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + 9.3 Built-in Function Objects + + Built-in function objects that are not identified as constructors do + not implement the [[Construct]] internal method unless otherwise + specified in the description of a particular function. +features: [BigInt, arrow-function] +---*/ + +assert.throws(TypeError, () => new BigInt.parseInt()); diff --git a/test/built-ins/BigInt/parseInt/octal-prefix.js b/test/built-ins/BigInt/parseInt/octal-prefix.js new file mode 100644 index 0000000000..15c7a5e463 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/octal-prefix.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: String argument with octal prefix +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to + the specified radix. Leading white space in string is ignored. If + radix is undefined or 0, it is assumed to be 10 except when the + number begins with the code unit pairs 0x or 0X, in which case a + radix of 16 is assumed. If radix is 16, the number may also + optionally begin with the code unit pairs 0x or 0X. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("010"), 10n, "parseInt should no longer accept octal"); diff --git a/test/built-ins/BigInt/parseInt/parseInt.js b/test/built-ins/BigInt/parseInt/parseInt.js index e41681d66c..fefedc5af6 100644 --- a/test/built-ins/BigInt/parseInt/parseInt.js +++ b/test/built-ins/BigInt/parseInt/parseInt.js @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Robin Templeton. All rights reserved. +// Copyright (C) 2017 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/test/built-ins/BigInt/parseInt/prop-desc.js b/test/built-ins/BigInt/parseInt/prop-desc.js new file mode 100644 index 0000000000..5952121d29 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/prop-desc.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: BigInt.parseInt property descriptor +info: > + BigInt.parseInt ( string, radix ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt, "parseInt", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/BigInt/parseInt/radix-37.js b/test/built-ins/BigInt/parseInt/radix-37.js new file mode 100644 index 0000000000..8baa92f533 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-37.js @@ -0,0 +1,41 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Invalid radix (37) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 8. If R ≠ 0, then + a. If R < 2 or R > 36, return NaN. +features: [BigInt, arrow-function] +---*/ + +assert.throws(SyntaxError, () => BigInt.parseInt("0", 37), "0"); +assert.throws(SyntaxError, () => BigInt.parseInt("1", 37), "1"); +assert.throws(SyntaxError, () => BigInt.parseInt("2", 37), "2"); +assert.throws(SyntaxError, () => BigInt.parseInt("3", 37), "3"); +assert.throws(SyntaxError, () => BigInt.parseInt("4", 37), "4"); +assert.throws(SyntaxError, () => BigInt.parseInt("5", 37), "5"); +assert.throws(SyntaxError, () => BigInt.parseInt("6", 37), "6"); +assert.throws(SyntaxError, () => BigInt.parseInt("7", 37), "7"); +assert.throws(SyntaxError, () => BigInt.parseInt("8", 37), "8"); +assert.throws(SyntaxError, () => BigInt.parseInt("9", 37), "9"); +assert.throws(SyntaxError, () => BigInt.parseInt("10", 37), "10"); +assert.throws(SyntaxError, () => BigInt.parseInt("11", 37), "11"); diff --git a/test/built-ins/BigInt/parseInt/radix-boolean.js b/test/built-ins/BigInt/parseInt/radix-boolean.js new file mode 100644 index 0000000000..683e38d289 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-boolean.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Boolean radix +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 6. Let R be ? ToInt32(radix). + 7. Let stripPrefix be true. + 8. If R ≠ 0, then + a. If R < 2 or R > 36, return NaN. + b. If R ≠ 16, let stripPrefix be false. + 9. Else R = 0, + a. Let R be 10. + [...] +features: [BigInt, arrow-function] +---*/ + +assert.sameValue(BigInt.parseInt("11", false), 11n); +assert.throws(SyntaxError, () => BigInt.parseInt("11", true)); +assert.sameValue(BigInt.parseInt("11", new Boolean(false)), 11n); +assert.throws(SyntaxError, () => BigInt.parseInt("11", new Boolean(true))); diff --git a/test/built-ins/BigInt/parseInt/radix-int32.js b/test/built-ins/BigInt/parseInt/radix-int32.js new file mode 100644 index 0000000000..6e0776a65e --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-int32.js @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Radix converted using ToInt32 +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 6. Let R be ? ToInt32(radix). +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("11", 2.1), 0b11n); +assert.sameValue(BigInt.parseInt("11", 2.5), 0b11n); +assert.sameValue(BigInt.parseInt("11", 2.9), 0b11n); +assert.sameValue(BigInt.parseInt("11", 2.000000000001), 0b11n); +assert.sameValue(BigInt.parseInt("11", 2.999999999999), 0b11n); +assert.sameValue(BigInt.parseInt("11", 4294967298), 0b11n); +assert.sameValue(BigInt.parseInt("11", 4294967296), 11n); +assert.throws(SyntaxError, () => BigInt.parseInt("11", -2147483650), "-2147483650"); +assert.sameValue(BigInt.parseInt("11", -4294967294), 0b11n); +assert.sameValue(BigInt.parseInt("11", NaN), 11n); +assert.sameValue(BigInt.parseInt("11", +0), 11n); +assert.sameValue(BigInt.parseInt("11", -0), 11n); +assert.sameValue(BigInt.parseInt("11", Number.POSITIVE_INFINITY), 11n); +assert.sameValue(BigInt.parseInt("11", Number.NEGATIVE_INFINITY), 11n); diff --git a/test/built-ins/BigInt/parseInt/radix-number-obj.js b/test/built-ins/BigInt/parseInt/radix-number-obj.js new file mode 100644 index 0000000000..e311a659f7 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-number-obj.js @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Number object radix +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 6. Let R be ? ToInt32(radix). +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("11", new Number(2)), 0b11n); +assert.sameValue(BigInt.parseInt("11", new Number(Infinity)), 11n); diff --git a/test/built-ins/BigInt/parseInt/radix-one.js b/test/built-ins/BigInt/parseInt/radix-one.js new file mode 100644 index 0000000000..1a5e1694cb --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-one.js @@ -0,0 +1,41 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Invalid radix (1) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 8. If R ≠ 0, then + a. If R < 2 or R > 36, return NaN. +features: [BigInt, arrow-function] +---*/ + +assert.throws(SyntaxError, () => BigInt.parseInt("0", 1), "0"); +assert.throws(SyntaxError, () => BigInt.parseInt("1", 1), "1"); +assert.throws(SyntaxError, () => BigInt.parseInt("2", 1), "2"); +assert.throws(SyntaxError, () => BigInt.parseInt("3", 1), "3"); +assert.throws(SyntaxError, () => BigInt.parseInt("4", 1), "4"); +assert.throws(SyntaxError, () => BigInt.parseInt("5", 1), "5"); +assert.throws(SyntaxError, () => BigInt.parseInt("6", 1), "6"); +assert.throws(SyntaxError, () => BigInt.parseInt("7", 1), "7"); +assert.throws(SyntaxError, () => BigInt.parseInt("8", 1), "8"); +assert.throws(SyntaxError, () => BigInt.parseInt("9", 1), "9"); +assert.throws(SyntaxError, () => BigInt.parseInt("10", 1), "10"); +assert.throws(SyntaxError, () => BigInt.parseInt("11", 1), "11"); diff --git a/test/built-ins/BigInt/parseInt/radix-primitive-coercion.js b/test/built-ins/BigInt/parseInt/radix-primitive-coercion.js new file mode 100644 index 0000000000..11490fb4c4 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-primitive-coercion.js @@ -0,0 +1,51 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Radix converted using ToInt32 +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 6. Let R be ? ToInt32(radix). +features: [BigInt, arrow-function] +---*/ + +var object = {valueOf() {return 2}}; +assert.sameValue(BigInt.parseInt("11", object), 0b11n); + +var object = {valueOf() {return 2}, toString() {return 1}}; +assert.sameValue(BigInt.parseInt("11", object), 0b11n); + +var object = {valueOf() {return 2}, toString() {return {}}}; +assert.sameValue(BigInt.parseInt("11", object), 0b11n); + +var object = {valueOf() {return 2}, toString() {throw new Test262Error()}}; +assert.sameValue(BigInt.parseInt("11", object), 0b11n); + +var object = {toString() {return 2}}; +assert.sameValue(BigInt.parseInt("11", object), 0b11n); + +var object = {valueOf() {return {}}, toString() {return 2}} +assert.sameValue(BigInt.parseInt("11", object), 0b11n); + +var object = {valueOf() {throw new Test262Error()}, toString() {return 2}}; +assert.throws(Test262Error, () => BigInt.parseInt("11", object)); + +var object = {valueOf() {return {}}, toString() {return {}}}; +assert.throws(TypeError, () => BigInt.parseInt("11", object)); diff --git a/test/built-ins/BigInt/parseInt/radix-string.js b/test/built-ins/BigInt/parseInt/radix-string.js new file mode 100644 index 0000000000..d41406f5ee --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-string.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: String radix +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 6. Let R be ? ToInt32(radix). +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("11", "2"), 0b11n); +assert.sameValue(BigInt.parseInt("11", "0"), 11n); +assert.sameValue(BigInt.parseInt("11", ""), 11n); +assert.sameValue(BigInt.parseInt("11", new String("2")), 0b11n); +assert.sameValue(BigInt.parseInt("11", new String("Infinity")), 11n); +assert.sameValue(BigInt.parseInt("11", new String("")), 11n); diff --git a/test/built-ins/BigInt/parseInt/radix-undefined-or-null.js b/test/built-ins/BigInt/parseInt/radix-undefined-or-null.js new file mode 100644 index 0000000000..73cfdf8fe5 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-undefined-or-null.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Radix is undefined or null +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 6. Let R be ? ToInt32(radix). + [...] + 9. Else R = 0, + a. Let R be 10. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("11", undefined), 11n); +assert.sameValue(BigInt.parseInt("11", null), 11n); diff --git a/test/built-ins/BigInt/parseInt/radix-undefined.js b/test/built-ins/BigInt/parseInt/radix-undefined.js new file mode 100644 index 0000000000..10036e5846 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-undefined.js @@ -0,0 +1,56 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Radix is undefined +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 6. Let R be ? ToInt32(radix). + [...] + 9. Else R = 0, + a. Let R be 10. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("0"), 0n); + +assert.sameValue(BigInt.parseInt("1"), 1n); + +assert.sameValue(BigInt.parseInt("2"), 2n); + +assert.sameValue(BigInt.parseInt("3"), 3n); + +assert.sameValue(BigInt.parseInt("4"), 4n); + +assert.sameValue(BigInt.parseInt("5"), 5n); + +assert.sameValue(BigInt.parseInt("6"), 6n); + +assert.sameValue(BigInt.parseInt("7"), 7n); + +assert.sameValue(BigInt.parseInt("8"), 8n); + +assert.sameValue(BigInt.parseInt("9"), 9n); + +assert.sameValue(BigInt.parseInt("10"), 10n); + +assert.sameValue(BigInt.parseInt("11"), 11n); + +assert.sameValue(BigInt.parseInt("9999"), 9999n); diff --git a/test/built-ins/BigInt/parseInt/radix-zero.js b/test/built-ins/BigInt/parseInt/radix-zero.js new file mode 100644 index 0000000000..586661f458 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/radix-zero.js @@ -0,0 +1,56 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Radix is zero +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + [...] + 6. Let R be ? ToInt32(radix). + [...] + 9. Else R = 0, + a. Let R be 10. +features: [BigInt] +---*/ + +assert.sameValue(BigInt.parseInt("0", 0), 0n); + +assert.sameValue(BigInt.parseInt("1", 0), 1n); + +assert.sameValue(BigInt.parseInt("2", 0), 2n); + +assert.sameValue(BigInt.parseInt("3", 0), 3n); + +assert.sameValue(BigInt.parseInt("4", 0), 4n); + +assert.sameValue(BigInt.parseInt("5", 0), 5n); + +assert.sameValue(BigInt.parseInt("6", 0), 6n); + +assert.sameValue(BigInt.parseInt("7", 0), 7n); + +assert.sameValue(BigInt.parseInt("8", 0), 8n); + +assert.sameValue(BigInt.parseInt("9", 0), 9n); + +assert.sameValue(BigInt.parseInt("10", 0), 10n); + +assert.sameValue(BigInt.parseInt("11", 0), 11n); + +assert.sameValue(BigInt.parseInt("9999", 0), 9999n); diff --git a/test/built-ins/BigInt/parseInt/trailing-code-point.js b/test/built-ins/BigInt/parseInt/trailing-code-point.js new file mode 100644 index 0000000000..cf3039426a --- /dev/null +++ b/test/built-ins/BigInt/parseInt/trailing-code-point.js @@ -0,0 +1,85 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Trailing non-digit UTF-16 code point +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. + + [...] + + NOTE: parseInt may interpret only a leading portion of string as an + integer value; it ignores any code units that cannot be interpreted as + part of the notation of an integer, and no indication is given that + any such code units were ignored. +includes: [decimalToHexString.js] +features: [BigInt] +---*/ + +var errorCount = 0; +var count = 0; +var indexP; +var indexO = 0; +for (var index = 0; index <= 65535; index++) { + if ((index < 0x0030) || (index > 0x0039) && + (index < 0x0041) || (index > 0x005A) && + (index < 0x0061) || (index > 0x007A)) { + var hex = decimalToHexString(index); + if (BigInt.parseInt("1Z" + String.fromCharCode(index), 36) !== 71n) { + if (indexO === 0) { + indexO = index; + } else { + if ((index - indexP) !== 1) { + if ((indexP - indexO) !== 0) { + var hexP = decimalToHexString(indexP); + var hexO = decimalToHexString(indexO); + $ERROR('#' + hexO + '-' + hexP + ' '); + } + else { + var hexP = decimalToHexString(indexP); + $ERROR('#' + hexP + ' '); + } + indexO = index; + } + } + indexP = index; + errorCount++; + } + count++; + } +} + +if (errorCount > 0) { + if ((indexP - indexO) !== 0) { + var hexP = decimalToHexString(indexP); + var hexO = decimalToHexString(indexO); + $ERROR('#' + hexO + '-' + hexP + ' '); + } else { + var hexP = decimalToHexString(indexP); + $ERROR('#' + hexP + ' '); + } + $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' '); +} diff --git a/test/built-ins/BigInt/parseInt/trailing-invalid-digit-lc.js b/test/built-ins/BigInt/parseInt/trailing-invalid-digit-lc.js new file mode 100644 index 0000000000..d6b1c609a0 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/trailing-invalid-digit-lc.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Single digit and invalid trailing digit (lowercase) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. + + [...] + + NOTE: parseInt may interpret only a leading portion of string as an + integer value; it ignores any code units that cannot be interpreted as + part of the notation of an integer, and no indication is given that + any such code units were ignored. +features: [BigInt] +---*/ + +var R_digit = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; +for (var i = 2; i <= 35; i++) { + assert.sameValue(BigInt.parseInt(R_digit[i - 2] + R_digit[i - 1], i), BigInt(i - 1)); +} diff --git a/test/built-ins/BigInt/parseInt/trailing-invalid-digit-uc.js b/test/built-ins/BigInt/parseInt/trailing-invalid-digit-uc.js new file mode 100644 index 0000000000..587aa6d38c --- /dev/null +++ b/test/built-ins/BigInt/parseInt/trailing-invalid-digit-uc.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Single digit with trailing invalid digit (uppercase) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. + + [...] + + NOTE: parseInt may interpret only a leading portion of string as an + integer value; it ignores any code units that cannot be interpreted as + part of the notation of an integer, and no indication is given that + any such code units were ignored. +features: [BigInt] +---*/ + +var R_digit = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; +for (var i = 2; i <= 35; i++) { + assert.sameValue(BigInt.parseInt(R_digit[i - 2] + R_digit[i - 1], i), BigInt(i - 1)); +} diff --git a/test/built-ins/BigInt/parseInt/trailing-non-digit-and-digit.js b/test/built-ins/BigInt/parseInt/trailing-non-digit-and-digit.js new file mode 100644 index 0000000000..5b6f2c1606 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/trailing-non-digit-and-digit.js @@ -0,0 +1,43 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: 10 with trailing non-digit +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. + + [...] + + NOTE: parseInt may interpret only a leading portion of string as an + integer value; it ignores any code units that cannot be interpreted as + part of the notation of an integer, and no indication is given that + any such code units were ignored. +features: [BigInt] +---*/ + +for (var i = 2; i <= 36; i++) { + assert.sameValue(BigInt.parseInt("10$1", i), BigInt(i)); +} diff --git a/test/built-ins/BigInt/parseInt/trailing-non-digit-lc.js b/test/built-ins/BigInt/parseInt/trailing-non-digit-lc.js new file mode 100644 index 0000000000..d4e9a95e92 --- /dev/null +++ b/test/built-ins/BigInt/parseInt/trailing-non-digit-lc.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Single digit with trailing non-digit (lowercase) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. + + [...] + + NOTE: parseInt may interpret only a leading portion of string as an + integer value; it ignores any code units that cannot be interpreted as + part of the notation of an integer, and no indication is given that + any such code units were ignored. +features: [BigInt] +---*/ + +var R_digit = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; +for (var i = 2; i <= 36; i++) { + assert.sameValue(BigInt.parseInt(R_digit[i - 2] + "$", i), BigInt(i - 1)); +} diff --git a/test/built-ins/BigInt/parseInt/trailing-non-digit-uc.js b/test/built-ins/BigInt/parseInt/trailing-non-digit-uc.js new file mode 100644 index 0000000000..456b7bc3bb --- /dev/null +++ b/test/built-ins/BigInt/parseInt/trailing-non-digit-uc.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint-parseint-string-radix +description: Single digit with trailing non-digit (uppercase) +info: > + BigInt.parseInt ( string, radix ) + + The parseInt function produces a BigInt value dictated by + interpretation of the contents of the string argument according to + the specified radix. + + The algorithm is the same as 18.2.5 but with the following edits: + + * For all cases which result in returning NaN, throw a SyntaxError + exception. + * For all cases which result in returning -0, return 0n. + * Replace the second to last step, which casts mathInt to a Number, + with casting mathInt to a BigInt. + + 18.2.5 parseInt ( string, radix ) + + The parseInt function produces an integer value dictated by + interpretation of the contents of the string argument according to the + specified radix. Leading white space in string is ignored. If radix is + undefined or 0, it is assumed to be 10 except when the number begins + with the code unit pairs 0x or 0X, in which case a radix of 16 is + assumed. If radix is 16, the number may also optionally begin with the + code unit pairs 0x or 0X. + + [...] + + NOTE: parseInt may interpret only a leading portion of string as an + integer value; it ignores any code units that cannot be interpreted as + part of the notation of an integer, and no indication is given that + any such code units were ignored. +features: [BigInt] +---*/ + +var R_digit = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; +for (var i = 2; i <= 36; i++) { + assert.sameValue(BigInt.parseInt(R_digit[i - 2] + "$", i), BigInt(i - 1)); +}