Skip to content

Commit

Permalink
Bugfix: EOF detection with !string.IsNullOrEmpty => !streamReader.End…
Browse files Browse the repository at this point in the history
…OfStream
  • Loading branch information
eduherminio committed Mar 1, 2018
1 parent 50fc416 commit 3fa85c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions FileParserSolution/FileParser/Utils/FileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ static public Queue<Queue<string>> ParseFile(string path, char[] existingSeparat

using (reader)
{
string original_line;
while (!string.IsNullOrEmpty(original_line = reader.ReadLine()))
while (!reader.EndOfStream)
{
string original_line = reader.ReadLine();
// TODO: Evaluate if is it worth giving the user the option of detecting these kind of lines?
if (string.IsNullOrWhiteSpace(original_line) || string.IsNullOrWhiteSpace(original_line))
continue;
// end TODO
Queue<string> parsedLine = new Queue<string>(ProcessLine(original_line, existingSeparator));
parsedFile.Enqueue(parsedLine);
}
Expand Down
3 changes: 3 additions & 0 deletions FileParserSolution/FileParserTest/FileParserTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
</ItemGroup>

<ItemGroup>
<None Update="TestFiles\FileWithEmtpyLines.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\Sample_commas.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
7 changes: 7 additions & 0 deletions FileParserSolution/FileParserTest/ParsedFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,12 @@ public void PeekTestChangesNotAffectingOriginalFile()
Assert.Equal(peekedN, peekedN2);
}
}

[Fact]
public void FileWithEmptyLines()
{
IParsedFile file = new ParsedFile(_sampleFolderPath + "FileWithEmtpyLines.txt");
Assert.True(file.Count == 5);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
False 1 3.14159265 Vishy 12/31/1999 11:59:59 PM

False
1
3.14159265
Vishy

0 comments on commit 3fa85c3

Please sign in to comment.