-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x.json2.decode2: minor improvements and bugfixes (#23083)
- Loading branch information
Showing
12 changed files
with
1,329 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
vlib/x/json2/decoder2/tests/json2_tests/decode_and_encode_struct_any_test.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import x.json2.decoder2 as json | ||
import x.json2 | ||
|
||
struct AnyStruct[T] { | ||
val T | ||
} | ||
|
||
struct OptAnyStruct[T] { | ||
val ?T | ||
} | ||
|
||
// struct OptAnyArrStruct { | ||
// val []?json2.Any | ||
// } | ||
|
||
fn test_values() { | ||
assert json.decode[AnyStruct[json2.Any]]('{"val":5}')!.val.int() == 5 | ||
assert json.decode[OptAnyStruct[json2.Any]]('{}')!.val == none | ||
assert json.decode[AnyStruct[[]json2.Any]]('{"val":[5,10]}')!.val.map(it.int()) == [ | ||
5, | ||
10, | ||
] | ||
// assert json.decode[OptAnyArrStruct]('{"val":[5,null,10]}')!.val == [?json2.Any(5),json.Null{},10] // skipped because test still fails even though they're the same | ||
|
||
assert json2.encode[AnyStruct[json2.Any]](AnyStruct[json2.Any]{json2.Any(5)}) == '{"val":5}' | ||
assert json2.encode[OptAnyStruct[json2.Any]](OptAnyStruct[json2.Any]{none}) == '{}' | ||
assert json2.encode[AnyStruct[[]json2.Any]](AnyStruct[[]json2.Any]{[json2.Any(5), 10]}) == '{"val":[5,10]}' | ||
// assert json2.encode[OptAnyArrStruct](OptAnyArrStruct{[?json2.Any(5),none,10]}) == '{"val":[5,null,10]}' // encode_array has not implemented optional arrays yet | ||
} |
Oops, something went wrong.