CsvFieldIndexer: Fix handling of escaped characters

This commit is contained in:
2024-02-19 02:47:29 +01:00
parent 52cb729c0e
commit 13d9218944
3 changed files with 107 additions and 1 deletions

View File

@@ -36,7 +36,6 @@ public class CsvParserTest
Assert.Equal("Hello World", parser.Data[0][0]);
}
[Fact]
public void Parse__TwoLinesOfPainText__TwoRows()
{
@@ -105,6 +104,50 @@ public class CsvParserTest
Assert.Equal("World", parser.Data[1][1]);
}
[Fact]
public void Parse__TwoLinesWithOneQuotedColumnsWithEscapedQuotes__TwoRows()
{
// --- Arrange
StringReader sr = new(
"""
"Hello \"World\""
"Hello \"World\""
""");
// --- Act
CsvParser parser = new();
parser.Parse(sr);
// --- Assert
Assert.Equal(2, parser.Data.Count);
Assert.Single(parser.Data[0]);
Assert.Equal("Hello \"World\"", parser.Data[0][0]);
Assert.Single(parser.Data[1]);
Assert.Equal("Hello \"World\"", parser.Data[1][0]);
}
[Fact]
public void Parse__TwoLinesWithOneQuotedColumnsWithManyEscapedQuotes__TwoRows()
{
// --- Arrange
StringReader sr = new(
"""
"Hello \"World\""
"Hello \"World\"\"\""
""");
// --- Act
CsvParser parser = new();
parser.Parse(sr);
// --- Assert
Assert.Equal(2, parser.Data.Count);
Assert.Single(parser.Data[0]);
Assert.Equal("Hello \"World\"", parser.Data[0][0]);
Assert.Single(parser.Data[1]);
Assert.Equal("Hello \"World\"\"\"", parser.Data[1][0]);
}
[Fact]
public void GenerateIndex__TwoLinesWithTwoQuotedColumnsWithUnicode__TwoRowsTwoFields()
{