-
-
Save bleis-tift/a7a78d8122b99c083f1a to your computer and use it in GitHub Desktop.
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
type NonEmptyList<'T> = 'T * 'T list | |
type AssertResult<'T> = | |
| Failure of NonEmptyList<string> | |
| Success of 'T | |
type TestBuilder(description: string) = | |
// これを解除するとコンパイルエラーになってしまう・・・ | |
// member __.Bind(x, f) = | |
// match x with | |
// | Success res -> f res | |
// | Failure res -> Failure res | |
member __.Bind(x, f) = | |
match x with | |
| Success () -> f () | |
| Failure (res1, rest1) -> | |
match f () with | |
| Success _ -> Failure (res1, rest1) | |
| Failure (res2, rest2) -> | |
Failure (res1, rest1@(res2::rest2)) | |
member __.Return x = Success x | |
member __.Zero () = Success () | |
let assertEquals x y = | |
if x = y then Success () | |
else Failure (sprintf "Expect: %A\nActual: %A" x y, []) | |
let test description = TestBuilder(description) | |
test "hogehoge" { | |
do! assertEquals 1 2 | |
do! assertEquals 2 3 | |
do! assertEquals 2 2 | |
do! assertEquals 3 4 | |
} | |
(* => val it : AssertResult<unit> = | |
Failure | |
("Expect: 1 | |
Actual: 2", ["Expect: 2 | |
Actual: 3"; "Expect: 3 | |
Actual: 4"]) *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BindじゃなくてCombineに頼る方向性のほうがやっぱりいいのかも?