Esempio n. 1
0
 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]));
     }
 }
Esempio n. 2
0
 public void WhenFieldIsInQuotes_StripsTheQuotes()
 {
     using (var rowReader = new CsvRowReader("\"Hello\"".ToStream(), Encoding.UTF8, ',', '"'))
     {
         Assert.Collection(rowReader, x => Assert.Equal("Hello", x.Fields[0]));
     }
 }
Esempio n. 3
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]));
     }
 }
Esempio n. 4
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]));
     }
 }
Esempio n. 5
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));
     }
 }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
 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);
     }
 }
Esempio n. 8
0
 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]));
     }
 }
Esempio n. 9
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)));
     }
 }
Esempio n. 10
0
 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)));
     }
 }
Esempio n. 11
0
        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}");
            }
        }