Skip to content

Commit

Permalink
Fixes #2 - Support parsing from string
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Mar 28, 2013
1 parent 5af8b80 commit 6e0d49e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/index.js
Expand Up @@ -96,15 +96,17 @@ var walkFile = function(str, cb) {
item = {};
}
});
cb(null, data);
if (data.length) {
cb(null, data);
} else {
cb('Failed to parse string');
}
};

var parse = function(file, cb) {

exists(file, function(x) {
if (!x) {
cb("Failed to find file: " + file);
return;
return walkFile(file, cb);
}
fs.readFile(file, 'utf8', function(err, str) {
walkFile(str, cb);
Expand Down
10 changes: 10 additions & 0 deletions tests/parse.js
Expand Up @@ -22,6 +22,16 @@ var tests = {
assert.isString(err);
}
},
'Parse as a string': {
topic: function() {
parse('TN:TestName\nSF:foobar.js\nend_of_record\n', this.callback);
},
'should parse': function(err, data) {
assert.isArray(data);
assert.equal('TestName', data[0].title);
assert.equal('foobar.js', data[0].file);
}
},
'parse the file': {
topic: function() {
parse(yuiFile, this.callback);
Expand Down

0 comments on commit 6e0d49e

Please sign in to comment.