mirror of
https://github.com/musix-org/musix-oss
synced 2024-11-14 03:30:18 +00:00
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
|
var mocha = require('mocha')
|
||
|
, assert = require('chai').assert
|
||
|
, expect = require('chai').expect
|
||
|
, BigNumber = require('bignumber.js')
|
||
|
;
|
||
|
|
||
|
describe("Testing bigint support", function(){
|
||
|
var input = '{"big":9223372036854775807,"small":123}';
|
||
|
|
||
|
it("Should show classic JSON.parse lacks bigint support", function(done){
|
||
|
var obj = JSON.parse(input);
|
||
|
expect(obj.small.toString(), "string from small int").to.equal("123");
|
||
|
expect(obj.big.toString(), "string from big int").to.not.equal("9223372036854775807");
|
||
|
|
||
|
var output = JSON.stringify(obj);
|
||
|
expect(output).to.not.equal(input);
|
||
|
done();
|
||
|
});
|
||
|
|
||
|
it("Should show JSNbig does support bigint parse/stringify roundtrip", function(done){
|
||
|
var JSONbig = require('../index');
|
||
|
var obj = JSONbig.parse(input);
|
||
|
expect(obj.small.toString(), "string from small int").to.equal("123");
|
||
|
expect(obj.big.toString(), "string from big int").to.equal("9223372036854775807");
|
||
|
expect(obj.big, "instanceof big int").to.be.instanceof(BigNumber);
|
||
|
|
||
|
var output = JSONbig.stringify(obj);
|
||
|
expect(output).to.equal(input);
|
||
|
done();
|
||
|
});
|
||
|
});
|