Skip to content

Commit

Permalink
Result.TryCatch3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pizycki authored and bartsokol committed Apr 2, 2018
1 parent 9299960 commit 61fb238
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Monacs.UnitTests/ResultTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -537,5 +537,33 @@ module TryCatch2 =
let error = Errors.Error(errorMessage)
let result = Result.Error<ValueTuple<string, int>>(error)
Result.TryCatch2(result,
tryFunc = (fun _ _ -> "This should omitted."),
tryFunc = (fun _ _ -> "This should be omitted."),
errorHandler = (fun _ _ _ -> Errors.Error())) |> should equal (Result.Error<string>(error))


module TryCatch3 =

let testTuple = ("Some stringo", 101, 2.0).ToValueTuple()
let errorMessage = "Some error message."

[<Fact>]
let ``TryCatch<TValue, TFst, TSnd> returns Ok<TValue> when previous result is Ok<(TFst, TSnd)> and function call doesn't throw`` () =
let result = Result.Ok(testTuple)
Result.TryCatch3(result, (fun a b c -> (a, b, c).ToValueTuple()), (fun _ _ _ _ -> Errors.Error())) |> should equal (Result.Ok(testTuple))

[<Fact>]
let ``TryCatch<TValue, TFst, TSnd> returns Error<TValue> when previous result is Ok<TFst, TSnd> and function call throws`` () =
let message = errorMessage
let result = Result.Ok(testTuple)
Result.TryCatch3(result,
tryFunc = (fun _ _ _ -> raise(Exception(message))),
errorHandler = (fun a b c e -> Errors.Error((a, b, c).ToValueTuple().ToString() + e.Message)))
|> should equal (Result.Error(Errors.Error(testTuple.ToString() + message)))

[<Fact>]
let ``TryCatch<TValue, TFst, TSnd> returns Error<TValue> when previous result is Error<TFst, TSnd>`` () =
let error = Errors.Error(errorMessage)
let result = Result.Error<ValueTuple<string, int>>(error)
Result.TryCatch2(result,
tryFunc = (fun _ _ -> "This should be omitted."),
errorHandler = (fun _ _ _ -> Errors.Error())) |> should equal (Result.Error<string>(error))

0 comments on commit 61fb238

Please sign in to comment.