Permalink
Browse files

Test 'lineReader open hasNextLine should return true when buffer is e…

…mpty but not at EOF.' fixes #4.
  • Loading branch information...
1 parent 5444395 commit 146bb4202cfea2ddc8130e2884b9d963f6229435 @nickewing committed Sep 5, 2012
Showing with 25 additions and 1 deletion.
  1. +1 −1 lib/line_reader.js
  2. +3 −0 test/data/three_line_file.txt
  3. +21 −0 test/line_reader.js
View
@@ -62,7 +62,7 @@
}
function hasNextLine() {
- return bufferStr.length > 0;
+ return bufferStr.length > 0 || !eof;
}
function nextLine(cb) {
@@ -0,0 +1,3 @@
+This is line one.
+This is line two.
+This is line three.
View
@@ -5,6 +5,7 @@ var lineReader = require('../lib/line_reader'),
multibyteFilePath = __dirname + '/data/multibyte_file.txt',
emptyFilePath = __dirname + '/data/empty_file.txt',
oneLineFilePath = __dirname + '/data/one_line_file.txt',
+ threeLineFilePath = __dirname + '/data/three_line_file.txt',
testSeparatorFile = ['foo', 'bar\n', 'baz\n'],
testFile = [
'Jabberwocky',
@@ -179,5 +180,25 @@ describe("lineReader", function() {
});
}, '\n', 'utf8', 2);
});
+
+ describe("hasNextLine", function() {
+ it("should return true when buffer is empty but not at EOF", function(done) {
+ lineReader.open(threeLineFilePath, function(reader) {
+ reader.nextLine(function(line) {
+ assert.equal("This is line one.", line);
+ assert.ok(reader.hasNextLine());
+ reader.nextLine(function(line) {
+ assert.equal("This is line two.", line);
+ assert.ok(reader.hasNextLine());
+ reader.nextLine(function(line) {
+ assert.equal("This is line three.", line);
+ assert.ok(!reader.hasNextLine());
+ done();
+ });
+ });
+ });
+ }, '\n', 'utf-8', 36);
+ });
+ });
});
});

0 comments on commit 146bb42

Please sign in to comment.