1 | 'use strict';
|
---|
2 |
|
---|
3 | var test = require('tape');
|
---|
4 | var hasBigInts = require('..');
|
---|
5 |
|
---|
6 | test('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 |
|
---|
12 | test('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 |
|
---|
40 | test('BigInts are not supported', { skip: hasBigInts() }, function (t) {
|
---|
41 | t.equal(typeof BigInt, 'undefined', 'global BigInt is undefined');
|
---|
42 |
|
---|
43 | t.end();
|
---|
44 | });
|
---|