From 93b6225d85478b0a5bc42cdd7dc379e40af422b7 Mon Sep 17 00:00:00 2001 From: Jakub Date: Tue, 14 Jan 2025 23:59:25 +0100 Subject: [PATCH] implemen test for `reifying` an Exception using `Result` --- examples/stdlib/exception/combinators.check | 4 +++- examples/stdlib/exception/combinators.effekt | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/stdlib/exception/combinators.check b/examples/stdlib/exception/combinators.check index 4a6d49331..41969b94c 100644 --- a/examples/stdlib/exception/combinators.check +++ b/examples/stdlib/exception/combinators.check @@ -6,4 +6,6 @@ Error: Invalid index (-1) hello Test: Finalizer hello -Test: Finalizer \ No newline at end of file +Test: Finalizer +Error: Invalid index (0) +Success: hello \ No newline at end of file diff --git a/examples/stdlib/exception/combinators.effekt b/examples/stdlib/exception/combinators.effekt index 4c578c4d8..8d8e3ca56 100644 --- a/examples/stdlib/exception/combinators.effekt +++ b/examples/stdlib/exception/combinators.effekt @@ -1,6 +1,7 @@ module examples/pos/exception/combinators import exception +import result /** * Used as a type for `Exception` purely for independent testing @@ -59,4 +60,16 @@ def main() = { finalizeTestException { str.generalOperation(0) } // Test: Finalizer finalizeTestException { str.generalOperation(1) } // Test: Finalizer hello + // Test for "reifying" an Exception using Result + def resultTestException { p: => String / Exception[TestException] }: Unit = { + val res= result[String, TestException](on[TestException]) { p() } + res match { + case Success(msg) => println("Success: " ++ msg) + case Error(exc, msg) => println(msg) + } + } + + resultTestException { str.generalOperation(0) } // Error: Invalid index (0) + resultTestException { str.generalOperation(1) } // Success: hello + } \ No newline at end of file