From 09411128afc15cc9b95c06410459beb8587e020d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 21 Sep 2022 17:22:42 +0300 Subject: [PATCH] json.cjson: add a test case for more complex json object construction --- vlib/json/cjson/cjson_test.v | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vlib/json/cjson/cjson_test.v b/vlib/json/cjson/cjson_test.v index ac9a567af7..f50c7131c8 100644 --- a/vlib/json/cjson/cjson_test.v +++ b/vlib/json/cjson/cjson_test.v @@ -6,3 +6,16 @@ fn test_object_with_null() { root.add_item_to_object('age', cjson.create_null()) assert root.print_unformatted() == '{"name":"Andre","age":null}' } + +fn test_creating_complex_json() { + mut root := cjson.create_array() + root.add_item_to_array(cjson.create_string('user')) + mut obj := cjson.create_object() + obj.add_item_to_object('username', cjson.create_string('foo')) + obj.add_item_to_object('password', cjson.create_string('bar')) + root.add_item_to_array(obj) + result := root.print_unformatted() + println(result) + + assert result == '["user",{"username":"foo","password":"bar"}]' +}