blob: b3b8acad927641605f6ec883b41aee936c84008d [file] [log] [blame]
joepeck@webkit.org094223d52017-09-21 03:23:17 +00001// Copyright (C) 2017 Josh Wolfe. All rights reserved.
2// This code is governed by the BSD license found in the LICENSE file.
3/*---
joepeck@webkit.org094223d52017-09-21 03:23:17 +00004description: BigInt.asIntN type coercion for bits parameter
utatane.tea@gmail.com292d75e2018-02-02 21:48:40 +00005esid: pending
6info: |
joepeck@webkit.org094223d52017-09-21 03:23:17 +00007 BigInt.asIntN ( bits, bigint )
8
9 1. Let bits be ? ToIndex(bits).
utatane.tea@gmail.com292d75e2018-02-02 21:48:40 +000010features: [BigInt]
joepeck@webkit.org094223d52017-09-21 03:23:17 +000011---*/
12
utatane.tea@gmail.com292d75e2018-02-02 21:48:40 +000013assert.sameValue(BigInt.asIntN(0, 1n), 0n);
14assert.sameValue(BigInt.asIntN(1, 1n), -1n);
15assert.sameValue(BigInt.asIntN(-0.9, 1n), 0n, "ToIndex: truncate towards 0");
16assert.sameValue(BigInt.asIntN(0.9, 1n), 0n, "ToIndex: truncate towards 0");
17assert.sameValue(BigInt.asIntN(NaN, 1n), 0n, "ToIndex: NaN => 0");
18assert.sameValue(BigInt.asIntN(undefined, 1n), 0n, "ToIndex: undefined => NaN => 0");
19assert.sameValue(BigInt.asIntN(null, 1n), 0n, "ToIndex: null => 0");
20assert.sameValue(BigInt.asIntN(false, 1n), 0n, "ToIndex: false => 0");
21assert.sameValue(BigInt.asIntN(true, 1n), -1n, "ToIndex: true => 1");
22assert.sameValue(BigInt.asIntN("0", 1n), 0n, "ToIndex: parse Number");
23assert.sameValue(BigInt.asIntN("1", 1n), -1n, "ToIndex: parse Number");
24assert.sameValue(BigInt.asIntN("", 1n), 0n, "ToIndex: parse Number => NaN => 0");
25assert.sameValue(BigInt.asIntN("foo", 1n), 0n, "ToIndex: parse Number => NaN => 0");
26assert.sameValue(BigInt.asIntN("true", 1n), 0n, "ToIndex: parse Number => NaN => 0");
27assert.sameValue(BigInt.asIntN(3, 10n), 2n);
28assert.sameValue(BigInt.asIntN("3", 10n), 2n, "toIndex: parse Number");
29assert.sameValue(BigInt.asIntN(3.9, 10n), 2n, "toIndex: truncate towards 0");
30assert.sameValue(BigInt.asIntN("3.9", 10n), 2n, "toIndex: parse Number => truncate towards 0");
31assert.sameValue(BigInt.asIntN([0], 1n), 0n, 'ToIndex: [0].toString() => "0" => 0');
32assert.sameValue(BigInt.asIntN(["1"], 1n), -1n, 'ToIndex: ["1"].toString() => "1" => 1');
33assert.sameValue(BigInt.asIntN({}, 1n), 0n,
34 'ToIndex: ({}).toString() => "[object Object]" => NaN => 0');
35assert.sameValue(BigInt.asIntN([], 1n), 0n, 'ToIndex: [].toString() => "" => NaN => 0');