mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-07 01:06:54 +08:00
Add unit test to validate to_json()
This commit is contained in:
parent
783b8b7361
commit
3d97c93e49
18
unittests/json_15.chai
Normal file
18
unittests/json_15.chai
Normal file
@ -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)
|
||||
Loading…
x
Reference in New Issue
Block a user