Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #2 - Support parsing from string

  • Loading branch information...
commit 6e0d49e938bda599c5d389402a4964cf54f8cd67 1 parent 5af8b80
@davglass authored
Showing with 16 additions and 4 deletions.
  1. +6 −4 lib/index.js
  2. +10 −0 tests/parse.js
View
10 lib/index.js
@@ -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);
View
10 tests/parse.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.