aboutsummaryrefslogtreecommitdiff
path: root/test/gleam_json_test.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'test/gleam_json_test.gleam')
-rw-r--r--test/gleam_json_test.gleam42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/gleam_json_test.gleam b/test/gleam_json_test.gleam
new file mode 100644
index 0000000..162fa6e
--- /dev/null
+++ b/test/gleam_json_test.gleam
@@ -0,0 +1,42 @@
+import gleam/dynamic
+import gleam/option.{None, Some}
+import gleam/result
+import gleam/json
+import gleeunit/should
+import gleeunit
+
+pub fn main() {
+ gleeunit.main()
+}
+
+pub fn decode_test() {
+ json.decode("5")
+ |> result.map(dynamic.from)
+ |> should.equal(Ok(dynamic.from(5)))
+
+ json.decode(".")
+ |> 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([#("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")
+}