diff options
Diffstat (limited to 'ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Parsing/BufferSplittingLineEndingTests.cs')
-rw-r--r-- | ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Parsing/BufferSplittingLineEndingTests.cs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Parsing/BufferSplittingLineEndingTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Parsing/BufferSplittingLineEndingTests.cs new file mode 100644 index 0000000..c4457f4 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Parsing/BufferSplittingLineEndingTests.cs @@ -0,0 +1,98 @@ +// Copyright 2009-2022 Josh Close +// This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0. +// See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html for MS-PL and http://opensource.org/licenses/Apache-2.0 for Apache 2.0. +// https://github.com/JoshClose/CsvHelper +using System.Globalization; +using System.IO; +using System.Text; +using Xunit; + +namespace CsvHelper.Tests.Parsing +{ + + public class BufferSplittingLineEndingTests + { + [Fact] + public void Read_BufferSplitsCrLf_BufferNeedsResize_Parses() + { + var s = new StringBuilder(); + s.Append("1,0000000000321\r\n"); + s.Append("3,4\r\n"); + var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture) + { + BufferSize = 16, + }; + using (var reader = new StringReader(s.ToString())) + using (var parser = new CsvParser(reader, config)) + { + parser.Read(); + Assert.Equal("1", parser[0]); + Assert.Equal("0000000000321", parser[1]); + } + } + + [Fact] + public void Read_BufferSplitsCrLf_NoBufferResize_DoesntAddExtraField() + { + var s = new StringBuilder(); + s.Append("1,200000\r\n"); + s.Append("3,400000\r\n"); + s.Append("5,600\r\n"); + var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture) + { + BufferSize = 16, + }; + using (var reader = new StringReader(s.ToString())) + using (var parser = new CsvParser(reader, config)) + { + parser.Read(); + parser.Read(); + parser.Read(); + Assert.Equal(2, parser.Count); + } + } + + [Fact] + public void Read_BufferSplitsCrLf_NoBufferResize_RawRecordIsCorrect() + { + var s = new StringBuilder(); + s.Append("1,200000\r\n"); + s.Append("3,400000\r\n"); + s.Append("5,600\r\n"); + var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture) + { + BufferSize = 16, + }; + using (var reader = new StringReader(s.ToString())) + using (var parser = new CsvParser(reader, config)) + { + parser.Read(); + parser.Read(); + parser.Read(); + Assert.Equal("5,600\r\n", parser.RawRecord); + } + } + + [Fact] + public void BufferSplitsCrLfWithLastFieldQuotedTest() + { + var s = new StringBuilder(); + s.Append("1,200000\r\n"); + s.Append("3,4000\r\n"); + s.Append("5,\"600\"\r\n"); + var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture) + { + BufferSize = 16, + }; + using (var reader = new StringReader(s.ToString())) + using (var parser = new CsvParser(reader, config)) + { + parser.Read(); + parser.Read(); + parser.Read(); + Assert.Equal(2, parser.Count); + Assert.Equal("5,\"600\"\r\n", parser.RawRecord); + } + } + } +} |