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
2 changes: 1 addition & 1 deletion src/GuardCore/Guard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore;
namespace Takayama.GuardCore;

public static class Guard
{
Expand Down
4 changes: 2 additions & 2 deletions src/GuardCore/GuardCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0;net9.0;net10.0</TargetFrameworks>
<RootNamespace>GuardCore</RootNamespace>
<AssemblyName>GuardCore</AssemblyName>
<RootNamespace>Takayama.GuardCore</RootNamespace>
<AssemblyName>Takayama.GuardCore</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- 1701/1702: Summary references, 0436: PolySharp source conflicts, 9124: Ref struct checks -->
Expand Down
2 changes: 1 addition & 1 deletion src/GuardCore/Result.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore;
namespace Takayama.GuardCore;

public readonly struct Result<TValue, TError> where TError : Enum
{
Expand Down
2 changes: 1 addition & 1 deletion src/GuardCore/ResultExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore;
namespace Takayama.GuardCore;

/// <summary>
/// Transforms the inner error type if the result is a failure.
Expand Down
2 changes: 1 addition & 1 deletion src/GuardCore/Unit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore
namespace Takayama.GuardCore
{
/// <summary>
/// Represents a type with only one value.
Expand Down
4 changes: 2 additions & 2 deletions tests/GuardCore.Tests/EnsureTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore.Tests;
namespace Takayama.GuardCore.Tests;

public class EnsureTests
{
Expand Down Expand Up @@ -31,4 +31,4 @@ public void Ensure_WhenConditionPasses_ShouldNotThrow()
{
Should.NotThrow(() => Guard.Ensure(true, "This should never throw"));
}
}
}
2 changes: 1 addition & 1 deletion tests/GuardCore.Tests/GuardCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<ItemGroup>
<Using Include="Xunit" />
<Using Include="Shouldly" />
<Using Include="GuardCore" />
<Using Include="Takayama.GuardCore" />
<Using Include="System.Runtime.CompilerServices" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions tests/GuardCore.Tests/GuardStateLogicTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore.Tests;
namespace Takayama.GuardCore.Tests;

public class GuardStateLogicTests
{
Expand Down Expand Up @@ -48,4 +48,4 @@ public void Deconstruct_ShouldUnpackInternalStateFieldsCorrectly()
isSuccess.ShouldBeFalse();
error.ShouldBe(TestError.InvalidId);
}
}
}
4 changes: 2 additions & 2 deletions tests/GuardCore.Tests/GuardStateTerminalTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore.Tests;
namespace Takayama.GuardCore.Tests;

public class GuardStateTerminalTests
{
Expand Down Expand Up @@ -59,4 +59,4 @@ public void ToResult_WhenSuccess_ShouldReturnUnitSuccessResult()
result.IsSuccess.ShouldBeTrue();
result.Value.ShouldBe(Unit.Default);
}
}
}
8 changes: 4 additions & 4 deletions tests/GuardCore.Tests/ResultExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore.Tests;
namespace Takayama.GuardCore.Tests;

public class ResultExtensionsTests
{
Expand All @@ -7,8 +7,8 @@ public void MapError_WhenResultIsFailure_ShouldTransformErrorTypeNatively()
{
Result<string, TestError> failureResult = TestError.ValueTooHigh;
Result<string, AlternateError> transformed = failureResult.MapError(err =>
err == TestError.ValueTooHigh
? AlternateError.TranslatedFault
err == TestError.ValueTooHigh
? AlternateError.TranslatedFault
: AlternateError.None);

transformed.Failed.ShouldBeTrue();
Expand All @@ -24,4 +24,4 @@ public void MapError_WhenResultIsSuccess_ShouldForwardValueUnchanged()
transformed.IsSuccess.ShouldBeTrue();
transformed.Value.ShouldBe("PreserveMe");
}
}
}
14 changes: 7 additions & 7 deletions tests/GuardCore.Tests/ResultTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore.Tests;
namespace Takayama.GuardCore.Tests;

public enum AlternateError
{
Expand Down Expand Up @@ -31,7 +31,7 @@ public void ImplicitConversion_FromValue_ShouldCreateValidSuccessResult()
result.IsSuccess.ShouldBeTrue();
result.Failed.ShouldBeFalse();
result.Value.ShouldBe("SystemNormalized");

Should.Throw<InvalidOperationException>(() => { var _ = result.Error; })
.Message.ShouldBe("Cannot access Error of a successful Result container.");
}
Expand Down Expand Up @@ -66,15 +66,15 @@ public void Map_WhenSuccess_ShouldTransformInnerValueTypeNatively()
mapped.IsSuccess.ShouldBeTrue();
mapped.Value.ShouldBe(100);
}

[Fact]
public void Bind_WhenSuccess_ShouldChainMonadicOperationsWithoutAllocating()
{
Result<string, TestError> initial = "100";

var bound = initial.Bind(val =>
int.TryParse(val, out int cleanInt)
? new Result<int, TestError>(cleanInt)
var bound = initial.Bind(val =>
int.TryParse(val, out int cleanInt)
? new Result<int, TestError>(cleanInt)
: new Result<int, TestError>(TestError.FallbackError));

bound.IsSuccess.ShouldBeTrue();
Expand Down Expand Up @@ -104,4 +104,4 @@ public void Deconstruct_ShouldUnpackInternalStateNatively()
isSuccess.ShouldBeTrue();
value.ShouldBe("DataStream");
}
}
}
4 changes: 2 additions & 2 deletions tests/GuardCore.Tests/TestError.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore.Tests;
namespace Takayama.GuardCore.Tests;

public enum TestError
{
Expand All @@ -7,4 +7,4 @@ public enum TestError
ValueTooLow,
ValueTooHigh,
FallbackError
}
}
4 changes: 2 additions & 2 deletions tests/GuardCore.Tests/UniTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GuardCore.Tests;
namespace Takayama.GuardCore.Tests;

public class UnitTests
{
Expand All @@ -15,4 +15,4 @@ public void UnitDefault_ShouldAlwaysBeEqualAndReturnExpectedString()
unit1.ToString().ShouldBe("()");
unit1.CompareTo(unit2).ShouldBe(0);
}
}
}
Loading