Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / json-bigint / test / bigint-test.js
diff --git a/legacy-libs/json-bigint/test/bigint-test.js b/legacy-libs/json-bigint/test/bigint-test.js
new file mode 100644 (file)
index 0000000..5f5e1a3
--- /dev/null
@@ -0,0 +1,31 @@
+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();
+    });
+});