Skip to content

Commit

Permalink
Merge pull request #1272 from leobalter/cxielarko-bigint-tostring
Browse files Browse the repository at this point in the history
Updated tests for BigInt.prototype.toString
  • Loading branch information
rwaldron authored Oct 13, 2017
2 parents 0b5c39c + b77af3a commit 56e0261
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/built-ins/BigInt/prototype/toString/length.js
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions test/built-ins/BigInt/prototype/toString/name.js
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions test/built-ins/BigInt/prototype/toString/prop-desc.js
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions test/built-ins/BigInt/prototype/toString/prototype-call.js
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions test/built-ins/BigInt/prototype/toString/radix-2-to-36.js
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions test/built-ins/BigInt/prototype/toString/radix-err.js
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 56e0261

Please sign in to comment.