bigint.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. var inspect = require('../');
  3. var test = require('tape');
  4. var hasSymbols = require('has-symbols/shams')();
  5. test('bigint', { skip: typeof BigInt === 'undefined' }, function (t) {
  6. t.test('primitives', function (st) {
  7. st.plan(3);
  8. st.equal(inspect(BigInt(-256)), '-256n');
  9. st.equal(inspect(BigInt(0)), '0n');
  10. st.equal(inspect(BigInt(256)), '256n');
  11. });
  12. t.test('objects', function (st) {
  13. st.plan(3);
  14. st.equal(inspect(Object(BigInt(-256))), 'Object(-256n)');
  15. st.equal(inspect(Object(BigInt(0))), 'Object(0n)');
  16. st.equal(inspect(Object(BigInt(256))), 'Object(256n)');
  17. });
  18. t.test('syntactic primitives', function (st) {
  19. st.plan(3);
  20. /* eslint-disable no-new-func */
  21. st.equal(inspect(Function('return -256n')()), '-256n');
  22. st.equal(inspect(Function('return 0n')()), '0n');
  23. st.equal(inspect(Function('return 256n')()), '256n');
  24. });
  25. t.test('toStringTag', { skip: !hasSymbols || typeof Symbol.toStringTag === 'undefined' }, function (st) {
  26. st.plan(1);
  27. var faker = {};
  28. faker[Symbol.toStringTag] = 'BigInt';
  29. st.equal(
  30. inspect(faker),
  31. '{ [Symbol(Symbol.toStringTag)]: \'BigInt\' }',
  32. 'object lying about being a BigInt inspects as an object'
  33. );
  34. });
  35. t.end();
  36. });