public void WhenFieldIsInQuotes_NewLineIsReadAsPartOfTheField() { using (var rowReader = new CsvRowReader("\"Hello\r\nWorld\"".ToStream(), Encoding.UTF8, ',', '"')) { Assert.Collection(rowReader, x => Assert.Equal("Hello\r\nWorld", x.Fields[0])); } }
public void WhenFieldIsInQuotes_StripsTheQuotes() { using (var rowReader = new CsvRowReader("\"Hello\"".ToStream(), Encoding.UTF8, ',', '"')) { Assert.Collection(rowReader, x => Assert.Equal("Hello", x.Fields[0])); } }
public void WhenFieldIsInQuotes_ReplacesTwoQuotesWithASingleQuote() { using (var rowReader = new CsvRowReader("\"Hello \"\"World\"\"\"".ToStream(), Encoding.UTF8, ',', '"')) { Assert.Collection(rowReader, x => Assert.Equal("Hello \"World\"", x.Fields[0])); } }
public void NewLineAtEndOfStreamIsIgnored() { using (var rowReader = new CsvRowReader("Hello\r\n".ToStream(), Encoding.UTF8, ',', '"')) { Assert.Collection(rowReader, x => Assert.Equal("Hello", x.Fields[0])); } }
public void WhenLeftHandFieldIsEmpty_ReturnsEmptyField() { using (var rowReader = new CsvRowReader(",World".ToStream(), Encoding.UTF8, ',', '"')) { Assert.Collection(rowReader.First().Fields, x => Assert.Equal("", x), x => Assert.Equal("World", x)); } }
public void WhenFieldIsInQuotes_AndContainsOneQuoteAloneAndNotAtEndOfField_ThrowsCsvException() { using (var rowReader = new CsvRowReader("\"Hello \"World\"".ToStream(), Encoding.UTF8, ',', '"')) { var ex = Assert.Throws <CsvException>(() => rowReader.First()); Assert.Equal(8, ex.Position); } }
public void GivenFieldIsNotInQuotes_WhenItContainsAQuote_ThrowsCsvException() { using (var rowReader = new CsvRowReader("Hello \"World".ToStream(), Encoding.UTF8, ',', '"')) { var ex = Assert.Throws <CsvException>(() => rowReader.First()); Assert.Equal(7, ex.Position); } }
public void NewLineMarksEndOfRow() { using (var rowReader = new CsvRowReader("Hello\r\nWorld".ToStream(), Encoding.UTF8, ',', '"')) { Assert.Collection(rowReader, x => Assert.Equal("Hello", x.Fields[0]), x => Assert.Equal("World", x.Fields[0])); } }
public void WhenDataIsSeperatedByCommas_ReadsAsSeperateFields() { using (var rowReader = new CsvRowReader("Hello,World".ToStream(), Encoding.UTF8, ',', '"')) { Assert.Collection(rowReader, x => Assert.Collection(x.Fields, f => Assert.Equal("Hello", f), f => Assert.Equal("World", f))); } }
public void WhenPassingHashQualifierAndTildeSeparator_ThenParsesRecordCorrectly() { using (var rowReader = new CsvRowReader("Hello~World~#Field~with~tildes#".ToStream(), Encoding.UTF8, '~', '#')) { Assert.Collection(rowReader, x => Assert.Collection(x.Fields, f => Assert.Equal("Hello", f), f => Assert.Equal("World", f), f => Assert.Equal("Field~with~tildes", f))); } }
static void Main(string[] args) { CsvRowReader.Use(); var text = "First,Last\nJohn,Doe\n"; var file = NameFile.Parse(text); foreach (var n in file) { WriteLine($"{n.First} {n.Last}"); } }