mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Move custom equality comparers to tests to increase coverage
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using CliFx.Models;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.Internal;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Models;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.Internal;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CliFx.Internal;
|
||||
using CliFx.Models;
|
||||
|
||||
namespace CliFx.Models
|
||||
namespace CliFx.Tests.Internal
|
||||
{
|
||||
public partial class CommandInputEqualityComparer : IEqualityComparer<CommandInput>
|
||||
{
|
||||
@@ -21,10 +21,7 @@ namespace CliFx.Models
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetHashCode(CommandInput obj) => new HashCodeBuilder()
|
||||
.Add(obj.CommandName, StringComparer.OrdinalIgnoreCase)
|
||||
.AddMany(obj.Options, CommandOptionInputEqualityComparer.Instance)
|
||||
.Build();
|
||||
public int GetHashCode(CommandInput obj) => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public partial class CommandInputEqualityComparer
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CliFx.Internal;
|
||||
using CliFx.Models;
|
||||
|
||||
namespace CliFx.Models
|
||||
namespace CliFx.Tests.Internal
|
||||
{
|
||||
public partial class CommandOptionInputEqualityComparer : IEqualityComparer<CommandOptionInput>
|
||||
{
|
||||
@@ -21,10 +21,7 @@ namespace CliFx.Models
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetHashCode(CommandOptionInput obj) => new HashCodeBuilder()
|
||||
.Add(obj.Alias, StringComparer.OrdinalIgnoreCase)
|
||||
.AddMany(obj.Values, StringComparer.Ordinal)
|
||||
.Build();
|
||||
public int GetHashCode(CommandOptionInput obj) => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public partial class CommandOptionInputEqualityComparer
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CliFx.Internal;
|
||||
using CliFx.Models;
|
||||
|
||||
namespace CliFx.Models
|
||||
namespace CliFx.Tests.Internal
|
||||
{
|
||||
public partial class CommandOptionSchemaEqualityComparer : IEqualityComparer<CommandOptionSchema>
|
||||
{
|
||||
@@ -23,13 +23,7 @@ namespace CliFx.Models
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetHashCode(CommandOptionSchema obj) => new HashCodeBuilder()
|
||||
.Add(obj.Property)
|
||||
.Add(obj.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.Add(obj.ShortName)
|
||||
.Add(obj.GroupName, StringComparer.OrdinalIgnoreCase)
|
||||
.Add(obj.Description, StringComparer.Ordinal)
|
||||
.Build();
|
||||
public int GetHashCode(CommandOptionSchema obj) => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public partial class CommandOptionSchemaEqualityComparer
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CliFx.Internal;
|
||||
using CliFx.Models;
|
||||
|
||||
namespace CliFx.Models
|
||||
namespace CliFx.Tests.Internal
|
||||
{
|
||||
public partial class CommandSchemaEqualityComparer : IEqualityComparer<CommandSchema>
|
||||
{
|
||||
@@ -23,12 +23,7 @@ namespace CliFx.Models
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetHashCode(CommandSchema obj) => new HashCodeBuilder()
|
||||
.Add(obj.Type)
|
||||
.Add(obj.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.Add(obj.Description, StringComparer.Ordinal)
|
||||
.AddMany(obj.Options, CommandOptionSchemaEqualityComparer.Instance)
|
||||
.Build();
|
||||
public int GetHashCode(CommandSchema obj) => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public partial class CommandSchemaEqualityComparer
|
||||
@@ -1,38 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CliFx.Internal
|
||||
{
|
||||
internal class HashCodeBuilder
|
||||
{
|
||||
private int _code = 17;
|
||||
|
||||
public HashCodeBuilder Add(int hashCode)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
_code = _code * 23 + hashCode;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public HashCodeBuilder Add(IEnumerable<int> hashCodes)
|
||||
{
|
||||
foreach (var hashCode in hashCodes)
|
||||
Add(hashCode);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public HashCodeBuilder Add<T>(T obj, IEqualityComparer<T> comparer) => Add(comparer.GetHashCode(obj));
|
||||
|
||||
public HashCodeBuilder Add<T>(T obj) => Add(obj, EqualityComparer<T>.Default);
|
||||
|
||||
public HashCodeBuilder AddMany<T>(IEnumerable<T> objs, IEqualityComparer<T> comparer) => Add(objs.Select(comparer.GetHashCode));
|
||||
|
||||
public HashCodeBuilder AddMany<T>(IEnumerable<T> objs) => AddMany(objs, EqualityComparer<T>.Default);
|
||||
|
||||
public int Build() => _code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user