Skip to content

Commit

Permalink
Refactor tests for the BigInt construtor
Browse files Browse the repository at this point in the history
  • Loading branch information
leobalter committed Aug 25, 2017
1 parent 37beb36 commit 7765873
Show file tree
Hide file tree
Showing 45 changed files with 724 additions and 295 deletions.
10 changes: 0 additions & 10 deletions test/built-ins/BigInt/asIntN.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/built-ins/BigInt/asUintN.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/built-ins/BigInt/constructor-prototype.js

This file was deleted.

16 changes: 0 additions & 16 deletions test/built-ins/BigInt/constructor.js

This file was deleted.

42 changes: 42 additions & 0 deletions test/built-ins/BigInt/infinity-throws-rangeerror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt throws a RangeError if value is Infinity
esid: sec-bigint-constructor
info: |
BigInt ( value )
...
2. Let prim be ? ToPrimitive(value, hint Number).
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
...
NumberToBigInt ( number )
...
2. If IsSafeInteger(number) is false, throw a RangeError exception.
...
IsSafeInteger ( number )
...
2. If number is NaN, +∞, or -∞, return false.
features: [BigInt]
---*/

assert.throws(RangeError, function() {
BigInt(Infinity);
});

var calls = 0;
var obj = {
valueOf: function() {
calls++;
return Infinity;
}
}
assert.throws(RangeError, function() {
BigInt(obj);
});
assert.sameValue(calls, 1, "it fails after fetching the primitive value");
42 changes: 42 additions & 0 deletions test/built-ins/BigInt/nan-throws-rangeerror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt throws a RangeError if value is NaN
esid: sec-bigint-constructor
info: |
BigInt ( value )
...
2. Let prim be ? ToPrimitive(value, hint Number).
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
...
NumberToBigInt ( number )
...
2. If IsSafeInteger(number) is false, throw a RangeError exception.
...
IsSafeInteger ( number )
...
2. If number is NaN, +∞, or -∞, return false.
features: [BigInt]
---*/

assert.throws(RangeError, function() {
BigInt(NaN);
});

var calls = 0;
var obj = {
valueOf: function() {
calls++;
return NaN;
}
}
assert.throws(RangeError, function() {
BigInt(obj);
});
assert.sameValue(calls, 1, "it fails after fetching the primitive value");
42 changes: 42 additions & 0 deletions test/built-ins/BigInt/negative-infinity-throws.rangeerror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2017 The V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt throws a RangeError if value is Infinity
esid: sec-bigint-constructor
info: |
BigInt ( value )
...
2. Let prim be ? ToPrimitive(value, hint Number).
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
...
NumberToBigInt ( number )
...
2. If IsSafeInteger(number) is false, throw a RangeError exception.
...
IsSafeInteger ( number )
...
2. If number is NaN, +∞, or -∞, return false.
features: [BigInt]
---*/

assert.throws(RangeError, function() {
BigInt(-Infinity);
});

var calls = 0;
var obj = {
valueOf: function() {
calls++;
return -Infinity;
}
}
assert.throws(RangeError, function() {
BigInt(obj);
});
assert.sameValue(calls, 1, "it fails after fetching the primitive value");
33 changes: 33 additions & 0 deletions test/built-ins/BigInt/new-target-throws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Throws a TypeError if BigInt is called with a new target
esid: sec-bigint-constructor
info: |
1. If NewTarget is not undefined, throw a TypeError exception.
2. Let prim be ? ToPrimitive(value, hint Number).
...
features: [BigInt]
---*/

assert.throws(TypeError, function() {
new BigInt();
});

assert.throws(TypeError, function() {
new BigInt(NaN);
});

assert.throws(TypeError, function() {
new BigInt({
valueOf: function() { throw new Test262Error("unreachable"); }
});
});

for (let x of [NaN, Infinity, 0.5, 2**53]) {
assert.throws(RangeError, () => BigInt(x));
assert.throws(RangeError, () => BigInt(-x));
}
assert.sameValue(BigInt(9007199254740991), 9007199254740991n);
assert.sameValue(BigInt(-9007199254740991), -9007199254740991n);
57 changes: 57 additions & 0 deletions test/built-ins/BigInt/non-integer-rangeerror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Non integer number values will throw a RangeError
esid: sec-bigint-constructor
info: |
BigInt ( value )
...
2. Let prim be ? ToPrimitive(value, hint Number).
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
...
NumberToBigInt ( number )
...
2. If IsSafeInteger(number) is false, throw a RangeError exception.
...
IsSafeInteger ( number )
...
2. If number is NaN, +∞, or -∞, return false.
3. Let integer be ToInteger(number).
4. If integer is not equal to number, return false.
...
features: [BigInt]
---*/

assert.throws(RangeError, function() {
BigInt(0.00005);
});

assert.throws(RangeError, function() {
BigInt(-0.00005);
});

assert.throws(RangeError, function() {
BigInt(.1);
});

assert.throws(RangeError, function() {
BigInt(-.1);
});

assert.throws(RangeError, function() {
BigInt(1.1);
});

assert.throws(RangeError, function() {
BigInt(-1.1);
});

assert.throws(RangeError, function() {
BigInt(Number.MIN_VALUE);
});
40 changes: 40 additions & 0 deletions test/built-ins/BigInt/out-of-bounds-integer-rangeerror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt throws a RangeError if value is not a safe integer.
esid: sec-bigint-constructor
info: |
BigInt ( value )
...
2. Let prim be ? ToPrimitive(value, hint Number).
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
...
NumberToBigInt ( number )
...
2. If IsSafeInteger(number) is false, throw a RangeError exception.
...
IsSafeInteger ( number )
...
3. Let integer be ToInteger(number).
4. If integer is not equal to number, return false.
5. If abs(integer) ≤ 2**53-1, return true.
6. Otherwise, return false.
features: [BigInt]
---*/

var pos = Math.pow(2, 53);
var neg = -pos;

assert.throws(RangeError, function() {
BigInt(pos);
});

assert.throws(RangeError, function() {
BigInt(neg);
});
File renamed without changes.
23 changes: 23 additions & 0 deletions test/built-ins/BigInt/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2017 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-bigint-constructor
description: >
Property descriptor of BigInt
info: |
The BigInt Object
ECMAScript Standard Built-in Objects:
Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
---*/

verifyProperty(this, "BigInt", {
enumerable: false,
writable: true,
configurable: true
});
15 changes: 15 additions & 0 deletions test/built-ins/BigInt/proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: The prototype of BigInt constructor is Function.prototype
esid: sec-properties-of-the-bigint-constructor
info: >
The value of the [[Prototype]] internal slot of the BigInt constructor is the
intrinsic object %FunctionPrototype%.
features: [BigInt]
---*/

var proto = Object.getPrototypeOf(BigInt);

assert.sameValue(proto, Function.prototype);
13 changes: 0 additions & 13 deletions test/built-ins/BigInt/prototype/attributes.js

This file was deleted.

18 changes: 18 additions & 0 deletions test/built-ins/BigInt/prototype/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: The property descriptor BigInt.prototype
esid: sec-bigint.prototype
info: >
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: false }.
features: [BigInt]
includes: [propertyHelper.js]
---*/

verifyProperty(BigInt, "prototype", {
writable: false,
enumerable: false,
configurable: false
});
14 changes: 14 additions & 0 deletions test/built-ins/BigInt/prototype/proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: The prototype of BigInt.prototype is Object.prototype
esid: sec-properties-of-the-bigint-prototype-object
info: >
The value of the [[Prototype]] internal slot of the BigInt prototype object
is the intrinsic object %ObjectPrototype%.
features: [BigInt]
---*/

var proto = Object.getPrototypeOf(BigInt.prototype);
assert.sameValue(proto, Object.prototype);
Loading

0 comments on commit 7765873

Please sign in to comment.