Add monad assertions to the test project - #834
Open
Jack-Edwards wants to merge 2 commits into
Open
Conversation
Asserting on Maybe and Either meant `Assert.That(result.IsRight, Is.True)`, which reports only `Expected: True, But was: False` and reveals nothing about the state the monad was actually in. Reaching the value then took a second step through a lambda or an *OrDefault call. The new assertions report the actual state and its payload on failure, and return the matched value so a test can assert and bind in one statement. NUnit's Assert cannot be extended, so these live on a subclass of it declared in the Crypter.Test namespace. Unqualified `Assert` in a test resolves there and reaches the inherited assertions through the same name as before, which is why no existing test changed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Inside an Assert.Multiple scope, Fail records the failure and returns rather than throwing. The assertions that return a value went on to hand back a default, so a test would bind null and report a NullReferenceException in place of the failure message, and the remaining assertions in the scope never ran. There is no value to return once the state is wrong, so these now throw. IsNone and IsNeither still call Fail, so a multiple scope collects them. Adds coverage for the value-returning assertions inside a multiple scope, and for the Neither state appearing in an IsRight or IsLeft failure message. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Assert.IsSome,IsNone,IsRight,IsLeft, andIsNeitherforMaybeandEither, each with an overload taking an expected value and anAsyncvariant taking the task directly. The ones that match a value return it, so a test can assert the state and bind the value in one statement, and the failure messages name the actual state and its payload.Asserthere is a subclass of NUnit's, declared in theCrypter.Testnamespace. UnqualifiedAssertin a test now resolves to it and reaches the inherited assertions by the same name. No existing assertions were changed.The assertions that return a value throw on the wrong state rather than calling
Fail. Inside anAssert.MultiplescopeFailrecords the failure and returns, which would leave them handing back a default value for the test to bind and dereference.IsNoneandIsNeithercallFail, so a multiple scope still collects them.🤖 Generated with Claude Code