mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: fix option state (#18802)
This commit is contained in:
46
vlib/json/json_option_none_test.v
Normal file
46
vlib/json/json_option_none_test.v
Normal file
@ -0,0 +1,46 @@
|
||||
import json
|
||||
|
||||
struct Struct {
|
||||
a int
|
||||
}
|
||||
|
||||
struct Test {
|
||||
a ?int
|
||||
b ?string
|
||||
c ?Struct
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
a := json.decode(Test, '{"a": 1, "b": "foo"}')!
|
||||
dump(a)
|
||||
|
||||
assert a.a != none
|
||||
assert a.b != none
|
||||
|
||||
b := json.decode(Test, '{"a": 1}')!
|
||||
dump(b)
|
||||
assert b.a != none
|
||||
assert b.b == none
|
||||
|
||||
c := json.decode(Test, '{"a": 1, "b": null}')!
|
||||
dump(b)
|
||||
assert c.a != none
|
||||
assert c.b == none
|
||||
|
||||
d := json.decode(Test, '{"a": null, "b": null}')!
|
||||
dump(d)
|
||||
assert d.a == none
|
||||
assert d.b == none
|
||||
|
||||
e := json.decode(Test, '{"a": null, "b": null, "c": null}')!
|
||||
dump(e)
|
||||
assert e.a == none
|
||||
assert e.b == none
|
||||
assert e.c == none
|
||||
|
||||
f := json.decode(Test, '{"a": null, "b": null, "c": {"a":1}}')!
|
||||
dump(f)
|
||||
assert f.a == none
|
||||
assert f.b == none
|
||||
assert f.c != none
|
||||
}
|
Reference in New Issue
Block a user