diff options
author | Peter <peterhsaxton@gmail.com> | 2020-07-30 09:38:23 +0100 |
---|---|---|
committer | Peter <peterhsaxton@gmail.com> | 2020-07-30 09:38:23 +0100 |
commit | aeb7f383ef34c4be6036a25d2ae7d676f416233b (patch) | |
tree | fe758b208d06b372021d2da7dd040ca33ff355f7 /test | |
parent | ec9652394fc2c394b1dac2dd0d82a1b1457cea7c (diff) | |
download | gleam_json-aeb7f383ef34c4be6036a25d2ae7d676f416233b.tar.gz gleam_json-aeb7f383ef34c4be6036a25d2ae7d676f416233b.zip |
add encoding test
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/json_test.gleam | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/gleam/json_test.gleam b/test/gleam/json_test.gleam index 84f0352..25228bb 100644 --- a/test/gleam/json_test.gleam +++ b/test/gleam/json_test.gleam @@ -1,4 +1,5 @@ import gleam/dynamic +import gleam/option.{None, Some} import gleam/result import gleam/json.{Json} import gleam/should @@ -12,3 +13,25 @@ pub fn decode_test() { |> result.nil_error() |> should.equal(Error(Nil)) } + +pub fn encode_test() { + json.string("hello") + |> json.encode() + |> should.equal("\"hello\"") + + json.null() + |> json.encode() + |> should.equal("null") + + json.object([tuple("foo", json.int(5))]) + |> json.encode() + |> should.equal("{\"foo\":5}") + + json.nullable(Some(5), json.int) + |> json.encode() + |> should.equal("5") + + json.nullable(None, json.int) + |> json.encode() + |> should.equal("null") +} |