bigint.js
 1  'use strict';
 2  
 3  var inspect = require('../');
 4  var test = require('tape');
 5  var hasToStringTag = require('has-tostringtag/shams')();
 6  
 7  test('bigint', { skip: typeof BigInt === 'undefined' }, function (t) {
 8      t.test('primitives', function (st) {
 9          st.plan(3);
10  
11          st.equal(inspect(BigInt(-256)), '-256n');
12          st.equal(inspect(BigInt(0)), '0n');
13          st.equal(inspect(BigInt(256)), '256n');
14      });
15  
16      t.test('objects', function (st) {
17          st.plan(3);
18  
19          st.equal(inspect(Object(BigInt(-256))), 'Object(-256n)');
20          st.equal(inspect(Object(BigInt(0))), 'Object(0n)');
21          st.equal(inspect(Object(BigInt(256))), 'Object(256n)');
22      });
23  
24      t.test('syntactic primitives', function (st) {
25          st.plan(3);
26  
27          /* eslint-disable no-new-func */
28          st.equal(inspect(Function('return -256n')()), '-256n');
29          st.equal(inspect(Function('return 0n')()), '0n');
30          st.equal(inspect(Function('return 256n')()), '256n');
31      });
32  
33      t.test('toStringTag', { skip: !hasToStringTag }, function (st) {
34          st.plan(1);
35  
36          var faker = {};
37          faker[Symbol.toStringTag] = 'BigInt';
38          st.equal(
39              inspect(faker),
40              '{ [Symbol(Symbol.toStringTag)]: \'BigInt\' }',
41              'object lying about being a BigInt inspects as an object'
42          );
43      });
44  
45      t.test('numericSeparator', function (st) {
46          st.equal(inspect(BigInt(0), { numericSeparator: false }), '0n', '0n, numericSeparator false');
47          st.equal(inspect(BigInt(0), { numericSeparator: true }), '0n', '0n, numericSeparator true');
48  
49          st.equal(inspect(BigInt(1234), { numericSeparator: false }), '1234n', '1234n, numericSeparator false');
50          st.equal(inspect(BigInt(1234), { numericSeparator: true }), '1_234n', '1234n, numericSeparator true');
51          st.equal(inspect(BigInt(-1234), { numericSeparator: false }), '-1234n', '1234n, numericSeparator false');
52          st.equal(inspect(BigInt(-1234), { numericSeparator: true }), '-1_234n', '1234n, numericSeparator true');
53  
54          st.end();
55      });
56  
57      t.end();
58  });