Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/KubeOps.Cli/Transpilation/TargetFrameworkComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace KubeOps.Cli.Transpilation;
internal sealed partial class TargetFrameworkComparer : IComparer<string>
{
[GeneratedRegex(
"[(]?(?<tfm>(?<n>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
"[(]?(?<tfm>(?<platform>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
RegexOptions.Compiled)]
public static partial Regex TfmRegex();

Expand All @@ -28,8 +28,8 @@ public int Compare(string? x, string? y)
case ({ Success: false }, _) or (_, { Success: false }):
return StringComparer.CurrentCulture.Compare(x, y);
case ({ } matchX, { } matchY):
var platformX = matchX.Groups["name"].Value;
var platformY = matchY.Groups["name"].Value;
var platformX = matchX.Groups["platform"].Value;
var platformY = matchY.Groups["platform"].Value;
if (platformX != platformY)
{
return (platformX, platformY) switch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using FluentAssertions;

using KubeOps.Cli.Transpilation;

namespace KubeOps.Cli.Test.Transpilation;

[Trait(TestTrait.Category, TestCategory.UnitTest)]
[Trait(TestTrait.Area, TestArea.Cli)]
public sealed class TargetFrameworkComparerTest
{
[Theory]
[InlineData("netstandard2.1", "netcoreapp2.1")]
[InlineData("netcoreapp5.0", "net5.0")]
[InlineData("netstandard2.1", "net2.1")]
[InlineData("net8.0", "net10.0")]
[InlineData("net10.0", "net10.1")]
public void Compare_Orders_The_Older_Target_Framework_First(string older, string newer)
{
var comparer = new TargetFrameworkComparer();

comparer.Compare(older, newer).Should().BeNegative();
comparer.Compare(newer, older).Should().BePositive();
}

[Fact]
public void Compare_Treats_Equal_Target_Frameworks_As_Equal()
{
new TargetFrameworkComparer().Compare("net10.0", "net10.0").Should().Be(0);
}
}