mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 20:44:43 +02:00
Merge pull request #1272 from leobalter/cxielarko-bigint-tostring
Updated tests for BigInt.prototype.toString
This commit is contained in:
commit
56e02611d4
20
test/built-ins/BigInt/prototype/toString/length.js
vendored
Normal file
20
test/built-ins/BigInt/prototype/toString/length.js
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-bigint.prototype.tostring
|
||||||
|
description: BigInt.prototype.toString.length property descriptor
|
||||||
|
info: >
|
||||||
|
BigInt.prototype.toString ( [ radix ] )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [BigInt]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(BigInt.prototype.toString, "length", {
|
||||||
|
value: 1,
|
||||||
|
writable: false,
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
20
test/built-ins/BigInt/prototype/toString/name.js
vendored
Normal file
20
test/built-ins/BigInt/prototype/toString/name.js
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) 2017 Robin Templeton. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-bigint.prototype.tostring
|
||||||
|
description: BigInt.prototype.toString.name property descriptor
|
||||||
|
info: >
|
||||||
|
BigInt.prototype.toString ( [ radix ] )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [BigInt]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(BigInt.prototype.toString, "name", {
|
||||||
|
value: "toString",
|
||||||
|
writable: false,
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
19
test/built-ins/BigInt/prototype/toString/prop-desc.js
vendored
Normal file
19
test/built-ins/BigInt/prototype/toString/prop-desc.js
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2016 Robin Templeton. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-bigint.prototype.tostring
|
||||||
|
description: BigInt.prototype.toString property descriptor
|
||||||
|
info: >
|
||||||
|
BigInt.prototype.toString ( [ radix ] )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [BigInt]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(BigInt.prototype, "toString", {
|
||||||
|
writable: true,
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
21
test/built-ins/BigInt/prototype/toString/prototype-call.js
vendored
Normal file
21
test/built-ins/BigInt/prototype/toString/prototype-call.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2017 Robin Templeton. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-bigint.prototype.tostring
|
||||||
|
description: Direct toString on BigInt prototype
|
||||||
|
info: >
|
||||||
|
BigInt.prototype.toString ( [ radix ] )
|
||||||
|
|
||||||
|
Let x be ? thisBigIntValue(this value).
|
||||||
|
|
||||||
|
Properties of the BigInt Prototype Object
|
||||||
|
|
||||||
|
The BigInt prototype is not a BigInt object; it does not have a
|
||||||
|
[[BigIntData]] internal slot.
|
||||||
|
features: [BigInt]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
BigInt.prototype.toString(1);
|
||||||
|
});
|
24
test/built-ins/BigInt/prototype/toString/radix-2-to-36.js
vendored
Normal file
24
test/built-ins/BigInt/prototype/toString/radix-2-to-36.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2017 Robin Templeton. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-bigint.prototype.tostring
|
||||||
|
description: toString with radix between 2 and 36
|
||||||
|
info: >
|
||||||
|
BigInt.prototype.toString ( [ radix ] )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
6. If radixNumber = 10, return ! ToString(x).
|
||||||
|
7. Return the String representation of this Number value using the
|
||||||
|
radix specified by radixNumber. Letters a-z are used for digits
|
||||||
|
with values 10 through 35. The precise algorithm is
|
||||||
|
implementation-dependent, however the algorithm should be a
|
||||||
|
generalization of that specified in 3.1.4.1.
|
||||||
|
features: [BigInt]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
for (let r = 2; r <= 36; r++) {
|
||||||
|
assert.sameValue((0n).toString(r), "0", "0, radix " + r);
|
||||||
|
assert.sameValue((-1n).toString(r), "-1", "-1, radix " + r);
|
||||||
|
assert.sameValue((1n).toString(r), "1", "1, radix " + r);
|
||||||
|
}
|
27
test/built-ins/BigInt/prototype/toString/radix-err.js
vendored
Normal file
27
test/built-ins/BigInt/prototype/toString/radix-err.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2017 Robin Templeton. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-bigint.prototype.tostring
|
||||||
|
description: toString with invalid radix
|
||||||
|
info: >
|
||||||
|
BigInt.prototype.toString ( [ radix ] )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
4. Else, let radixNumber be ? ToInteger(radix).
|
||||||
|
5. If radixNumber < 2 or radixNumber > 36, throw a RangeError
|
||||||
|
exception.
|
||||||
|
features: [BigInt]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
for (let r of [0, 1, 37, null]) {
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
(0n).toString(r);
|
||||||
|
}, "0, radix " + r);
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
(-1n).toString(r);
|
||||||
|
}, "-1, radix " + r);
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
(1n).toString(r);
|
||||||
|
}, "1, radix " + r);
|
||||||
|
}
|
67
test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js
vendored
Normal file
67
test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js
vendored
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright 2017 Leo Balter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-bigint.prototype.tostring
|
||||||
|
description: Throws a TypeError if the this value is not a BigInt
|
||||||
|
info: >
|
||||||
|
BigInt.prototype.toString ( [ radix ] )
|
||||||
|
|
||||||
|
1. Let x be ? thisBigIntValue(this value).
|
||||||
|
...
|
||||||
|
|
||||||
|
The abstract operation thisBigIntValue(value) performs the following steps:
|
||||||
|
|
||||||
|
1. If Type(value) is BigInt, return value.
|
||||||
|
2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then
|
||||||
|
...
|
||||||
|
3. Throw a TypeError exception.
|
||||||
|
features: [BigInt, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toString = BigInt.prototype.toString;
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call({x: 1n});
|
||||||
|
}, '{x: 1n}');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call([1n]);
|
||||||
|
}, '[1n]');
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
valueOf: function() { throw new Test262Error('no [[BigIntData]]') },
|
||||||
|
toString: function() { throw new Test262Error('no [[BigIntData]]') },
|
||||||
|
[Symbol.toPrimitive]: function() { throw new Test262Error('no [[BigIntData]]') }
|
||||||
|
};
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call(obj);
|
||||||
|
}, '{valueOf, toString, toPrimitive}');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call(0);
|
||||||
|
}, '0');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call(1);
|
||||||
|
}, '1');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call(NaN);
|
||||||
|
}, 'NaN');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call(undefined);
|
||||||
|
}, 'undefined');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call(null);
|
||||||
|
}, 'null');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call(true);
|
||||||
|
}, 'true');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toString.call(false);
|
||||||
|
}, 'false');
|
Loading…
x
Reference in New Issue
Block a user