Skip to content

Commit

Permalink
package.json deps, more comprehensive (and now failing) tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DTrejo committed Mar 27, 2011
1 parent d3b0e13 commit 041153e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
10 changes: 7 additions & 3 deletions package.json
Expand Up @@ -15,7 +15,11 @@
"scripts": {
"test": "nodeunit test/test.js"
},
"engines": {
"node": "*"
}
"dependencies": {
"traverse": ">=0.2.6"
},
"devDependencies" : {
"nodeunit": ">=0.5.1"
},
"engines": { "node": ">=0.4.1" }
}
13 changes: 13 additions & 0 deletions readme.md
Expand Up @@ -2,6 +2,8 @@

A streaming version of `JSON.stringify`.

npm install

## Methods

### `streamify(object, function)`
Expand Down Expand Up @@ -37,3 +39,14 @@ Most of this was written by [James Halliday](http://substack.net), with a few sm
### TODOs

- allow a stream to be passed into `streamify(object, stream)`?
- escapes strings correctly
- package.json has deps
- throw binary data at it and make sure JSON.parse() doesn't error when you read it back
try using this string:

var s = ''; for (var i = 0; i < 255; i++) { s += String.fromCharCode(i) }

and maybe this to fix it, along with something else.

.replace(/\\/gi, '\\\\')
- fix the tests which fail on the above few todos
15 changes: 15 additions & 0 deletions test/test.js
Expand Up @@ -48,4 +48,19 @@ module.exports = testCase({
assert.done();
});
}
, test_encode_object: function(assert) {
var s = '';
for (var i = 0; i < 255; i++) { s += String.fromCharCode(i); }
var obj = { "a tricky string": s };
var str = ''
streamify(obj, function(data) { str += data; });

assert.equals(JSON.stringify(obj), str
, 'Properly escapes strings');

assert.equals(JSON.parse(JSON.stringify(obj)), JSON.parse(str)
, 'Properly parses strings');
assert.done();
}

});

0 comments on commit 041153e

Please sign in to comment.