bigint-test.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. var mocha = require('mocha')
  2. , assert = require('chai').assert
  3. , expect = require('chai').expect
  4. , BigNumber = require('bignumber.js')
  5. ;
  6. describe("Testing bigint support", function(){
  7. var input = '{"big":9223372036854775807,"small":123}';
  8. it("Should show classic JSON.parse lacks bigint support", function(done){
  9. var obj = JSON.parse(input);
  10. expect(obj.small.toString(), "string from small int").to.equal("123");
  11. expect(obj.big.toString(), "string from big int").to.not.equal("9223372036854775807");
  12. var output = JSON.stringify(obj);
  13. expect(output).to.not.equal(input);
  14. done();
  15. });
  16. it("Should show JSONbig does support bigint parse/stringify roundtrip", function(done){
  17. var JSONbig = require('../index');
  18. var obj = JSONbig.parse(input);
  19. expect(obj.small.toString(), "string from small int").to.equal("123");
  20. expect(obj.big.toString(), "string from big int").to.equal("9223372036854775807");
  21. expect(obj.big, "instanceof big int").to.be.instanceof(BigNumber);
  22. var output = JSONbig.stringify(obj);
  23. expect(output).to.equal(input);
  24. done();
  25. });
  26. });