mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: replace generic '<>' with '[]' in .vv files (#16593)
This commit is contained in:
@@ -13,7 +13,7 @@ mut:
|
||||
|
||||
fn test_json_decode_fails_to_decode_unrecognised_array_of_dicts() {
|
||||
data := '[{"twins":[{"id":123,"seed":"abcde","pubkey":"xyzasd"},{"id":456,"seed":"dfgdfgdfgd","pubkey":"skjldskljh45sdf"}]}]'
|
||||
json.decode<TestTwins>(data) or {
|
||||
json.decode[TestTwins](data) or {
|
||||
assert err.msg() == "expected field 'twins' is missing"
|
||||
return
|
||||
}
|
||||
@@ -22,7 +22,7 @@ fn test_json_decode_fails_to_decode_unrecognised_array_of_dicts() {
|
||||
|
||||
fn test_json_decode_works_with_a_dict_of_arrays() {
|
||||
data := '{"twins":[{"id":123,"seed":"abcde","pubkey":"xyzasd"},{"id":456,"seed":"dfgdfgdfgd","pubkey":"skjldskljh45sdf"}]}'
|
||||
res := json.decode<TestTwins>(data) or {
|
||||
res := json.decode[TestTwins](data) or {
|
||||
assert false
|
||||
exit(1)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ struct Mount {
|
||||
|
||||
fn test_decode_u64() {
|
||||
data := '{"size": 10737418240}'
|
||||
m := json.decode<Mount>(data)!
|
||||
m := json.decode[Mount](data)!
|
||||
assert m.size == 10737418240
|
||||
// println(m)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ mut:
|
||||
|
||||
fn test_skip_fields_should_be_initialised_by_json_decode() {
|
||||
data := '{"total_comments": 55, "id": 123}'
|
||||
mut task := json.decode<Task>(data)!
|
||||
mut task := json.decode[Task](data)!
|
||||
assert task.id == 123
|
||||
assert task.total_comments == 55
|
||||
assert task.comments == []
|
||||
@@ -79,7 +79,7 @@ struct DbConfig {
|
||||
}
|
||||
|
||||
fn test_decode_error_message_should_have_enough_context_empty() {
|
||||
json.decode<DbConfig>('') or {
|
||||
json.decode[DbConfig]('') or {
|
||||
assert err.msg().len < 2
|
||||
return
|
||||
}
|
||||
@@ -87,7 +87,7 @@ fn test_decode_error_message_should_have_enough_context_empty() {
|
||||
}
|
||||
|
||||
fn test_decode_error_message_should_have_enough_context_just_brace() {
|
||||
json.decode<DbConfig>('{') or {
|
||||
json.decode[DbConfig]('{') or {
|
||||
assert err.msg() == '{'
|
||||
return
|
||||
}
|
||||
@@ -100,7 +100,7 @@ fn test_decode_error_message_should_have_enough_context_trailing_comma_at_end()
|
||||
"dbname": "alex",
|
||||
"user": "alex",
|
||||
}'
|
||||
json.decode<DbConfig>(txt) or {
|
||||
json.decode[DbConfig](txt) or {
|
||||
assert err.msg() == ' "user": "alex",\n}'
|
||||
return
|
||||
}
|
||||
@@ -109,7 +109,7 @@ fn test_decode_error_message_should_have_enough_context_trailing_comma_at_end()
|
||||
|
||||
fn test_decode_error_message_should_have_enough_context_in_the_middle() {
|
||||
txt := '{"host": "localhost", "dbname": "alex" "user": "alex", "port": "1234"}'
|
||||
json.decode<DbConfig>(txt) or {
|
||||
json.decode[DbConfig](txt) or {
|
||||
assert err.msg() == 'ost", "dbname": "alex" "user":'
|
||||
return
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ struct TodoDto {
|
||||
|
||||
fn test_decode_with_encode_arg() {
|
||||
body := TodoDto{}
|
||||
ret := json.decode<TodoDto>(json.encode(body))!
|
||||
ret := json.decode[TodoDto](json.encode(body))!
|
||||
println(ret)
|
||||
assert ret.foo == 0
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import x.json2 as json
|
||||
|
||||
struct Result<T> {
|
||||
struct Result[T] {
|
||||
ok bool
|
||||
result T
|
||||
}
|
||||
@@ -10,14 +10,14 @@ struct User {
|
||||
username string
|
||||
}
|
||||
|
||||
fn func<T>() !T {
|
||||
fn func[T]() !T {
|
||||
text := '{"ok": true, "result":{"id":37467243, "username": "ciao"}}'
|
||||
a := json.decode<Result<T>>(text)!
|
||||
a := json.decode[Result[T]](text)!
|
||||
return a.result
|
||||
}
|
||||
|
||||
fn test_decode_with_generic_struct() {
|
||||
ret := func<User>()!
|
||||
ret := func[User]()!
|
||||
println(ret)
|
||||
assert ret.id == 37467243
|
||||
assert ret.username == 'ciao'
|
||||
|
@@ -282,7 +282,7 @@ fn test_nested_type() {
|
||||
}
|
||||
}
|
||||
|
||||
struct Foo<T> {
|
||||
struct Foo[T] {
|
||||
pub:
|
||||
name string
|
||||
data T
|
||||
@@ -290,10 +290,10 @@ pub:
|
||||
|
||||
//! BUGFIX - .from_json(res)
|
||||
fn test_generic_struct() {
|
||||
foo_int := Foo<int>{'bar', 12}
|
||||
foo_int := Foo[int]{'bar', 12}
|
||||
foo_enc := json.encode(foo_int)
|
||||
assert foo_enc == '{"name":"bar","data":12}'
|
||||
foo_dec := json.decode<Foo<int>>(foo_enc)!
|
||||
foo_dec := json.decode[Foo[int]](foo_enc)!
|
||||
assert foo_dec.name == 'bar'
|
||||
assert foo_dec.data == 12
|
||||
}
|
||||
@@ -302,7 +302,7 @@ fn test_generic_struct() {
|
||||
fn test_errors() {
|
||||
invalid_array := fn () {
|
||||
data := '{"countries":[{"cities":[{"name":"London"},{"name":"Manchester"}],"name":"UK"},{"cities":{"name":"Donlon"},"name":"KU"}],"users":{"Foo":{"age":10,"nums":[1,2,3],"lastName":"Johnson","IsRegistered":true,"type":0,"pet_animals":"little foo"},"Boo":{"age":20,"nums":[5,3,1],"lastName":"Smith","IsRegistered":false,"type":4,"pet_animals":"little boo"}},"extra":{"2":{"n1":2,"n2":4,"n3":8,"n4":16},"3":{"n1":3,"n2":9,"n3":27,"n4":81}}}'
|
||||
json.decode<Data>(data) or {
|
||||
json.decode[Data](data) or {
|
||||
assert err.msg().starts_with('Json element is not an array:')
|
||||
return
|
||||
}
|
||||
@@ -310,7 +310,7 @@ fn test_errors() {
|
||||
}
|
||||
invalid_object := fn () {
|
||||
data := '{"countries":[{"cities":[{"name":"London"},{"name":"Manchester"}],"name":"UK"},{"cities":[{"name":"Donlon"},{"name":"Termanches"}],"name":"KU"}],"users":[{"age":10,"nums":[1,2,3],"lastName":"Johnson","IsRegistered":true,"type":0,"pet_animals":"little foo"},{"age":20,"nums":[5,3,1],"lastName":"Smith","IsRegistered":false,"type":4,"pet_animals":"little boo"}],"extra":{"2":{"n1":2,"n2":4,"n3":8,"n4":16},"3":{"n1":3,"n2":9,"n3":27,"n4":81}}}'
|
||||
json.decode<Data>(data) or {
|
||||
json.decode[Data](data) or {
|
||||
assert err.msg().starts_with('Json element is not an object:')
|
||||
return
|
||||
}
|
||||
@@ -330,7 +330,7 @@ struct Message {
|
||||
|
||||
//! BUGFIX - .from_json(res)
|
||||
fn test_decode_alias_struct() {
|
||||
msg := json.decode<Message>('{"id": "118499178790780929"}')!
|
||||
msg := json.decode[Message]('{"id": "118499178790780929"}')!
|
||||
// hacky way of comparing aliased strings
|
||||
assert msg.id.str() == '118499178790780929'
|
||||
}
|
||||
@@ -342,21 +342,21 @@ struct List {
|
||||
|
||||
//! BUGFIX - .from_json(res)
|
||||
fn test_list() {
|
||||
list := json.decode<List>('{"id": 1, "items": ["1", "2"]}')!
|
||||
list := json.decode[List]('{"id": 1, "items": ["1", "2"]}')!
|
||||
assert list.id == 1
|
||||
assert list.items == ['1', '2']
|
||||
}
|
||||
|
||||
//! BUGFIX - .from_json(res)
|
||||
fn test_list_no_id() {
|
||||
list := json.decode<List>('{"items": ["1", "2"]}')!
|
||||
list := json.decode[List]('{"items": ["1", "2"]}')!
|
||||
assert list.id == 0
|
||||
assert list.items == ['1', '2']
|
||||
}
|
||||
|
||||
//! BUGFIX - .from_json(res)
|
||||
fn test_list_no_items() {
|
||||
list := json.decode<List>('{"id": 1}')!
|
||||
list := json.decode[List]('{"id": 1}')!
|
||||
assert list.id == 1
|
||||
assert list.items == []
|
||||
}
|
||||
@@ -369,7 +369,7 @@ struct Info {
|
||||
|
||||
//! BUGFIX - .from_json(res)
|
||||
fn test_decode_null_object() {
|
||||
info := json.decode<Info>('{"id": 22, "items": null, "maps": null}')!
|
||||
info := json.decode[Info]('{"id": 22, "items": null, "maps": null}')!
|
||||
assert info.id == 22
|
||||
assert '${info.items}' == '[]'
|
||||
assert '${info.maps}' == '{}'
|
||||
@@ -377,7 +377,7 @@ fn test_decode_null_object() {
|
||||
|
||||
//! BUGFIX - .from_json(res)
|
||||
fn test_decode_missing_maps_field() {
|
||||
info := json.decode<Info>('{"id": 22, "items": null}')!
|
||||
info := json.decode[Info]('{"id": 22, "items": null}')!
|
||||
assert info.id == 22
|
||||
assert '${info.items}' == '[]'
|
||||
assert '${info.maps}' == '{}'
|
||||
|
Reference in New Issue
Block a user