|
1 | | -var mocha = require('mocha') |
2 | | - , assert = require('chai').assert |
3 | | - , expect = require('chai').expect |
4 | | - ; |
| 1 | +var mocha = require('mocha'), |
| 2 | + assert = require('chai').assert, |
| 3 | + expect = require('chai').expect; |
| 4 | +describe("Testing 'strict' option", function () { |
| 5 | + var dupkeys = '{ "dupkey": "value 1", "dupkey": "value 2"}'; |
| 6 | + it('Should show that duplicate keys just get overwritten by default', function (done) { |
| 7 | + var JSONbig = require('../index'); |
| 8 | + var result = 'before'; |
| 9 | + function tryParse() { |
| 10 | + result = JSONbig.parse(dupkeys); |
| 11 | + } |
| 12 | + expect(tryParse).to.not.throw('anything'); |
| 13 | + expect(result.dupkey).to.equal('value 2'); |
| 14 | + done(); |
| 15 | + }); |
5 | 16 |
|
6 | | -describe("Testing 'strict' option", function(){ |
7 | | - var dupkeys = '{ "dupkey": "value 1", "dupkey": "value 2"}'; |
8 | | - it("Should show that duplicate keys just get overwritten by default", function(done){ |
9 | | - var JSONbig = require('../index'); |
10 | | - var result = "before"; |
11 | | - function tryParse() { |
12 | | - result = JSONbig.parse(dupkeys); |
13 | | - } |
14 | | - expect(tryParse).to.not.throw("anything"); |
15 | | - expect(result.dupkey).to.equal("value 2"); |
16 | | - done(); |
17 | | - }); |
| 17 | + it("Should show that the 'strict' option will fail-fast on duplicate keys", function (done) { |
| 18 | + var JSONstrict = require('../index')({ strict: true }); |
| 19 | + var result = 'before'; |
| 20 | + function tryParse() { |
| 21 | + result = JSONstrict.parse(dupkeys); |
| 22 | + } |
18 | 23 |
|
19 | | - it("Should show that the 'strict' option will fail-fast on duplicate keys", function(done){ |
20 | | - var JSONstrict = require('../index')({"strict": true}); |
21 | | - var result = "before"; |
22 | | - function tryParse() { |
23 | | - result = JSONstrict.parse(dupkeys); |
24 | | - } |
25 | | - expect(tryParse).to.throw({ |
26 | | - name: 'SyntaxError', |
27 | | - message: 'Duplicate key "dupkey"', |
28 | | - at: 33, |
29 | | - text: '{ "dupkey": "value 1", "dupkey": "value 2"}' |
30 | | - }); |
31 | | - expect(result).to.equal("before"); |
32 | | - done(); |
33 | | - }); |
| 24 | + expect(tryParse).to.throw('Duplicate key "dupkey"'); |
| 25 | + expect(result).to.equal('before'); |
| 26 | + done(); |
| 27 | + }); |
34 | 28 | }); |
0 commit comments