Ejemplo n.º 1
0
        public void ByteCountTestWithQuotedFieldsClosingQuoteAtStartOfBuffer()
        {
            var config = new Configuration.CsvConfiguration()
            {
                CountBytes = true,
                BufferSize = 4
            };

            using( var stream = new MemoryStream() )
            using( var writer = new StreamWriter( stream ) )
            using( var reader = new StreamReader( stream ) )
            using( var parser = new CsvParser( reader, config ) )
            {
                writer.Write( "1,\"2\",3\r\n" );
                writer.Write( "\"4\",5,\"6\"\r\n" );
                writer.Flush();
                stream.Position = 0;

                parser.Read();
                Assert.AreEqual( 9, parser.BytePosition );

                parser.Read();
                Assert.AreEqual( 20, parser.BytePosition );

                Assert.IsNull( parser.Read() );
            }
        }
Ejemplo n.º 2
0
        public void ByteCountTestWithQuotedFieldsEscapedQuoteAtStartOfBuffer()
        {
            var config = new Configuration.CsvConfiguration()
            {
                CountBytes = true,
                BufferSize = 4
            };

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var parser = new CsvParser(reader, config))
                        {
                            writer.Write("1,\"2a\",3\r\n");
                            writer.Write("\"\"\"4\"\"\",5,\"6\"\r\n");
                            writer.Flush();
                            stream.Position = 0;

                            var r1 = parser.Read();
                            Assert.AreEqual(10, parser.BytePosition);

                            var r2 = parser.Read();
                            Assert.AreEqual(25, parser.BytePosition);

                            Assert.IsNull(parser.Read());
                        }
        }