aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRJ Dellecese <rjdellecese@gmail.com>2019-12-18 22:04:16 -0500
committerLouis Pilfold <louis@lpil.uk>2019-12-19 10:35:55 +0000
commitdd7dd9b1df1c77a62c49ca6e2620f6757b5b0734 (patch)
treee519bb3fd5573c0bd067d1f7c62c407fee8a37bd /test
parent2be45a710cb7332cf3c9a16d251c97561f88109c (diff)
downloadgleam_stdlib-dd7dd9b1df1c77a62c49ca6e2620f6757b5b0734.tar.gz
gleam_stdlib-dd7dd9b1df1c77a62c49ca6e2620f6757b5b0734.zip
Add dynamic.element for decoding tuples
Diffstat (limited to 'test')
-rw-r--r--test/gleam/dynamic_test.gleam37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/gleam/dynamic_test.gleam b/test/gleam/dynamic_test.gleam
index f840ce8..96db8c1 100644
--- a/test/gleam/dynamic_test.gleam
+++ b/test/gleam/dynamic_test.gleam
@@ -221,3 +221,40 @@ pub fn field_test() {
|> dynamic.field(_, [])
|> expect.is_error
}
+
+pub fn element_test() {
+ let Ok(ok_atom) = atom.from_string("ok")
+ let Ok(error_atom) = atom.from_string("ok")
+ let ok_one_struct = struct(ok_atom, 1)
+
+ ok_one_struct
+ |> dynamic.from
+ |> dynamic.element(_, 0)
+ |> expect.equal(_, Ok(dynamic.from(ok_atom)))
+
+ ok_one_struct
+ |> dynamic.from
+ |> dynamic.element(_, 1)
+ |> expect.equal(_, Ok(dynamic.from(1)))
+
+ ok_one_struct
+ |> dynamic.from
+ |> dynamic.element(_, 2)
+ |> expect.is_error
+
+ ok_one_struct
+ |> dynamic.from
+ |> dynamic.element(_, -1)
+ |> expect.is_error
+
+ 1
+ |> dynamic.from
+ |> dynamic.element(_, 0)
+ |> expect.is_error
+
+ map.new()
+ |> map.insert(_, 1, ok_atom)
+ |> dynamic.from
+ |> dynamic.element(_, 0)
+ |> expect.is_error
+}