diff --git a/RecordParser.Benchmark/FixedLengthReaderBenchmark.cs b/RecordParser.Benchmark/FixedLengthReaderBenchmark.cs index ba5a5ce..0e1d2fa 100644 --- a/RecordParser.Benchmark/FixedLengthReaderBenchmark.cs +++ b/RecordParser.Benchmark/FixedLengthReaderBenchmark.cs @@ -4,7 +4,7 @@ using FlatFiles; using FlatFiles.TypeMapping; using RecordParser.Builders.Reader; -using RecordParser.Extensions.FileReader; +using RecordParser.Extensions; using System; using System.Globalization; using System.IO; diff --git a/RecordParser.Benchmark/VariableLengthReaderBenchmark.cs b/RecordParser.Benchmark/VariableLengthReaderBenchmark.cs index e476f46..77ec9f3 100644 --- a/RecordParser.Benchmark/VariableLengthReaderBenchmark.cs +++ b/RecordParser.Benchmark/VariableLengthReaderBenchmark.cs @@ -7,7 +7,7 @@ using FlatFiles; using FlatFiles.TypeMapping; using RecordParser.Builders.Reader; -using RecordParser.Extensions.FileReader; +using RecordParser.Extensions; using System; using System.Globalization; using System.IO; diff --git a/RecordParser.Test/SpanExtensions.cs b/RecordParser.Test/SpanExtensions.cs index 401b99e..50a8599 100644 --- a/RecordParser.Test/SpanExtensions.cs +++ b/RecordParser.Test/SpanExtensions.cs @@ -25,6 +25,9 @@ public static string ToLower(this ReadOnlySpan value) public static StringAssertions Should(this Span value) => value.ToString().Should(); + // FluentAssertions does not support ReadOnlySpan yet + public static StringAssertions Should(this ReadOnlySpan value) + => value.ToString().Should(); public static readonly FuncSpanTIntBool ToUpperInvariant = (Span span, ReadOnlySpan text) => (text.ToUpperInvariant(span) is var written && written == text.Length, Math.Max(0, written)); diff --git a/RecordParser.Test/TextFindHelperTest.cs b/RecordParser.Test/TextFindHelperTest.cs new file mode 100644 index 0000000..07d45d2 --- /dev/null +++ b/RecordParser.Test/TextFindHelperTest.cs @@ -0,0 +1,71 @@ +using FluentAssertions; +using RecordParser.Engines.Reader; +using System; +using Xunit; + +namespace RecordParser.Test +{ + public class TextFindHelperTest : TestSetup + { + [Fact] + public void Given_column_mapped_more_than_once_should_works() + { + var id = Guid.NewGuid().ToString(); + var date = "2020.05.23"; + var color = "LightBlue"; + + var record = $"{id};{date};{color}"; + var finder = new TextFindHelper(record, ";", ('"', "\"")); + ; + // Act + + var a = finder.GetValue(0); + var b = finder.GetValue(0); + var c = finder.GetValue(1); + var d = finder.GetValue(2); + var e = finder.GetValue(2); + + // Assert + + a.Should().Be(id); + b.Should().Be(id); + c.Should().Be(date); + d.Should().Be(color); + e.Should().Be(color); + } + + [Fact] + public void Given_access_to_past_column_should_throw() + { + var id = Guid.NewGuid().ToString(); + var date = "2020.05.23"; + var color = "LightBlue"; + + var record = $"{id};{date};{color}"; + + string a, b, c, d; + a = b = c = d = null; + + // Act + + var action = () => + { + var finder = new TextFindHelper(record, ";", ('"', "\"")); + + a = finder.GetValue(0).ToString(); + b = finder.GetValue(1).ToString(); + c = finder.GetValue(2).ToString(); + d = finder.GetValue(1).ToString(); + }; + + // Assert + + action.Should().Throw().WithMessage("can only be forward"); + + a.Should().Be(id); + b.Should().Be(date); + c.Should().Be(color); + d.Should().BeNull(); + } + } +} diff --git a/RecordParser/RecordParser.csproj b/RecordParser/RecordParser.csproj index 8b7b2db..a0b4a81 100644 --- a/RecordParser/RecordParser.csproj +++ b/RecordParser/RecordParser.csproj @@ -30,6 +30,12 @@ + + + <_Parameter1>RecordParser.Test + + +