Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/BigInt/constructor-from-binary-string.js

raw
1 // Copyright (C) 2017 Caio Lima. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: String should be parsed to BigInt according StringToBigInt
6 esid: sec-string-to-bigint
7 info: |
8 Apply the algorithm in 3.1.3.1 with the following changes:
9
10 - Replace the StrUnsignedDecimalLiteral production with DecimalDigits
11 to not allow decimal points or exponents.
12
13 features: [BigInt]
14 ---*/
15
16 assert.sameValue(BigInt("0b1111"), 15n);
17 assert.sameValue(BigInt("0b10"), 2n);
18 assert.sameValue(BigInt("0b0"), 0n);
19 assert.sameValue(BigInt("0b1"), 1n);
20
21 let binaryString = "0b1";
22 for (let i = 0; i < 128; i++)
23 binaryString += "0";
24
25 assert.sameValue(BigInt(binaryString), 340282366920938463463374607431768211456n);
26
27 assert.sameValue(BigInt("0B1111"), 15n);
28 assert.sameValue(BigInt("0B10"), 2n);
29 assert.sameValue(BigInt("0B0"), 0n);
30 assert.sameValue(BigInt("0B1"), 1n);
31
32 binaryString = "0B1";
33 for (let i = 0; i < 128; i++)
34 binaryString += "0";
35
36 assert.sameValue(BigInt(binaryString), 340282366920938463463374607431768211456n);