aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRobert Attard <robert.attard@mail.mcgill.ca>2022-01-09 13:17:37 -0500
committerGitHub <noreply@github.com>2022-01-09 18:17:37 +0000
commitc6f14db8fd21f66be20f3ef027df0d4dc5806bdb (patch)
treef702b447429da1acaa413a57a658ef983f644cbe /test
parent1d9085ea75c850ef270e1bec56c4d74721c6e9a0 (diff)
downloadgleam_stdlib-c6f14db8fd21f66be20f3ef027df0d4dc5806bdb.tar.gz
gleam_stdlib-c6f14db8fd21f66be20f3ef027df0d4dc5806bdb.zip
option.lazy_unwrap and option.lazy_or (#261)
Diffstat (limited to 'test')
-rw-r--r--test/gleam/option_test.gleam26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/gleam/option_test.gleam b/test/gleam/option_test.gleam
index 35c9eb3..36a40f7 100644
--- a/test/gleam/option_test.gleam
+++ b/test/gleam/option_test.gleam
@@ -49,6 +49,14 @@ pub fn unwrap_option_test() {
|> should.equal(0)
}
+pub fn lazy_unwrap_option_test() {
+ option.lazy_unwrap(Some(1), fn() { 0 })
+ |> should.equal(1)
+
+ option.lazy_unwrap(None, fn() { 0 })
+ |> should.equal(0)
+}
+
pub fn map_option_test() {
Some(1)
|> option.map(fn(x) { x + 1 })
@@ -109,6 +117,24 @@ pub fn or_option_test() {
|> should.equal(None)
}
+pub fn lazy_or_option_test() {
+ Some(1)
+ |> option.lazy_or(fn() { Some(2) })
+ |> should.equal(Some(1))
+
+ Some(1)
+ |> option.lazy_or(fn() { None })
+ |> should.equal(Some(1))
+
+ None
+ |> option.lazy_or(fn() { Some(2) })
+ |> should.equal(Some(2))
+
+ None
+ |> option.lazy_or(fn() { None })
+ |> should.equal(None)
+}
+
pub fn values_test() {
option.values([Some(1), None, Some(3)])
|> should.equal([1, 3])