Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
leandromoh committed Nov 1, 2023
1 parent f9134aa commit 8d4a228
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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

0 comments on commit 8d4a228

Please sign in to comment.