Skip to content

Commit 0941112

Browse files
committed
json.cjson: add a test case for more complex json object construction
1 parent 21c5cad commit 0941112

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

vlib/json/cjson/cjson_test.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,16 @@ fn test_object_with_null() {
66
root.add_item_to_object('age', cjson.create_null())
77
assert root.print_unformatted() == '{"name":"Andre","age":null}'
88
}
9+
10+
fn test_creating_complex_json() {
11+
mut root := cjson.create_array()
12+
root.add_item_to_array(cjson.create_string('user'))
13+
mut obj := cjson.create_object()
14+
obj.add_item_to_object('username', cjson.create_string('foo'))
15+
obj.add_item_to_object('password', cjson.create_string('bar'))
16+
root.add_item_to_array(obj)
17+
result := root.print_unformatted()
18+
println(result)
19+
20+
assert result == '["user",{"username":"foo","password":"bar"}]'
21+
}

0 commit comments

Comments
 (0)