blob: efbc98b5ba811e9678c6bc25c6577113773a07ab [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var test = require('tape');
4var hasBigInts = require('..');
5
6test('interface', function (t) {
7 t.equal(typeof hasBigInts, 'function', 'is a function');
8 t.equal(typeof hasBigInts(), 'boolean', 'returns a boolean');
9 t.end();
10});
11
12test('BigInts are supported', { skip: !hasBigInts() }, function (t) {
13 t.equal(typeof BigInt, 'function', 'global BigInt is a function');
14 if (typeof BigInt !== 'function') {
15 return;
16 }
17
18 t.equal(BigInt(42), BigInt(42), '42n === 42n');
19 t['throws'](
20 function () { BigInt(NaN); },
21 RangeError,
22 'NaN is not an integer; BigInt(NaN) throws'
23 );
24
25 t['throws'](
26 function () { BigInt(Infinity); },
27 RangeError,
28 'Infinity is not an integer; BigInt(Infinity) throws'
29 );
30
31 t['throws'](
32 function () { BigInt(1.1); },
33 RangeError,
34 '1.1 is not an integer; BigInt(1.1) throws'
35 );
36
37 t.end();
38});
39
40test('BigInts are not supported', { skip: hasBigInts() }, function (t) {
41 t.equal(typeof BigInt, 'undefined', 'global BigInt is undefined');
42
43 t.end();
44});