mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
json.cjson: add a test case for more complex json object construction
This commit is contained in:
parent
21c5cadc59
commit
09411128af
1 changed files with 13 additions and 0 deletions
|
@ -6,3 +6,16 @@ fn test_object_with_null() {
|
||||||
root.add_item_to_object('age', cjson.create_null())
|
root.add_item_to_object('age', cjson.create_null())
|
||||||
assert root.print_unformatted() == '{"name":"Andre","age":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"}]'
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue