From 3d97c93e494fec79c9e85e46716ab02128984056 Mon Sep 17 00:00:00 2001 From: Glen Fraser Date: Thu, 11 Jan 2018 19:43:32 +0100 Subject: [PATCH] Add unit test to validate to_json() --- unittests/json_15.chai | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 unittests/json_15.chai diff --git a/unittests/json_15.chai b/unittests/json_15.chai new file mode 100644 index 00000000..7e8ad652 --- /dev/null +++ b/unittests/json_15.chai @@ -0,0 +1,18 @@ +// Various to_json() tests +assert_equal(to_json(-13570), "-13570") +assert_equal(to_json(0.654321), "0.654321") +assert_equal(to_json("ChaiScript"), "\"ChaiScript\"") +assert_equal(to_json(true), "true") +assert_equal(to_json([1, 2, 3]), "[1, 2, 3]") +assert_equal(to_json(Vector()), "[]") // empty vector +assert_equal(to_json([]), "[]") // empty vector +assert_equal(to_json(Map()), "{\n\n}") // empty map +assert_equal(to_json(Dynamic_Object()), "{\n\n}") // empty object + +// Round-trip JSON tests +assert_equal(from_json(to_json([])), []) +assert_equal(from_json(to_json(Map())), Map()) +assert_equal(to_json(from_json("null")), "null") +assert_equal(from_json(to_json(["a": 5, "b": "stuff"])), ["a": 5, "b": "stuff"]) +auto x = [3.5, true, false, "test", [], Vector(), Map()] +assert_equal(from_json(to_json(x)), x)