diff options
author | Louis Pilfold <louis@lpil.uk> | 2022-01-01 21:28:55 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-01-01 21:28:55 +0000 |
commit | 1348b7f94697910853e11b847f500ff868b21fd8 (patch) | |
tree | 44d5182fc9bf1f213fac680fb0a7200ea39cef4d /test | |
parent | 665e851b0d2a2fd249ac61911b6de4e2591971f9 (diff) | |
download | gleam_stdlib-1348b7f94697910853e11b847f500ff868b21fd8.tar.gz gleam_stdlib-1348b7f94697910853e11b847f500ff868b21fd8.zip |
Any on JS
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/dynamic_test.gleam | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/gleam/dynamic_test.gleam b/test/gleam/dynamic_test.gleam index 57dfdae..8529b9a 100644 --- a/test/gleam/dynamic_test.gleam +++ b/test/gleam/dynamic_test.gleam @@ -1,6 +1,7 @@ import gleam/should import gleam/dynamic.{DecodeError} import gleam/bit_string +import gleam/result import gleam/map import gleam/option.{None, Some} @@ -793,3 +794,28 @@ pub fn result_test() { |> dynamic.result(ok: dynamic.int, error: dynamic.string) |> should.equal(Error(DecodeError(expected: "Result", found: "Int"))) } + +pub fn any_test() { + let decoder = dynamic.any( + _, + [ + fn(x) { result.map(dynamic.int(x), fn(_) { "int" }) }, + fn(x) { result.map(dynamic.float(x), fn(_) { "float" }) }, + ], + ) + + 1 + |> dynamic.from + |> decoder + |> should.equal(Ok("int")) + + 1.1 + |> dynamic.from + |> decoder + |> should.equal(Ok("float")) + + "" + |> dynamic.from + |> decoder + |> should.equal(Error(DecodeError("Float or Int", "String"))) +} |