| 1 |
// Copyright (C) 2017 Josh Wolfe. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
description: BigInt.asIntN type coercion for bits parameter |
| 5 |
esid: pending |
| 6 |
info: | |
| 7 |
BigInt.asIntN ( bits, bigint ) |
| 8 |
|
| 9 |
1. Let bits be ? ToIndex(bits). |
| 10 |
features: [BigInt] |
| 11 |
---*/ |
| 12 |
|
| 13 |
assert.sameValue(BigInt.asIntN(0, 1n), 0n); |
| 14 |
assert.sameValue(BigInt.asIntN(1, 1n), -1n); |
| 15 |
assert.sameValue(BigInt.asIntN(-0.9, 1n), 0n, "ToIndex: truncate towards 0"); |
| 16 |
assert.sameValue(BigInt.asIntN(0.9, 1n), 0n, "ToIndex: truncate towards 0"); |
| 17 |
assert.sameValue(BigInt.asIntN(NaN, 1n), 0n, "ToIndex: NaN => 0"); |
| 18 |
assert.sameValue(BigInt.asIntN(undefined, 1n), 0n, "ToIndex: undefined => NaN => 0"); |
| 19 |
assert.sameValue(BigInt.asIntN(null, 1n), 0n, "ToIndex: null => 0"); |
| 20 |
assert.sameValue(BigInt.asIntN(false, 1n), 0n, "ToIndex: false => 0"); |
| 21 |
assert.sameValue(BigInt.asIntN(true, 1n), -1n, "ToIndex: true => 1"); |
| 22 |
assert.sameValue(BigInt.asIntN("0", 1n), 0n, "ToIndex: parse Number"); |
| 23 |
assert.sameValue(BigInt.asIntN("1", 1n), -1n, "ToIndex: parse Number"); |
| 24 |
assert.sameValue(BigInt.asIntN("", 1n), 0n, "ToIndex: parse Number => NaN => 0"); |
| 25 |
assert.sameValue(BigInt.asIntN("foo", 1n), 0n, "ToIndex: parse Number => NaN => 0"); |
| 26 |
assert.sameValue(BigInt.asIntN("true", 1n), 0n, "ToIndex: parse Number => NaN => 0"); |
| 27 |
assert.sameValue(BigInt.asIntN(3, 10n), 2n); |
| 28 |
assert.sameValue(BigInt.asIntN("3", 10n), 2n, "toIndex: parse Number"); |
| 29 |
assert.sameValue(BigInt.asIntN(3.9, 10n), 2n, "toIndex: truncate towards 0"); |
| 30 |
assert.sameValue(BigInt.asIntN("3.9", 10n), 2n, "toIndex: parse Number => truncate towards 0"); |
| 31 |
assert.sameValue(BigInt.asIntN([0], 1n), 0n, 'ToIndex: [0].toString() => "0" => 0'); |
| 32 |
assert.sameValue(BigInt.asIntN(["1"], 1n), -1n, 'ToIndex: ["1"].toString() => "1" => 1'); |
| 33 |
assert.sameValue(BigInt.asIntN({}, 1n), 0n, |
| 34 |
'ToIndex: ({}).toString() => "[object Object]" => NaN => 0'); |
| 35 |
assert.sameValue(BigInt.asIntN([], 1n), 0n, 'ToIndex: [].toString() => "" => NaN => 0'); |