mirror of
https://github.com/SabreTools/SabreTools.Matching.git
synced 2026-02-10 21:31:14 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
036ee4246b | ||
|
|
8e3bcb9015 | ||
|
|
8b1ac53ccf | ||
|
|
0c9e255d48 | ||
|
|
1227488572 | ||
|
|
bd878cf1a1 | ||
|
|
b436b64c3a | ||
|
|
6f6d071a79 | ||
|
|
69130a6e9f |
@@ -8,7 +8,7 @@ namespace SabreTools.Matching.Test.Compare
|
||||
public class NaturalComparerTests
|
||||
{
|
||||
[Fact]
|
||||
public void NaturalComparer_ListSort_Numeric()
|
||||
public void ListSort_Numeric()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["0", "100", "5", "2", "1000"];
|
||||
@@ -22,7 +22,7 @@ namespace SabreTools.Matching.Test.Compare
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NaturalComparer_ListSort_Mixed()
|
||||
public void ListSort_Mixed()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["b3b", "c", "b", "a", "a1"];
|
||||
@@ -34,33 +34,5 @@ namespace SabreTools.Matching.Test.Compare
|
||||
// Check the output
|
||||
Assert.True(sortable.SequenceEqual(expected));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NaturalReversedComparer_ListSort_Numeric()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["0", "100", "5", "2", "1000"];
|
||||
string[] expected = ["1000", "100", "5", "2", "0"];
|
||||
|
||||
// Run sorting on array
|
||||
Array.Sort(sortable, new NaturalReversedComparer());
|
||||
|
||||
// Check the output
|
||||
Assert.True(sortable.SequenceEqual(expected));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NaturalReversedComparer_ListSort_Mixed()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["b3b", "c", "b", "a", "a1"];
|
||||
string[] expected = ["c", "b3b", "b", "a1", "a"];
|
||||
|
||||
// Run sorting on array
|
||||
Array.Sort(sortable, new NaturalReversedComparer());
|
||||
|
||||
// Check the output
|
||||
Assert.True(sortable.SequenceEqual(expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace SabreTools.Matching.Test.Compare
|
||||
int actual = NaturalComparerUtil.ComparePaths(null, null);
|
||||
Assert.Equal(0, actual);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void CompareNumeric_SingleNull_Ordered()
|
||||
{
|
||||
@@ -63,4 +63,4 @@ namespace SabreTools.Matching.Test.Compare
|
||||
Assert.Equal(-1, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using SabreTools.Matching.Compare;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Matching.Test.Compare
|
||||
{
|
||||
public class NaturalReversedComparerTests
|
||||
{
|
||||
[Fact]
|
||||
public void ListSort_Numeric()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["0", "100", "5", "2", "1000"];
|
||||
string[] expected = ["1000", "100", "5", "2", "0"];
|
||||
|
||||
// Run sorting on array
|
||||
Array.Sort(sortable, new NaturalReversedComparer());
|
||||
|
||||
// Check the output
|
||||
Assert.True(sortable.SequenceEqual(expected));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ListSort_Mixed()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["b3b", "c", "b", "a", "a1"];
|
||||
string[] expected = ["c", "b3b", "b", "a1", "a"];
|
||||
|
||||
// Run sorting on array
|
||||
Array.Sort(sortable, new NaturalReversedComparer());
|
||||
|
||||
// Check the output
|
||||
Assert.True(sortable.SequenceEqual(expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,4 +199,4 @@ namespace SabreTools.Matching.Test.Content
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,4 +268,4 @@ namespace SabreTools.Matching.Test.Content
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,4 +393,4 @@ namespace SabreTools.Matching.Test
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,4 +321,4 @@ namespace SabreTools.Matching.Test
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,4 @@ namespace SabreTools.Matching.Test.Paths
|
||||
Assert.Equal(expected, fpm.Needle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,4 +183,4 @@ namespace SabreTools.Matching.Test.Paths
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,4 +290,4 @@ namespace SabreTools.Matching.Test.Paths
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<NoWarn>NU1903</NoWarn>
|
||||
@@ -10,13 +10,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -329,4 +329,4 @@ namespace SabreTools.Matching.Content
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,4 +235,4 @@ namespace SabreTools.Matching.Content
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,4 @@ namespace SabreTools.Matching
|
||||
/// <param name="positions">List of positions in the Stream that were matched</param>
|
||||
/// <returns>Version string on success, null on failure</returns>
|
||||
public delegate string? GetStreamVersion(string path, Stream? content, List<int> positions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace System.Runtime.CompilerServices
|
||||
internal sealed class ExtensionAttribute : Attribute {}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -223,4 +223,4 @@ namespace SabreTools.Matching
|
||||
return FirstPosition(stack, needle, start: stack.Length - needle.Length) > -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
namespace SabreTools.Matching
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a matcher for a particular type
|
||||
/// </summary>
|
||||
public interface IMatch<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Nullable typed data to be matched
|
||||
/// </summary>
|
||||
T? Needle { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,4 @@ namespace SabreTools.Matching
|
||||
/// </summary>
|
||||
public string SetName { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace SabreTools.Matching
|
||||
var version = matcher.GetArrayVersion(file, stack, positions);
|
||||
if (version == null)
|
||||
continue;
|
||||
|
||||
|
||||
// Trim and add the version
|
||||
version = version.Trim();
|
||||
if (version.Length > 0)
|
||||
@@ -212,7 +212,7 @@ namespace SabreTools.Matching
|
||||
var version = matcher.GetStreamVersion(file, stack, positions);
|
||||
if (version == null)
|
||||
continue;
|
||||
|
||||
|
||||
// Trim and add the version
|
||||
version = version.Trim();
|
||||
if (version.Length > 0)
|
||||
@@ -314,12 +314,20 @@ namespace SabreTools.Matching
|
||||
foreach (var matcher in matchSets)
|
||||
{
|
||||
// Determine if the matcher passes
|
||||
List<string> matches = any
|
||||
? [matcher.MatchesAny(stack)]
|
||||
: matcher.MatchesAll(stack);
|
||||
List<string> matches = [];
|
||||
if (any)
|
||||
{
|
||||
string? anyMatch = matcher.MatchesAny(stack);
|
||||
if (anyMatch != null)
|
||||
matches = [anyMatch];
|
||||
}
|
||||
else
|
||||
{
|
||||
matches = matcher.MatchesAll(stack);
|
||||
}
|
||||
|
||||
// If we don't have a pass, just continue
|
||||
if (matches.Count == 0 || matches[0] == null)
|
||||
if (matches.Count == 0)
|
||||
continue;
|
||||
|
||||
// Build the output string
|
||||
@@ -333,7 +341,7 @@ namespace SabreTools.Matching
|
||||
var version = matcher.GetVersion(matches[0], stack);
|
||||
if (version == null)
|
||||
continue;
|
||||
|
||||
|
||||
// Trim and add the version
|
||||
version = version.Trim();
|
||||
if (version.Length > 0)
|
||||
@@ -353,4 +361,4 @@ namespace SabreTools.Matching
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,4 @@ namespace SabreTools.Matching.Paths
|
||||
public FilePathMatch(string needle, bool matchCase = false)
|
||||
: base($"{Path.DirectorySeparatorChar}{needle}", matchCase, true) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,4 +89,4 @@ namespace SabreTools.Matching.Paths
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,4 +152,4 @@ namespace SabreTools.Matching.Paths
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Assembly Properties -->
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<NoWarn>NU1903</NoWarn>
|
||||
<Nullable>enable</Nullable>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.5.2</Version>
|
||||
<Version>1.6.0</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
Reference in New Issue
Block a user