From 07d4c5e55453450013a0e398b9cc85e13c27d10d Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Sun, 9 Jan 2022 22:32:31 +0000 Subject: decode takes a dynamic decoder --- test/gleam_json_test.gleam | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/gleam_json_test.gleam b/test/gleam_json_test.gleam index 7e93ab7..fb55c90 100644 --- a/test/gleam_json_test.gleam +++ b/test/gleam_json_test.gleam @@ -11,21 +11,27 @@ pub fn main() { } pub fn decode_test() { - json.decode("5") - |> result.map(dynamic.from) - |> should.equal(Ok(dynamic.from(5))) + json.decode(from: "5", using: dynamic.int) + |> should.equal(Ok(5)) } pub fn decode_empty_test() { - json.decode("") + json.decode(from: "", using: dynamic.int) |> should.equal(Error(json.UnexpectedEndOfInput)) } pub fn decode_unexpected_byte_test() { - json.decode("[}") + json.decode(from: "[}", using: dynamic.int) |> should.equal(Error(json.UnexpectedByte("0x7D", 1))) } +pub fn decode_unexpected_format_test() { + json.decode(from: "[]", using: dynamic.int) + |> should.equal(Error(json.UnexpectedFormat([ + dynamic.DecodeError(expected: "Int", found: "List", path: []), + ]))) +} + pub fn encode_string_test() { json.string("hello") |> should_encode("\"hello\"") -- cgit v1.2.3