This repository has been archived by the owner on Dec 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14362c9
commit dd916d7
Showing
5 changed files
with
168 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
|
|||
|
|||
/* | |||
sometimes jsonparse changes numbers slightly. | |||
*/ | |||
|
|||
var r = Math.random() | |||
, Parser = require('jsonparse') | |||
, p = new Parser() | |||
, assert = require('assert') | |||
, times = 20 | |||
while (times --) { | |||
|
|||
assert.equal(JSON.parse(JSON.stringify(r)), r, 'core JSON') | |||
|
|||
p.onValue = function (v) { | |||
console.error('parsed', v) | |||
assert.equal(v, r) | |||
} | |||
console.error('correct', r) | |||
p.write (new Buffer(JSON.stringify([r]))) | |||
|
|||
|
|||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
|
|||
var fs = require ('fs') | |||
, join = require('path').join | |||
, file = join(__dirname, 'fixtures','all_npm.json') | |||
, JSONStream = require('../') | |||
, it = require('it-is').style('colour') | |||
|
|||
function randomObj () { | |||
return ( | |||
Math.random () < 0.4 | |||
? {hello: 'eonuhckmqjk', | |||
whatever: 236515, | |||
lies: true, | |||
nothing: [null], | |||
stuff: [Math.random(),Math.random(),Math.random()] | |||
} | |||
: ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]] | |||
) | |||
} | |||
|
|||
var expected = [] | |||
, stringify = JSONStream.stringify() | |||
, es = require('event-stream') | |||
, stringified = '' | |||
, called = 0 | |||
, count = 10 | |||
, ended = false | |||
|
|||
while (count --) | |||
expected.push(randomObj()) | |||
|
|||
es.connect( | |||
es.readArray(expected), | |||
stringify, | |||
//JSONStream.parse([/./]), | |||
es.writeArray(function (err, lines) { | |||
|
|||
it(JSON.parse(lines.join(''))).deepEqual(expected) | |||
console.error('PASSED') | |||
}) | |||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
|
|||
var fs = require ('fs') | |||
, join = require('path').join | |||
, file = join(__dirname, 'fixtures','all_npm.json') | |||
, JSONStream = require('../') | |||
, it = require('it-is').style('colour') | |||
|
|||
function randomObj () { | |||
return ( | |||
Math.random () < 0.4 | |||
? {hello: 'eonuhckmqjk', | |||
whatever: 236515, | |||
lies: true, | |||
nothing: [null], | |||
// stuff: [Math.random(),Math.random(),Math.random()] | |||
} | |||
: ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]] | |||
) | |||
} | |||
|
|||
var expected = [] | |||
, stringify = JSONStream.stringify() | |||
, es = require('event-stream') | |||
, stringified = '' | |||
, called = 0 | |||
, count = 10 | |||
, ended = false | |||
|
|||
while (count --) | |||
expected.push(randomObj()) | |||
|
|||
es.connect( | |||
es.readArray(expected), | |||
stringify, | |||
JSONStream.parse([/./]), | |||
es.writeArray(function (err, lines) { | |||
|
|||
it(lines).has(expected) | |||
console.error('PASSED') | |||
}) | |||
) |