-
Notifications
You must be signed in to change notification settings - Fork 32
Both Result and Choice for error handling #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wallymathieu
wants to merge
13
commits into
jack-pappas:master
Choose a base branch
from
wallymathieu:using_result_and_choice_for_errors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
145e437
First take on dual Result and Choice version of ExtCore
wallymathieu 1b0028c
Renaming Notification.Error to Notification.Exception
wallymathieu 4a17699
Using same sort of test for FoldBack as can be found for Fold
wallymathieu 4163435
Moving ProtectedState with Choice into Compability
wallymathieu c8caf70
Moved conflicting Choice to Compatibility
wallymathieu 57b6c51
Cleanup: Accidentally duplicated more than intended
wallymathieu 85110bb
Moved Choice methods to Compatibility namespace
wallymathieu b646aa3
Compilation due to Choice moved to Compatibility
wallymathieu 30888d3
Merge branch 'master' into using_result_and_choice_for_errors
wallymathieu 90c3fbe
Adding comment to result continuation func
wallymathieu aece156
Reverting change to get smaller diff
wallymathieu 006bdcf
Normalising cmd pack with rest of cmd in appveyor yml
wallymathieu 2a83652
Merge remote-tracking branch 'origin/master' into using_result_and_ch…
wallymathieu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| (* | ||
|
|
||
| Copyright 2013 Jack Pappas | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| *) | ||
|
|
||
| namespace Tests.ExtCore.Control.Compatibility | ||
|
|
||
| open System | ||
| open System.Runtime.CompilerServices | ||
| open ExtCore.Control | ||
| open ExtCore.Compatibility | ||
| open ExtCore.Control.Compatibility | ||
| open NUnit.Framework | ||
|
|
||
| /// Test fixture which tests that the .Using() member of AsyncChoiceBuilder | ||
| /// disposes the supplied resource at the correct point in the program's execution. | ||
| [<TestFixture; Sealed>] | ||
| type AsyncChoiceBuilderDisposeFixture() = | ||
| let disposed = StrongBox (false) | ||
|
|
||
| let createDisposable (disposed : StrongBox<bool>) = | ||
| { new IDisposable with | ||
| member __.Dispose () = | ||
| printfn "disposing!" | ||
| disposed.Value <- true } | ||
|
|
||
| let createAsyncChoiceDisposable() = | ||
| async { return Choice1Of2(createDisposable disposed) } | ||
|
|
||
| let waitAsyncChoice() = | ||
| asyncChoice { | ||
| printfn "waiting" | ||
| } | ||
|
|
||
| let shouldNotBeDisposed() = | ||
| printfn "Should not be disposed. Checking..." | ||
| Assert.IsFalse(disposed.Value) | ||
|
|
||
| let createAsyncDisposable() = async { return (createDisposable disposed) } | ||
|
|
||
| let waitAsync() = | ||
| async { | ||
| printfn "waiting" | ||
| } | ||
|
|
||
| [<SetUp>] | ||
| member __.Setup () : unit = | ||
| disposed.Value <- false | ||
|
|
||
| [<TearDown>] | ||
| member __.Teardown () : unit = | ||
| printfn "Should be disposed. Checking..." | ||
| Assert.IsTrue(disposed.Value) | ||
|
|
||
| // asyncChoice wrong behavior | ||
| [<Test>] | ||
| member __.UsingAsyncChoice() : unit = | ||
| asyncChoice { | ||
| use! d = createAsyncChoiceDisposable() | ||
| shouldNotBeDisposed() | ||
| let! a = waitAsyncChoice() | ||
| shouldNotBeDisposed() | ||
| } | ||
| |> Async.RunSynchronously | ||
| |> Choice.get | ||
| |> ignore | ||
|
|
||
| // async - expected behavior | ||
| [<Test>] | ||
| member __.UsingAsync() : unit = | ||
| async { | ||
| use! d = createAsyncDisposable() | ||
| shouldNotBeDisposed() | ||
| do! waitAsync() | ||
| shouldNotBeDisposed() | ||
| } | ||
| |> Async.RunSynchronously | ||
| |> ignore | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Tests for <see cref="ExtCore.Control.ChoiceBuilder"/>. | ||
| /// </summary> | ||
| module ChoiceBuilder = | ||
| /// <summary>Tests for <see cref="ExtCore.Control.ChoiceBuilder.For"/>.</summary> | ||
| module ``ChoiceBuilder_For`` = | ||
| [<Test>] | ||
| let ``simple test`` () : unit = | ||
| let count = ref 0 | ||
| let data = [| 1..3 |] | ||
| let result = choice { | ||
| for i in data do | ||
| incr count | ||
| return true | ||
| } | ||
|
|
||
| // Check the loop iteration count is correct. | ||
| assertEqual 3 !count | ||
|
|
||
| // Check the result of the computation. | ||
| assertEqual (Choice1Of2 true) result | ||
|
|
||
| /// <summary>Tests for <see cref="ExtCore.Control.ChoiceBuilder.While"/>.</summary> | ||
| module ``ChoiceBuilder_While`` = | ||
| [<Test>] | ||
| let ``simple test`` () : unit = | ||
| let count = ref 0 | ||
| let data = [| 1..3 |] | ||
| let result = choice { | ||
| while !count < 3 do | ||
| incr count | ||
| return true | ||
| } | ||
|
|
||
| // Check the loop iteration count is correct. | ||
| assertEqual 3 !count | ||
|
|
||
| // Check the result of the computation. | ||
| assertEqual (Choice1Of2 true) result | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| (* | ||
|
|
||
| Copyright 2013 Jack Pappas | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| *) | ||
|
|
||
| namespace Tests.ExtCore.Control | ||
|
|
||
| open System | ||
| open System.Runtime.CompilerServices | ||
| open ExtCore.Control | ||
| open NUnit.Framework | ||
|
|
||
|
|
||
| /// Test fixture which tests that the .Using() member of AsyncResultBuilder | ||
| /// disposes the supplied resource at the correct point in the program's execution. | ||
| [<TestFixture; Sealed>] | ||
| type AsyncResultBuilderDisposeFixture() = | ||
| let disposed = StrongBox (false) | ||
|
|
||
| let createDisposable (disposed : StrongBox<bool>) = | ||
| { new IDisposable with | ||
| member __.Dispose () = | ||
| printfn "disposing!" | ||
| disposed.Value <- true } | ||
|
|
||
| let createAsyncResultDisposable() = | ||
| async { return Ok(createDisposable disposed) } | ||
|
|
||
| let waitAsyncResult() = | ||
| asyncResult { | ||
| printfn "waiting" | ||
| } | ||
|
|
||
| let shouldNotBeDisposed() = | ||
| printfn "Should not be disposed. Checking..." | ||
| Assert.IsFalse(disposed.Value) | ||
|
|
||
| let createAsyncDisposable() = async { return (createDisposable disposed) } | ||
|
|
||
| let waitAsync() = | ||
| async { | ||
| printfn "waiting" | ||
| } | ||
|
|
||
| [<SetUp>] | ||
| member __.Setup () : unit = | ||
| disposed.Value <- false | ||
|
|
||
| [<TearDown>] | ||
| member __.Teardown () : unit = | ||
| printfn "Should be disposed. Checking..." | ||
| Assert.IsTrue(disposed.Value) | ||
|
|
||
| // asyncResult wrong behavior | ||
| [<Test>] | ||
| member __.UsingAsyncChoice() : unit = | ||
| asyncResult { | ||
| use! d = createAsyncResultDisposable() | ||
| shouldNotBeDisposed() | ||
| let! a = waitAsyncResult() | ||
| shouldNotBeDisposed() | ||
| } | ||
| |> Async.RunSynchronously | ||
| |> Result.get | ||
| |> ignore | ||
|
|
||
| // async - expected behavior | ||
| [<Test>] | ||
| member __.UsingAsync() : unit = | ||
| async { | ||
| use! d = createAsyncDisposable() | ||
| shouldNotBeDisposed() | ||
| do! waitAsync() | ||
| shouldNotBeDisposed() | ||
| } | ||
| |> Async.RunSynchronously | ||
| |> ignore | ||
|
|
||
| /// <summary> | ||
| /// Tests for <see cref="ExtCore.Control.ResultBuilder"/>. | ||
| /// </summary> | ||
| module ResultBuilder = | ||
| /// <summary>Tests for <see cref="ExtCore.Control.ResultBuilder.For"/>.</summary> | ||
| module ``ResultBuilder_For`` = | ||
| [<Test>] | ||
| let ``simple test`` () : unit = | ||
| let count = ref 0 | ||
| let data = [| 1..3 |] | ||
| let result = result { | ||
| for i in data do | ||
| incr count | ||
| return true | ||
| } | ||
|
|
||
| // Check the loop iteration count is correct. | ||
| assertEqual 3 !count | ||
|
|
||
| // Check the result of the computation. | ||
| assertEqual (Ok true) result | ||
|
|
||
| /// <summary>Tests for <see cref="ExtCore.Control.ResultBuilder.While"/>.</summary> | ||
| module ``ResultBuilder_While`` = | ||
| [<Test>] | ||
| let ``simple test`` () : unit = | ||
| let count = ref 0 | ||
| let data = [| 1..3 |] | ||
| let result = result { | ||
| while !count < 3 do | ||
| incr count | ||
| return true | ||
| } | ||
|
|
||
| // Check the loop iteration count is correct. | ||
| assertEqual 3 !count | ||
|
|
||
| // Check the result of the computation. | ||
| assertEqual (Ok true) result | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
<summary>tag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bit extra, that's why?