json2: encode reference fields too (#17058)

This commit is contained in:
Hitalo Souza 2023-04-28 10:24:27 -03:00 committed by GitHub
parent 433208ea7e
commit b0589c645d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 43 deletions

View file

@ -108,26 +108,6 @@ fn test_option_sumtypes() {
assert json.encode(StructTypeOption[SumTypes]{ val: 1 }) == '{"val":1}'
}
fn test_pointer() {
// mut string_initialized_with_reference := ""
assert json.encode(StructTypePointer[string]{ val: 0 }) == '{"val":""}' // REVIEW
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 }) == '{"val":false}' // REVIEW
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 }) == '{"val":0}' // REVIEW
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_caos() {
typed_string_struct := StructType[string]{
val: 'a'