Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
leandromoh committed Oct 23, 2023
1 parent 9f81357 commit edab6d3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion RecordParser.Benchmark/FixedLengthReaderBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion RecordParser.Benchmark/VariableLengthReaderBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions RecordParser.Test/SpanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public static string ToLower(this ReadOnlySpan<char> value)
public static StringAssertions Should(this Span<char> value)
=> value.ToString().Should();

// FluentAssertions does not support ReadOnlySpan yet
public static StringAssertions Should(this ReadOnlySpan<char> value)
=> value.ToString().Should();

public static readonly FuncSpanTIntBool ToUpperInvariant = (Span<char> span, ReadOnlySpan<char> text) =>
(text.ToUpperInvariant(span) is var written && written == text.Length, Math.Max(0, written));
Expand Down
71 changes: 71 additions & 0 deletions RecordParser.Test/TextFindHelperTest.cs
Original file line number Diff line number Diff line change
@@ -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<Exception>().WithMessage("can only be forward");

a.Should().Be(id);
b.Should().Be(date);
c.Should().Be(color);
d.Should().BeNull();
}
}
}
6 changes: 6 additions & 0 deletions RecordParser/RecordParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<None Include="..\LICENSE.md" Pack="true" PackagePath="LICENSE.md"/>
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>RecordParser.Test</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<PropertyGroup Condition="
( '$(Configuration)' == 'Debug' OR '$(Configuration)' == 'Release') AND
( '$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0') AND
Expand Down

0 comments on commit edab6d3

Please sign in to comment.