Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/quote-scenarios #89

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions RecordParser.Test/QuotedFileReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using RecordParser.Extensions;
using System;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;

Expand All @@ -18,6 +19,59 @@ public class Quoted
public Gender Gender;
}


[Theory]
[InlineData(true)]
[InlineData(false)]
public void foo(bool parallel)
{
// Arrange

var fileContent = """
A,B,C,D
"x
y",2,3,4
""";

var reader = new StringReader(fileContent);
var options = new VariableLengthReaderRawOptions
{
HasHeader = true,
ContainsQuotedFields = true,
ColumnCount = 4,
Separator = ",",
ParallelismOptions = new()
{
Enabled = parallel,
MaxDegreeOfParallelism = 2
},
};

// Act

var records = reader.ReadRecordsRaw(options, getField =>
{
var record = new
{
A = getField(0),
B = getField(1),
C = getField(2),
D = getField(3)
};
return record;
}).ToList();

// Assert

records.Should().HaveCount(1);

var record = records.Single();
record.A.Should().Be("x\r\ny");
record.B.Should().Be("2");
record.C.Should().Be("3");
record.D.Should().Be("4");
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override IEnumerable<ReadOnlyMemory<char>> ReadLines()
else if (c == quote)
{
ReadOnlySpan<char> span = buffer.AsSpan().Slice(0, i - 1);
var isQuotedField = span.TrimEnd().EndsWith(separator);
var isQuotedField = i == 1 || span[span.Length - 1] == '\n' || span.TrimEnd().EndsWith(separator);

if (isQuotedField is false)
continue;
Expand Down
Loading