Skip to content

Commit

Permalink
add BigInt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Templeton authored and leobalter committed Aug 24, 2017
1 parent d9f62e4 commit 37beb36
Show file tree
Hide file tree
Showing 29 changed files with 413 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/built-ins/BigInt/asIntN.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt.asIntN
esid: pending
features: [BigInt]
---*/

assert.sameValue(BigInt.asIntN(1, 3n), -1n);
10 changes: 10 additions & 0 deletions test/built-ins/BigInt/asUintN.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt.asUintN
esid: pending
features: [BigInt]
---*/

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

/*---
description: Prototype of BigInt constructor
esid: pending
features: [BigInt]
---*/

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

/*---
description: BigInt constructor
esid: pending
features: [BigInt]
---*/

assert.throws(TypeError, () => new BigInt(0));
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);
18 changes: 18 additions & 0 deletions test/built-ins/BigInt/parseInt.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: BigInt string parsing
esid: pending
features: [BigInt]
---*/

assert.throws(SyntaxError, () => BigInt.parseInt(""));
assert.throws(SyntaxError, () => BigInt.parseInt("@"));
assert.throws(SyntaxError, () => BigInt.parseInt("1", 1));
assert.throws(SyntaxError, () => BigInt.parseInt("1", 37));
assert.sameValue(BigInt.parseInt("0xf", 0), 0xfn);
assert.sameValue(BigInt.parseInt("-0"), 0n);
assert.sameValue(BigInt.parseInt(" 0@"), 0n);
assert.sameValue(BigInt.parseInt("kf12oikf12oikf12oi", 36),
5849853453554480289462428370n);
13 changes: 13 additions & 0 deletions test/built-ins/BigInt/prototype/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt prototype object attributes
esid: pending
features: [BigInt]
includes: [propertyHelper.js]
---*/

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

/*---
description: Prototype of BigInt.prototype
esid: pending
features: [BigInt]
---*/

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

/*---
description: BigInt toString method
esid: pending
features: [BigInt]
---*/

const n = 1234567890n;
const strs = {
2: "1001001100101100000001011010010",
3: "10012001001112202200",
4: "1021211200023102",
5: "10012022133030",
6: "322301024030",
7: "42410440203",
8: "11145401322",
9: "3161045680",
10: "1234567890",
11: "583977146",
12: "2a5555016",
13: "168a0865a",
14: "b9d6b5aa",
15: "735b7d60",
16: "499602d2",
17: "30288g3a",
18: "20568ad0",
19: "174b57c7",
20: "j5g0jea",
21: "e8605e3",
22: "ajc3e26",
23: "87ifcgi",
24: "6b1230i",
25: "51ac8ff",
26: "3pnfhma",
27: "3511eki",
28: "2fkfbqa",
29: "225ep2g",
30: "1ko4m30",
31: "1c3ou0k",
32: "14pc0mi",
33: "vi0m56",
34: "r5spaa",
35: "nhokia",
36: "kf12oi"
};

assert.throws(TypeError, () => BigInt.prototype.toString.call(null));
assert.sameValue(n.toString(), n.toString(10));
assert.sameValue(n.toString(undefined), n.toString(10));
for (let radix of [1, 37, NaN, 0, Infinity]) {
assert.throws(RangeError, () => n.toString(radix));
assert.throws(RangeError, () => n.toString(-radix));
}
for (let i = 2; i < 37; i++) {
for (let x of [n, Object(n)]) {
assert.sameValue(x.toString(i), strs[i]);
assert.sameValue(x.toString(i + 0.5), strs[i]);
}
}
12 changes: 12 additions & 0 deletions test/built-ins/BigInt/prototype/valueOf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt valueOf method and thisBigIntValue operation
esid: pending
features: [BigInt]
---*/

assert.sameValue(BigInt.prototype.valueOf.call(0n), 0n);
assert.sameValue(BigInt.prototype.valueOf.call(Object(0n)), 0n);
assert.throws(TypeError, () => BigInt.prototype.valueOf.call(null));
10 changes: 10 additions & 0 deletions test/built-ins/JSON/stringify/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: JSON serialization of BigInt values
esid: pending
features: [BigInt]
---*/

assert.throws(TypeError, () => JSON.stringify(0n));
11 changes: 11 additions & 0 deletions test/built-ins/Number/bigint-conversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt to Number conversion
esid: pending
features: [BigInt]
---*/

assert.sameValue(Number(0n), 0);
assert.sameValue(+(new Number(0n)), +(new Number(0)));
11 changes: 11 additions & 0 deletions test/built-ins/Object/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Conversion of BigInt values to Objects
esid: pending
features: [BigInt]
---*/

assert(Object(0n) instanceof BigInt);
assert.sameValue(Object(0n).valueOf(), 0n);
16 changes: 16 additions & 0 deletions test/built-ins/Object/setPrototypeOf/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: RequireObjectCoercible for BigInt values
esid: pending
features: [BigInt]
---*/

try {
let {} = 0n;
} catch (e) {
$ERROR('Expected RequireObjectCoercible to succeed for BigInt values');
}

assert.sameValue(Object.setPrototypeOf(0n, null), 0n);
16 changes: 16 additions & 0 deletions test/language/expressions/addition/bigint-to-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: ToString for BigInt values
esid: pending
features: [BigInt]
---*/

const ToString = (x) => x + "";

assert.sameValue(ToString(-1n), "-1");
assert.sameValue(ToString(0n), "0");
assert.sameValue(ToString(1n), "1");
assert.sameValue(ToString(1234567890n), "1234567890");
assert.sameValue(ToString(-1234567890n), "-1234567890");
10 changes: 10 additions & 0 deletions test/language/expressions/division/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt division
esid: pending
features: [BigInt]
---*/

assert.throws(RangeError, () => 1n / 0n);
18 changes: 18 additions & 0 deletions test/language/expressions/does-not-equals/bigint.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: BigInt equality
esid: pending
features: [BigInt]
---*/

assert("x" != 0n);
assert(0n != "x");
assert(true != 0n);
assert(false != 1n);
assert(0n != true);
assert(1n != false);
assert(0n != NaN);
assert(0n != Infinity);
assert(0n != -Infinity);
19 changes: 19 additions & 0 deletions test/language/expressions/equals/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt equality
esid: pending
features: [BigInt]
---*/

assert("" == 0n);
assert("0" == 0n);
assert(0n == "");
assert(0n == "0");
assert(true == 1n);
assert(false == 0n);
assert(1n == true);
assert(0n == false);
assert(0n == 0);
assert(0 == 0n);
11 changes: 11 additions & 0 deletions test/language/expressions/exponentiation/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt exponentiation
esid: pending
features: [BigInt]
---*/

assert.throws(RangeError, () => 1n ** -1n);
assert.sameValue(0n ** 0n, 1n);
13 changes: 13 additions & 0 deletions test/language/expressions/greater-than-or-equal/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt comparison
esid: pending
features: [BigInt]
---*/

assert(1n >= 0);
assert(1 >= 0n);
assert(1n >= 1);
assert(1 >= 1n);
11 changes: 11 additions & 0 deletions test/language/expressions/greater-than/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt comparison
esid: pending
features: [BigInt]
---*/

assert(1 > 0n);
assert(1n > 0);
13 changes: 13 additions & 0 deletions test/language/expressions/less-than-or-equal/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt comparison
esid: pending
features: [BigInt]
---*/

assert(0n <= 1);
assert(0 <= 1n);
assert(1n <= 1);
assert(1 <= 1n);
11 changes: 11 additions & 0 deletions test/language/expressions/less-than/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt comparison
esid: pending
features: [BigInt]
---*/

assert(0n < 1);
assert(0 < 1n);
11 changes: 11 additions & 0 deletions test/language/expressions/logical-not/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Conversion of BigInt values to booleans
esid: pending
features: [BigInt]
---*/

assert.sameValue(!!0n, false, "Expected ToBoolean(0n) to be false");
assert.sameValue(!!1n, true, "Expected ToBoolean(1n) to be true");
10 changes: 10 additions & 0 deletions test/language/expressions/modulus/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt modulus
esid: pending
features: [BigInt]
---*/

assert.throws(RangeError, () => 1n % 0n);
10 changes: 10 additions & 0 deletions test/language/expressions/unary-plus/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Conversion of BigInt values to numbers
esid: pending
features: [BigInt]
---*/

assert.throws(TypeError, () => +0n);
13 changes: 13 additions & 0 deletions test/language/literals/bigint/binary-invalid-digit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Binary BigInt literal containing an invalid digit
esid: pending
features: [BigInt]
negative:
phase: early
type: SyntaxError
---*/

0b2n;
Loading

0 comments on commit 37beb36

Please sign in to comment.