Skip to content

Commit

Permalink
Add multi-targeting to unit test project with net481 support (#40)
Browse files Browse the repository at this point in the history
* Add multi-targeting to unit test project with net481 support

* Use .NET 8 SDK in build pipeline
  • Loading branch information
paulirwin authored Aug 9, 2024
1 parent e08c8c4 commit f2b0321
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Setup .NET
- name: Setup .NET 6
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Setup .NET 8
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
7 changes: 3 additions & 4 deletions test/F23.StringSimilarity.Tests/DamerauTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using F23.StringSimilarity.Tests.TestUtil;
using Xunit;

Expand All @@ -48,11 +47,11 @@ public void TestDistance(string s1, string s2, double expected)

// test char span version
Assert.Equal(expected, actual: instance.Distance(s1.AsSpan(), s2.AsSpan()));

// test byte span version
Assert.Equal(expected, actual: instance.Distance<byte>(
Encoding.Latin1.GetBytes(s1).AsSpan(),
Encoding.Latin1.GetBytes(s2).AsSpan()));
EncodingUtil.Latin1.GetBytes(s1).AsSpan(),
EncodingUtil.Latin1.GetBytes(s2).AsSpan()));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(TargetFrameworks);net481</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions test/F23.StringSimilarity.Tests/JaroWinklerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void TestSimilarity(string s1, string s2, double expected)
Assert.Equal(
expected,
actual: instance.Similarity<byte>(
System.Text.Encoding.Latin1.GetBytes(s1).AsSpan(),
System.Text.Encoding.Latin1.GetBytes(s2).AsSpan()),
EncodingUtil.Latin1.GetBytes(s1).AsSpan(),
EncodingUtil.Latin1.GetBytes(s2).AsSpan()),
precision: 6 // 0.000001
);
}
Expand Down
8 changes: 4 additions & 4 deletions test/F23.StringSimilarity.Tests/LevenshteinTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void TestDistance(string s1, string s2, double expected)

// test byte span version
Assert.Equal(expected, actual: instance.Distance<byte>(
System.Text.Encoding.Latin1.GetBytes(s1).AsSpan(),
System.Text.Encoding.Latin1.GetBytes(s2).AsSpan()));
EncodingUtil.Latin1.GetBytes(s1).AsSpan(),
EncodingUtil.Latin1.GetBytes(s2).AsSpan()));
}

[InlineData("My string", "M string2", 4, 2.0)]
Expand All @@ -70,8 +70,8 @@ public void TestDistanceWithLimits(string s1, string s2, int limit, double expec

// test byte span version
Assert.Equal(expected, actual: instance.Distance<byte>(
System.Text.Encoding.Latin1.GetBytes(s1).AsSpan(),
System.Text.Encoding.Latin1.GetBytes(s2).AsSpan(),
EncodingUtil.Latin1.GetBytes(s1).AsSpan(),
EncodingUtil.Latin1.GetBytes(s2).AsSpan(),
limit));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void TestDistance(string s1, string s2, double expected)

// test byte span version
Assert.Equal(expected, actual: instance.Distance<byte>(
System.Text.Encoding.Latin1.GetBytes(s1).AsSpan(),
System.Text.Encoding.Latin1.GetBytes(s2).AsSpan()));
EncodingUtil.Latin1.GetBytes(s1).AsSpan(),
EncodingUtil.Latin1.GetBytes(s2).AsSpan()));
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions test/F23.StringSimilarity.Tests/OptimalStringAlignmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void TestDistance(string s1, string s2, double expected)
Assert.Equal(
expected: expected,
actual: instance.Distance<byte>(
System.Text.Encoding.Latin1.GetBytes(s1).AsSpan(),
System.Text.Encoding.Latin1.GetBytes(s2).AsSpan()),
EncodingUtil.Latin1.GetBytes(s1).AsSpan(),
EncodingUtil.Latin1.GetBytes(s2).AsSpan()),
precision: 0 // 0.0
);
}
Expand Down
13 changes: 13 additions & 0 deletions test/F23.StringSimilarity.Tests/TestUtil/EncodingUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Text;

namespace F23.StringSimilarity.Tests.TestUtil;

internal class EncodingUtil
{
public static Encoding Latin1 =>
#if NET5_0_OR_GREATER
Encoding.Latin1;
#else
Encoding.GetEncoding("ISO-8859-1");
#endif
}

0 comments on commit f2b0321

Please sign in to comment.