aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2020-07-15 11:38:16 +0100
committerLouis Pilfold <louis@lpil.uk>2020-07-15 11:38:16 +0100
commit36232a3920aa4aaca667d66dfbedfb2d4227a114 (patch)
treeaddf9ca942c117ab8ca9d8b1fe1532563da5dc01 /test
parent48d458d4f5785607fa236fd70e8dd773ab014699 (diff)
downloadgleam_stdlib-36232a3920aa4aaca667d66dfbedfb2d4227a114.tar.gz
gleam_stdlib-36232a3920aa4aaca667d66dfbedfb2d4227a114.zip
function.rescue
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(""))))
+}