1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

x.json2: update tests (#16847)

This commit is contained in:
Hitalo Souza 2023-01-03 05:16:36 -03:00 committed by GitHub
parent bd2b216ac7
commit 2e54a8cb0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 27 deletions

View File

@ -99,6 +99,21 @@ pub mut:
point string [raw]
}
fn test_raw_json_field() {
color := json.decode[Color]('{"space": "YCbCr", "point": {"Y": 123}}') or {
assert false
Color{}
}
assert color.point == '{"Y":123}'
assert color.space == 'YCbCr'
}
fn test_bad_raw_json_field() {
color := json.decode[Color]('{"space": "YCbCr"}') or { return }
assert color.point == ''
assert color.space == 'YCbCr'
}
fn test_encode_map() {
expected := '{"one":1,"two":2,"three":3,"four":4}'
numbers := {
@ -113,9 +128,8 @@ fn test_encode_map() {
// 'three': 3
// 'four': 4
// }
// out := json.encode(numbers)
out := numbers.str()
assert out == expected
assert json.encode(numbers) == expected
assert numbers.str() == expected
}
type ID = string
@ -155,15 +169,6 @@ fn test_generic() {
assert result.x == 'test'
}
fn test_raw_json_field() {
color := json.decode[Color]('{"space": "YCbCr", "point": {"Y": 123}}') or {
assert false
Color{}
}
assert color.point == '{"Y":123}'
assert color.space == 'YCbCr'
}
struct Foo[T] {
pub:
name string

View File

@ -139,21 +139,6 @@ fn test_encode_decode_time() {
assert user2.reg_date.str() == '2020-12-22 07:23:00'
}
struct Color {
pub mut:
space string
point string [raw]
}
//! FIX: returning 0
fn test_bad_raw_json_field() {
color := json.decode<Color>('{"space": "YCbCr"}') or {
return
}
assert color.point == ''
assert color.space == 'YCbCr'
}
struct City {
name string
}