aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2022-01-09 22:32:31 +0000
committerLouis Pilfold <louis@lpil.uk>2022-01-09 22:32:31 +0000
commit07d4c5e55453450013a0e398b9cc85e13c27d10d (patch)
tree79e309880b1620d6525fed29bdc0c1f876f0c262 /test
parent850d26eaaf1c3de9bed14b249b406b19e3b437a4 (diff)
downloadgleam_json-07d4c5e55453450013a0e398b9cc85e13c27d10d.tar.gz
gleam_json-07d4c5e55453450013a0e398b9cc85e13c27d10d.zip
decode takes a dynamic decoder
Diffstat (limited to 'test')
-rw-r--r--test/gleam_json_test.gleam16
1 files changed, 11 insertions, 5 deletions
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\"")