Skip to content

Commit

Permalink
generated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Wolfe committed Nov 4, 2017
1 parent 75a3416 commit 994e716
Show file tree
Hide file tree
Showing 31 changed files with 1,014 additions and 178 deletions.
42 changes: 42 additions & 0 deletions test/built-ins/BigInt/asIntN/bigint-tobigint-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This file was procedurally generated.
/*---
description: BigInt.asIntN type coercion for bigint parameter
esid: pending
info: |
BigInt.asIntN ( bits, bigint )
2. Let bigint ? ToBigInt(bigint).
flags: [generated]
features: [BigInt, Symbol, Symbol.toPrimitive, computed-property-names]
---*/

assert.throws(TypeError, function() { BigInt.asIntN(0, undefined); }, "ToBigInt: undefined => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: function() { return undefined; }}); }, "ToBigInt: @@toPrimitive => undefined => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: function() { return undefined; }}); }, "ToBigInt: valueOf => undefined => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {toString: function() { return undefined; }}); }, "ToBigInt: toString => undefined => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, null); }, "ToBigInt: null => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: function() { return null; }}); }, "ToBigInt: @@toPrimitive => null => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: function() { return null; }}); }, "ToBigInt: valueOf => null => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {toString: function() { return null; }}); }, "ToBigInt: toString => null => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, 0); }, "ToBigInt: Number => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, Object(0)); }, "ToBigInt: unbox object with internal slot => Number => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: function() { return 0; }}); }, "ToBigInt: @@toPrimitive => Number => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: function() { return 0; }}); }, "ToBigInt: valueOf => Number => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {toString: function() { return 0; }}); }, "ToBigInt: toString => Number => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, NaN); }, "ToBigInt: Number => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, Infinity); }, "ToBigInt: Number => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, Symbol("1")); }, "ToBigInt: Symbol => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, Object(Symbol("1"))); }, "ToBigInt: unbox object with internal slot => Symbol => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: function() { return Symbol("1"); }}); }, "ToBigInt: @@toPrimitive => Symbol => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: function() { return Symbol("1"); }}); }, "ToBigInt: valueOf => Symbol => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(0, {toString: function() { return Symbol("1"); }}); }, "ToBigInt: toString => Symbol => TypeError");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, "a"); }, "ToBigInt: unparseable BigInt");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, "0b2"); }, "ToBigInt: unparseable BigInt binary");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, Object("0b2")); }, "ToBigInt: unbox object with internal slot => unparseable BigInt binary");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: function() { return "0b2"; }}); }, "ToBigInt: @@toPrimitive => unparseable BigInt binary");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, {valueOf: function() { return "0b2"; }}); }, "ToBigInt: valueOf => unparseable BigInt binary");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, {toString: function() { return "0b2"; }}); }, "ToBigInt: toString => unparseable BigInt binary");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, " 0b2 "); }, "ToBigInt: unparseable BigInt with leading/trailing whitespace");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, "0o8"); }, "ToBigInt: unparseable BigInt octal");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, "0xg"); }, "ToBigInt: unparseable BigInt hex");
assert.throws(SyntaxError, function() { BigInt.asIntN(0, "1n"); }, "ToBigInt: unparseable BigInt due to literal suffix");
39 changes: 39 additions & 0 deletions test/built-ins/BigInt/asIntN/bigint-tobigint-toprimitive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file was procedurally generated.
/*---
description: BigInt.asIntN type coercion for bigint parameter
esid: pending
info: |
BigInt.asIntN ( bits, bigint )
2. Let bigint ? ToBigInt(bigint).
flags: [generated]
features: [BigInt, Symbol.toPrimitive, computed-property-names]
---*/

function err() {
throw new Test262Error();
}
function MyError() {}

assert.sameValue(BigInt.asIntN(2, {[Symbol.toPrimitive]: function() { return "1"; }, valueOf: err, toString: err}), 1n, "ToPrimitive: @@toPrimitive takes precedence");
assert.sameValue(BigInt.asIntN(2, {valueOf: function() { return "1"; }, toString: err}), 1n, "ToPrimitive: valueOf takes precedence over toString");
assert.sameValue(BigInt.asIntN(2, {toString: function() { return "1"; }}), 1n, "ToPrimitive: toString with no valueOf");
assert.sameValue(BigInt.asIntN(2, {[Symbol.toPrimitive]: undefined, valueOf: function() { return "1"; }}), 1n, "ToPrimitive: skip @@toPrimitive when it's undefined");
assert.sameValue(BigInt.asIntN(2, {[Symbol.toPrimitive]: null, valueOf: function() { return "1"; }}), 1n, "ToPrimitive: skip @@toPrimitive when it's null");
assert.sameValue(BigInt.asIntN(2, {valueOf: null, toString: function() { return "1"; }}), 1n, "ToPrimitive: skip valueOf when it's not callable");
assert.sameValue(BigInt.asIntN(2, {valueOf: 1, toString: function() { return "1"; }}), 1n, "ToPrimitive: skip valueOf when it's not callable");
assert.sameValue(BigInt.asIntN(2, {valueOf: {}, toString: function() { return "1"; }}), 1n, "ToPrimitive: skip valueOf when it's not callable");
assert.sameValue(BigInt.asIntN(2, {valueOf: function() { return {}; }, toString: function() { return "1"; }}), 1n, "ToPrimitive: skip valueOf when it returns an object");
assert.sameValue(BigInt.asIntN(2, {valueOf: function() { return Object(12345); }, toString: function() { return "1"; }}), 1n, "ToPrimitive: skip valueOf when it returns an object");
assert.throws(TypeError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: 1}); }, "ToPrimitive: throw when @@toPrimitive is not callable");
assert.throws(TypeError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: {}}); }, "ToPrimitive: throw when @@toPrimitive is not callable");
assert.throws(TypeError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: function() { return Object(1); }}); }, "ToPrimitive: throw when @@toPrimitive returns an object");
assert.throws(TypeError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: function() { return {}; }}); }, "ToPrimitive: throw when @@toPrimitive returns an object");
assert.throws(MyError, function() { BigInt.asIntN(0, {[Symbol.toPrimitive]: function() { throw new MyError(); }}); }, "ToPrimitive: propagate errors from @@toPrimitive");
assert.throws(MyError, function() { BigInt.asIntN(0, {valueOf: function() { throw new MyError(); }}); }, "ToPrimitive: propagate errors from valueOf");
assert.throws(MyError, function() { BigInt.asIntN(0, {toString: function() { throw new MyError(); }}); }, "ToPrimitive: propagate errors from toString");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: null, toString: null}); }, "ToPrimitive: throw when skipping both valueOf and toString");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: 1, toString: 1}); }, "ToPrimitive: throw when skipping both valueOf and toString");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: {}, toString: {}}); }, "ToPrimitive: throw when skipping both valueOf and toString");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: function() { return Object(1); }, toString: function() { return Object(1); }}); }, "ToPrimitive: throw when skipping both valueOf and toString");
assert.throws(TypeError, function() { BigInt.asIntN(0, {valueOf: function() { return {}; }, toString: function() { return {}; }}); }, "ToPrimitive: throw when skipping both valueOf and toString");
24 changes: 24 additions & 0 deletions test/built-ins/BigInt/asIntN/bigint-tobigint-wrapped-values.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file was procedurally generated.
/*---
description: BigInt.asIntN type coercion for bigint parameter
esid: pending
info: |
BigInt.asIntN ( bits, bigint )
2. Let bigint ? ToBigInt(bigint).
flags: [generated]
features: [BigInt, Symbol.toPrimitive, computed-property-names]
---*/

assert.sameValue(BigInt.asIntN(2, Object(0n)), 0n, "ToPrimitive: unbox object with internal slot");
assert.sameValue(BigInt.asIntN(2, {[Symbol.toPrimitive]: function() { return 0n; }}), 0n, "ToPrimitive: @@toPrimitive");
assert.sameValue(BigInt.asIntN(2, {valueOf: function() { return 0n; }}), 0n, "ToPrimitive: valueOf");
assert.sameValue(BigInt.asIntN(2, {toString: function() { return 0n; }}), 0n, "ToPrimitive: toString");
assert.sameValue(BigInt.asIntN(2, Object(true)), 1n, "ToBigInt: unbox object with internal slot => true => 1n");
assert.sameValue(BigInt.asIntN(2, {[Symbol.toPrimitive]: function() { return true; }}), 1n, "ToBigInt: @@toPrimitive => true => 1n");
assert.sameValue(BigInt.asIntN(2, {valueOf: function() { return true; }}), 1n, "ToBigInt: valueOf => true => 1n");
assert.sameValue(BigInt.asIntN(2, {toString: function() { return true; }}), 1n, "ToBigInt: toString => true => 1n");
assert.sameValue(BigInt.asIntN(2, Object("1")), 1n, "ToBigInt: unbox object with internal slot => parse BigInt");
assert.sameValue(BigInt.asIntN(2, {[Symbol.toPrimitive]: function() { return "1"; }}), 1n, "ToBigInt: @@toPrimitive => parse BigInt");
assert.sameValue(BigInt.asIntN(2, {valueOf: function() { return "1"; }}), 1n, "ToBigInt: valueOf => parse BigInt");
assert.sameValue(BigInt.asIntN(2, {toString: function() { return "1"; }}), 1n, "ToBigInt: toString => parse BigInt");
59 changes: 33 additions & 26 deletions test/built-ins/BigInt/asIntN/bigint-tobigint.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
// This file was procedurally generated.
/*---
esid: pending
description: BigInt.asIntN type coercion for bigint parameter
info: >
esid: pending
info: |
BigInt.asIntN ( bits, bigint )
2. Let bigint ? ToBigInt(bigint).
features: [BigInt, Symbol, Symbol.toPrimitive]
includes: [typeCoercion.js]
flags: [generated]
features: [BigInt]
---*/

testCoercibleToBigIntZero(function(zero) {
assert.sameValue(BigInt.asIntN(2, zero), 0n);
});

testCoercibleToBigIntOne(function(one) {
assert.sameValue(BigInt.asIntN(2, one), 1n);
});

testCoercibleToBigIntFromBigInt(10n, function(ten) {
assert.sameValue(BigInt.asIntN(3, ten), 2n);
});

testCoercibleToBigIntFromBigInt(12345678901234567890003n, function(value) {
assert.sameValue(BigInt.asIntN(4, value), 3n);
});

testNotCoercibleToBigInt(function(error, value) {
assert.throws(error, function() { BigInt.asIntN(0, value); });
});
assert.sameValue(BigInt.asIntN(2, 0n), 0n);
assert.sameValue(BigInt.asIntN(2, -0n), 0n);
assert.sameValue(BigInt.asIntN(2, false), 0n, "ToBigInt: false => 0n");
assert.sameValue(BigInt.asIntN(2, true), 1n, "ToBigInt: true => 1n");
assert.sameValue(BigInt.asIntN(2, "1"), 1n, "ToBigInt: parse BigInt");
assert.sameValue(BigInt.asIntN(2, "-0"), 0n, "ToBigInt: parse BigInt");
assert.sameValue(BigInt.asIntN(2, ""), 0n, "ToBigInt: empty String => 0n");
assert.sameValue(BigInt.asIntN(2, " "), 0n, "ToBigInt: String with only whitespace => 0n");
assert.sameValue(BigInt.asIntN(2, []), 0n, "ToBigInt: .toString() => empty String => 0n");
assert.sameValue(BigInt.asIntN(2, [1]), 1n, "ToBigInt: .toString() => parse BigInt");
assert.sameValue(BigInt.asIntN(3, 10n), 2n);
assert.sameValue(BigInt.asIntN(3, "10"), 2n, "ToBigInt: parse BigInt");
assert.sameValue(BigInt.asIntN(3, "0b1010"), 2n, "ToBigInt: parse BigInt binary");
assert.sameValue(BigInt.asIntN(3, "0o12"), 2n, "ToBigInt: parse BigInt octal");
assert.sameValue(BigInt.asIntN(3, "0xa"), 2n, "ToBigInt: parse BigInt hex");
assert.sameValue(BigInt.asIntN(3, " 0xa "), 2n, "ToBigInt: parse BigInt ignore leading/trailing whitespace");
assert.sameValue(BigInt.asIntN(3, " 10 "), 2n, "ToBigInt: parse BigInt ignore leading/trailing whitespace");
assert.sameValue(BigInt.asIntN(3, [10n]), 2n, "ToBigInt: .toString() => parse BigInt");
assert.sameValue(BigInt.asIntN(3, ["10"]), 2n, "ToBigInt: .toString() => parse BigInt");
assert.sameValue(BigInt.asIntN(4, 12345678901234567890003n), 3n);
assert.sameValue(BigInt.asIntN(4, "12345678901234567890003"), 3n, "ToBigInt: parse BigInt");
assert.sameValue(BigInt.asIntN(4, "0b10100111010100001010110110010011100111011001110001010000100100010001010011"), 3n, "ToBigInt: parse BigInt binary");
assert.sameValue(BigInt.asIntN(4, "0o2472412662347316120442123"), 3n, "ToBigInt: parse BigInt octal");
assert.sameValue(BigInt.asIntN(4, "0x29d42b64e7671424453"), 3n, "ToBigInt: parse BigInt hex");
assert.sameValue(BigInt.asIntN(4, " 0x29d42b64e7671424453 "), 3n, "ToBigInt: parse BigInt ignore leading/trailing whitespace");
assert.sameValue(BigInt.asIntN(4, " 12345678901234567890003 "), 3n, "ToBigInt: parse BigInt ignore leading/trailing whitespace");
assert.sameValue(BigInt.asIntN(4, [12345678901234567890003n]), 3n, "ToBigInt: .toString() => parse BigInt");
assert.sameValue(BigInt.asIntN(4, ["12345678901234567890003"]), 3n, "ToBigInt: .toString() => parse BigInt");
28 changes: 28 additions & 0 deletions test/built-ins/BigInt/asIntN/bits-toindex-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file was procedurally generated.
/*---
description: BigInt.asIntN type coercion for bits parameter
esid: pending
info: |
BigInt.asIntN ( bits, bigint )
1. Let bits be ? ToIndex(bits).
flags: [generated]
features: [BigInt, Symbol, Symbol.toPrimitive, computed-property-names]
---*/

assert.throws(RangeError, function() { BigInt.asIntN(-1, 0n); }, "ToIndex: throw when integerIndex < 0");
assert.throws(RangeError, function() { BigInt.asIntN(-2.5, 0n); }, "ToIndex: throw when integerIndex < 0");
assert.throws(RangeError, function() { BigInt.asIntN("-2.5", 0n); }, "ToIndex: parse Number => throw when integerIndex < 0");
assert.throws(RangeError, function() { BigInt.asIntN(-Infinity, 0n); }, "ToIndex: throw when integerIndex < 0");
assert.throws(RangeError, function() { BigInt.asIntN(9007199254740992, 0n); }, "ToIndex: throw when integerIndex > 2**53-1");
assert.throws(RangeError, function() { BigInt.asIntN(Infinity, 0n); }, "ToIndex: throw when integerIndex > 2**53-1");
assert.throws(TypeError, function() { BigInt.asIntN(0n, 0n); }, "ToIndex: BigInt => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(Object(0n), 0n); }, "ToIndex: unbox object with internal slot => BigInt => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN({[Symbol.toPrimitive]: function() { return 0n; }}, 0n); }, "ToIndex: @@toPrimitive => BigInt => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN({valueOf: function() { return 0n; }}, 0n); }, "ToIndex: valueOf => BigInt => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN({toString: function() { return 0n; }}, 0n); }, "ToIndex: toString => BigInt => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(Symbol("1"), 0n); }, "ToIndex: Symbol => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN(Object(Symbol("1")), 0n); }, "ToIndex: unbox object with internal slot => Symbol => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN({[Symbol.toPrimitive]: function() { return Symbol("1"); }}, 0n); }, "ToIndex: @@toPrimitive => Symbol => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN({valueOf: function() { return Symbol("1"); }}, 0n); }, "ToIndex: valueOf => Symbol => TypeError");
assert.throws(TypeError, function() { BigInt.asIntN({toString: function() { return Symbol("1"); }}, 0n); }, "ToIndex: toString => Symbol => TypeError");
39 changes: 39 additions & 0 deletions test/built-ins/BigInt/asIntN/bits-toindex-toprimitive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file was procedurally generated.
/*---
description: BigInt.asIntN type coercion for bits parameter
esid: pending
info: |
BigInt.asIntN ( bits, bigint )
1. Let bits be ? ToIndex(bits).
flags: [generated]
features: [BigInt, Symbol.toPrimitive, computed-property-names]
---*/

function err() {
throw new Test262Error();
}
function MyError() {}

assert.sameValue(BigInt.asIntN({[Symbol.toPrimitive]: function() { return 1; }, valueOf: err, toString: err}, 1n), -1n, "ToPrimitive: @@toPrimitive takes precedence");
assert.sameValue(BigInt.asIntN({valueOf: function() { return 1; }, toString: err}, 1n), -1n, "ToPrimitive: valueOf takes precedence over toString");
assert.sameValue(BigInt.asIntN({toString: function() { return 1; }}, 1n), -1n, "ToPrimitive: toString with no valueOf");
assert.sameValue(BigInt.asIntN({[Symbol.toPrimitive]: undefined, valueOf: function() { return 1; }}, 1n), -1n, "ToPrimitive: skip @@toPrimitive when it's undefined");
assert.sameValue(BigInt.asIntN({[Symbol.toPrimitive]: null, valueOf: function() { return 1; }}, 1n), -1n, "ToPrimitive: skip @@toPrimitive when it's null");
assert.sameValue(BigInt.asIntN({valueOf: null, toString: function() { return 1; }}, 1n), -1n, "ToPrimitive: skip valueOf when it's not callable");
assert.sameValue(BigInt.asIntN({valueOf: 1, toString: function() { return 1; }}, 1n), -1n, "ToPrimitive: skip valueOf when it's not callable");
assert.sameValue(BigInt.asIntN({valueOf: {}, toString: function() { return 1; }}, 1n), -1n, "ToPrimitive: skip valueOf when it's not callable");
assert.sameValue(BigInt.asIntN({valueOf: function() { return {}; }, toString: function() { return 1; }}, 1n), -1n, "ToPrimitive: skip valueOf when it returns an object");
assert.sameValue(BigInt.asIntN({valueOf: function() { return Object(12345); }, toString: function() { return 1; }}, 1n), -1n, "ToPrimitive: skip valueOf when it returns an object");
assert.throws(TypeError, function() { BigInt.asIntN({[Symbol.toPrimitive]: 1}, 0n); }, "ToPrimitive: throw when @@toPrimitive is not callable");
assert.throws(TypeError, function() { BigInt.asIntN({[Symbol.toPrimitive]: {}}, 0n); }, "ToPrimitive: throw when @@toPrimitive is not callable");
assert.throws(TypeError, function() { BigInt.asIntN({[Symbol.toPrimitive]: function() { return Object(1); }}, 0n); }, "ToPrimitive: throw when @@toPrimitive returns an object");
assert.throws(TypeError, function() { BigInt.asIntN({[Symbol.toPrimitive]: function() { return {}; }}, 0n); }, "ToPrimitive: throw when @@toPrimitive returns an object");
assert.throws(MyError, function() { BigInt.asIntN({[Symbol.toPrimitive]: function() { throw new MyError(); }}, 0n); }, "ToPrimitive: propagate errors from @@toPrimitive");
assert.throws(MyError, function() { BigInt.asIntN({valueOf: function() { throw new MyError(); }}, 0n); }, "ToPrimitive: propagate errors from valueOf");
assert.throws(MyError, function() { BigInt.asIntN({toString: function() { throw new MyError(); }}, 0n); }, "ToPrimitive: propagate errors from toString");
assert.throws(TypeError, function() { BigInt.asIntN({valueOf: null, toString: null}, 0n); }, "ToPrimitive: throw when skipping both valueOf and toString");
assert.throws(TypeError, function() { BigInt.asIntN({valueOf: 1, toString: 1}, 0n); }, "ToPrimitive: throw when skipping both valueOf and toString");
assert.throws(TypeError, function() { BigInt.asIntN({valueOf: {}, toString: {}}, 0n); }, "ToPrimitive: throw when skipping both valueOf and toString");
assert.throws(TypeError, function() { BigInt.asIntN({valueOf: function() { return Object(1); }, toString: function() { return Object(1); }}, 0n); }, "ToPrimitive: throw when skipping both valueOf and toString");
assert.throws(TypeError, function() { BigInt.asIntN({valueOf: function() { return {}; }, toString: function() { return {}; }}, 0n); }, "ToPrimitive: throw when skipping both valueOf and toString");
Loading

0 comments on commit 994e716

Please sign in to comment.