mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
json2: encode reference fields too (#17058)
This commit is contained in:
parent
433208ea7e
commit
b0589c645d
6 changed files with 63 additions and 43 deletions
|
@ -227,6 +227,26 @@ fn test_alias() {
|
|||
assert json.encode(StructType[StructAlias]{ val: StructType[int]{1} }) == '{"val":{"val":1}}'
|
||||
}
|
||||
|
||||
fn test_pointer() {
|
||||
mut string_initialized_with_reference := ''
|
||||
assert json.encode(StructTypePointer[string]{ val: 0 }) == '{}'
|
||||
assert json.encode(StructTypePointer[string]{ val: &string_initialized_with_reference }) == '{"val":""}'
|
||||
string_initialized_with_reference = 'a'
|
||||
assert json.encode(StructTypePointer[string]{ val: &string_initialized_with_reference }) == '{"val":"a"}'
|
||||
|
||||
mut bool_initialized_with_reference := false
|
||||
assert json.encode(StructTypePointer[bool]{ val: 0 }) == '{}'
|
||||
assert json.encode(StructTypePointer[bool]{ val: &bool_initialized_with_reference }) == '{"val":false}'
|
||||
bool_initialized_with_reference = true
|
||||
assert json.encode(StructTypePointer[bool]{ val: &bool_initialized_with_reference }) == '{"val":true}'
|
||||
|
||||
mut int_initialized_with_reference := 0
|
||||
assert json.encode(StructTypePointer[int]{ val: 0 }) == '{}'
|
||||
assert json.encode(StructTypePointer[int]{ val: &int_initialized_with_reference }) == '{"val":0}'
|
||||
int_initialized_with_reference = 1
|
||||
assert json.encode(StructTypePointer[int]{ val: &int_initialized_with_reference }) == '{"val":1}'
|
||||
}
|
||||
|
||||
fn test_sumtypes() {
|
||||
assert json.encode(StructType[SumTypes]{}) == '{}'
|
||||
assert json.encode(StructType[SumTypes]{ val: '' }) == '{"val":""}'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue