Skip to content

Commit

Permalink
Merge pull request #31 from pfpack/release/v3.0.2-rc.1
Browse files Browse the repository at this point in the history
release/v3.0.2-rc.1
  • Loading branch information
andreise authored Jan 6, 2025
2 parents 240ec32 + 98f1ff3 commit 9357a91
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 67 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2024 Andrei Sergeev, Pavel Moskovoy
Copyright (c) 2020-2025 Andrei Sergeev, Pavel Moskovoy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions src/core-unit/Unit.Tests.Old/Unit.Tests.Old.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Authors>Andrei Sergeev, Pavel Moskovoy</Authors>
<Copyright>Copyright © 2020-2024 Andrei Sergeev, Pavel Moskovoy</Copyright>
<Copyright>Copyright © 2020-2025 Andrei Sergeev, Pavel Moskovoy</Copyright>
<RootNamespace>PrimeFuncPack.Core.Tests</RootNamespace>
<AssemblyName>PrimeFuncPack.Core.Unit.Tests.Old</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.3.1" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;

partial class UnitTests
{
[Obsolete]
[Test]
public void CompareTo_Obj_Unit_ExpectZero()
{
object? obj = default(Unit);

var actual = Unit.Value.CompareTo(obj);
Assert.That(actual, Is.Zero);
}

[Obsolete]
[Test]
public void CompareTo_Obj_Null_ExpectGreaterThanZero_ExpectOne()
{
object? obj = null;

var actual = Unit.Value.CompareTo(obj);

Assert.That(actual, Is.Positive);
Assert.That(actual, Is.EqualTo(1));
}

[Obsolete]
[Test]
[TestCaseSource(nameof(CompareTo_Obj_NotUnit_ExpectArgumentException_TestCases))]
public void CompareTo_Obj_NotUnit_ExpectArgumentException(object obj)
{
var ex = Assert.Throws<ArgumentException>(() => _ = Unit.Value.CompareTo(obj))!;

Assert.That(ex.ParamName, Is.EqualTo("obj"));

var containsExpectedMessage = ex.Message.Contains("Object must be of type Unit.", StringComparison.Ordinal);
Assert.That(containsExpectedMessage, Is.True);
}

private static IEnumerable<object> CompareTo_Obj_NotUnit_ExpectArgumentException_TestCases()
{
yield return new object();
yield return PlusFifteen;
yield return PlusFifteenIdRefType;
yield return SomeTextStructType;
yield return Array.Empty<Unit>();
}
}
41 changes: 0 additions & 41 deletions src/core-unit/Unit.Tests.Old/UnitTests/UnitTests.Comparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,6 @@ public void CompareTo_Typed_ExpectZero()
Assert.That(actual, Is.Zero);
}

[Test]
public void CompareTo_Obj_Unit_ExpectZero()
{
object? obj = default(Unit);

var actual = Unit.Value.CompareTo(obj);
Assert.That(actual, Is.Zero);
}

[Test]
public void CompareTo_Obj_Null_ExpectGreaterThanZero_ExpectOne()
{
object? obj = null;

var actual = Unit.Value.CompareTo(obj);

Assert.That(actual, Is.Positive);
Assert.That(actual, Is.EqualTo(1));
}

[Test]
[TestCaseSource(nameof(CompareTo_Obj_NotUnit_ExpectArgumentException_TestCases))]
public void CompareTo_Obj_NotUnit_ExpectArgumentException(object obj)
{
var ex = Assert.Throws<ArgumentException>(() => _ = Unit.Value.CompareTo(obj))!;

Assert.That(ex.ParamName, Is.EqualTo("obj"));

var containsExpectedMessage = ex.Message.Contains("The object is not Unit.", StringComparison.Ordinal);
Assert.That(containsExpectedMessage, Is.True);
}

[Test]
public void Compare_Static_ExpectZero()
{
Expand Down Expand Up @@ -96,13 +64,4 @@ public void Compare_Operator_GreaterThan_ExpectFalse()
var actual = left > right;
Assert.That(actual, Is.False);
}

private static IEnumerable<object> CompareTo_Obj_NotUnit_ExpectArgumentException_TestCases()
{
yield return new object();
yield return PlusFifteen;
yield return PlusFifteenIdRefType;
yield return SomeTextStructType;
yield return Array.Empty<Unit>();
}
}
4 changes: 2 additions & 2 deletions src/core-unit/Unit.Tests/Unit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Authors>Andrei Sergeev, Pavel Moskovoy</Authors>
<Copyright>Copyright © 2020-2024 Andrei Sergeev, Pavel Moskovoy</Copyright>
<Copyright>Copyright © 2020-2025 Andrei Sergeev, Pavel Moskovoy</Copyright>
<RootNamespace>PrimeFuncPack.Core.Tests</RootNamespace>
<AssemblyName>PrimeFuncPack.Core.Unit.Tests</AssemblyName>
</PropertyGroup>
Expand All @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/core-unit/Unit/Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<RepositoryUrl>https://github.com/pfpack/pfpack-core-unit</RepositoryUrl>
<Company>pfpack</Company>
<Authors>Andrei Sergeev, Pavel Moskovoy</Authors>
<Copyright>Copyright © 2020-2024 Andrei Sergeev, Pavel Moskovoy</Copyright>
<Copyright>Copyright © 2020-2025 Andrei Sergeev, Pavel Moskovoy</Copyright>
<Description>PrimeFuncPack Core.Unit is a core library for .NET consisting of Unit type targeted for use in functional programming.</Description>
<RootNamespace>System</RootNamespace>
<AssemblyName>PrimeFuncPack.Core.Unit</AssemblyName>
<Version>3.0.1</Version>
<Version>3.0.2-rc.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/core-unit/Unit/Unit/Unit.Comparison.Obsolete.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace System;

// TODO: Remove Nongeneric IComparable declaration/implementation in v4.0
partial struct Unit : IComparable
{
[Obsolete("This method is obsolete. Call CompareTo(Unit) instead.")]
public int CompareTo(object? obj) => obj switch
{
null => 1,
Unit => default,
_ => throw new ArgumentException($"Object must be of type {nameof(Unit)}.", nameof(obj))
};
}
9 changes: 0 additions & 9 deletions src/core-unit/Unit/Unit/Unit.Comparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,4 @@
partial struct Unit
{
public int CompareTo(Unit other) => default;

public int CompareTo(object? obj) => obj switch
{
null => 1,

Unit => default,

_ => throw new ArgumentException("The object is not Unit.", nameof(obj))
};
}
2 changes: 1 addition & 1 deletion src/core-unit/Unit/Unit/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
namespace System;

[JsonConverter(typeof(UnitJsonConverter))]
public readonly partial struct Unit : IEquatable<Unit>, IComparable<Unit>, IComparable
public readonly partial struct Unit : IEquatable<Unit>, IComparable<Unit>
{
}
11 changes: 3 additions & 8 deletions src/core-unit/Unit/UnitJsonConverter/UnitJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@ public override Unit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSer
{
switch (reader.TokenType)
{
case JsonTokenType.StartObject:
case JsonTokenType.StartArray:
case JsonTokenType.StartObject or JsonTokenType.StartArray:
reader.Skip();
return default;

case JsonTokenType.String:
case JsonTokenType.Number:
case JsonTokenType.True:
case JsonTokenType.False:
case JsonTokenType.Null:
case JsonTokenType.String or JsonTokenType.Number or JsonTokenType.True or JsonTokenType.False or JsonTokenType.Null:
return default;

case var unexpected:
throw new JsonException($"An unexpected JSON token type ({unexpected}).");
};
}
}

public override void Write(Utf8JsonWriter writer, Unit value, JsonSerializerOptions options)
Expand Down

0 comments on commit 9357a91

Please sign in to comment.