diff options
author | Louis Pilfold <louis@lpil.uk> | 2022-01-01 16:03:32 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-01-01 16:03:32 +0000 |
commit | d3d0ff192ebb29827c63e28f3aa8ef101b575efe (patch) | |
tree | bd1c64fcab00c9b0f0684b54f30e0da90a159207 /test | |
parent | cdcf2fffcc49e0d5d24708cb54169a96fa356054 (diff) | |
download | gleam_json-d3d0ff192ebb29827c63e28f3aa8ef101b575efe.tar.gz gleam_json-d3d0ff192ebb29827c63e28f3aa8ef101b575efe.zip |
Test string builder generation
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam_json_test.gleam | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/test/gleam_json_test.gleam b/test/gleam_json_test.gleam index 80849e3..7617ebb 100644 --- a/test/gleam_json_test.gleam +++ b/test/gleam_json_test.gleam @@ -1,6 +1,7 @@ import gleam/dynamic -import gleam/json +import gleam/json.{Json} import gleam/option.{None, Some} +import gleam/string_builder import gleam/result import gleeunit import gleeunit/should @@ -27,34 +28,41 @@ pub fn decode_unexpected_byte_test() { pub fn encode_string_test() { json.string("hello") - |> json.to_string() - |> should.equal("\"hello\"") + |> should_encode("\"hello\"") } pub fn encode_null_test() { json.null() - |> json.to_string() - |> should.equal("null") + |> should_encode("null") } pub fn encode_object_test() { json.object([#("foo", json.int(5))]) - |> json.to_string() - |> should.equal("{\"foo\":5}") + |> should_encode("{\"foo\":5}") } pub fn encode_list_test() { json.list([json.int(5), json.int(6)]) - |> json.to_string() - |> should.equal("[5,6]") + |> should_encode("[5,6]") } -pub fn encode_nullable_test() { +pub fn encode_nullable_some_test() { json.nullable(Some(5), json.int) - |> json.to_string() - |> should.equal("5") + |> should_encode("5") +} +pub fn encode_nullable_none_test() { json.nullable(None, json.int) + |> should_encode("null") +} + +fn should_encode(data: Json, expected: String) { + data |> json.to_string() - |> should.equal("null") + |> should.equal(expected) + + data + |> json.to_string_builder + |> string_builder.to_string + |> should.equal(json.to_string(data)) } |