Skip to content

Commit

Permalink
implemen test for reifying an Exception using Result
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubSchwenkbeck committed Jan 14, 2025
1 parent e67cad8 commit 93b6225
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/stdlib/exception/combinators.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ Error: Invalid index (-1)
hello
Test: Finalizer
hello
Test: Finalizer
Test: Finalizer
Error: Invalid index (0)
Success: hello
13 changes: 13 additions & 0 deletions examples/stdlib/exception/combinators.effekt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module examples/pos/exception/combinators

import exception
import result

/**
* Used as a type for `Exception` purely for independent testing
Expand Down Expand Up @@ -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

}

0 comments on commit 93b6225

Please sign in to comment.