index.js 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. var test = require('tape');
  3. var hasBigInts = require('..');
  4. test('interface', function (t) {
  5. t.equal(typeof hasBigInts, 'function', 'is a function');
  6. t.equal(typeof hasBigInts(), 'boolean', 'returns a boolean');
  7. t.end();
  8. });
  9. test('BigInts are supported', { skip: !hasBigInts() }, function (t) {
  10. t.equal(typeof BigInt, 'function', 'global BigInt is a function');
  11. if (typeof BigInt !== 'function') {
  12. return;
  13. }
  14. t.equal(BigInt(42), BigInt(42), '42n === 42n');
  15. t['throws'](
  16. function () { BigInt(NaN); },
  17. RangeError,
  18. 'NaN is not an integer; BigInt(NaN) throws'
  19. );
  20. t['throws'](
  21. function () { BigInt(Infinity); },
  22. RangeError,
  23. 'Infinity is not an integer; BigInt(Infinity) throws'
  24. );
  25. t['throws'](
  26. function () { BigInt(1.1); },
  27. RangeError,
  28. '1.1 is not an integer; BigInt(1.1) throws'
  29. );
  30. t.end();
  31. });
  32. test('BigInts are not supported', { skip: hasBigInts() }, function (t) {
  33. t.equal(typeof BigInt, 'undefined', 'global BigInt is undefined');
  34. t.end();
  35. });