aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/gleam/function_test.gleam18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/gleam/function_test.gleam b/test/gleam/function_test.gleam
index eb94581..f5d34a9 100644
--- a/test/gleam/function_test.gleam
+++ b/test/gleam/function_test.gleam
@@ -1,4 +1,5 @@
import gleam/should
+import gleam/dynamic
import gleam/function
import gleam/int
import gleam/list
@@ -65,3 +66,20 @@ pub fn identity_test() {
|> function.identity
|> should.equal(tuple(1, 2.0))
}
+
+external fn throw(a) -> Nil =
+ "erlang" "throw"
+
+external fn raise_error(a) -> Nil =
+ "erlang" "error"
+
+pub fn rescue_test() {
+ function.rescue(fn() { 1 })
+ |> should.equal(Ok(1))
+
+ function.rescue(fn() { throw(1) })
+ |> should.equal(Error(function.Thrown(dynamic.from(1))))
+
+ function.rescue(fn() { raise_error("") })
+ |> should.equal(Error(function.Errored(dynamic.from(""))))
+}