aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2022-01-09 17:51:28 +0000
committerLouis Pilfold <louis@lpil.uk>2022-01-09 17:51:28 +0000
commit3ea1726ae5040af3c67bd3dc8c1b6718c69ff67b (patch)
tree65b457a4f99887a5d74c5ac0e380ffbc4690f00d /test
parentd331545082e3cdaab501142facf56ac5a16ee745 (diff)
downloadgleam_stdlib-3ea1726ae5040af3c67bd3dc8c1b6718c69ff67b.tar.gz
gleam_stdlib-3ea1726ae5040af3c67bd3dc8c1b6718c69ff67b.zip
decode4
Diffstat (limited to 'test')
-rw-r--r--test/gleam/dynamic_test.gleam28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/gleam/dynamic_test.gleam b/test/gleam/dynamic_test.gleam
index 45704bc..245d894 100644
--- a/test/gleam/dynamic_test.gleam
+++ b/test/gleam/dynamic_test.gleam
@@ -838,3 +838,31 @@ pub fn decode3_test() {
DecodeError(expected: "String", found: "Float", path: ["1"]),
]))
}
+
+type Four(a, b, c, d) {
+ Four(a, b, c, d)
+}
+
+pub fn decode4_test() {
+ let decoder =
+ dynamic.decode4(
+ Four,
+ dynamic.element(0, dynamic.int),
+ dynamic.element(1, dynamic.string),
+ dynamic.element(2, dynamic.int),
+ dynamic.element(3, dynamic.int),
+ )
+
+ #(1, "2", 3, 4)
+ |> dynamic.from
+ |> decoder
+ |> should.equal(Ok(Four(1, "2", 3, 4)))
+
+ #(1.3, 2.1, 3, 4)
+ |> dynamic.from
+ |> decoder
+ |> should.equal(Error([
+ DecodeError(expected: "Int", found: "Float", path: ["0"]),
+ DecodeError(expected: "String", found: "Float", path: ["1"]),
+ ]))
+}