mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
add (commented-out) problematic multiple-nested struct test-case
This commit is contained in:
parent
21d98ff904
commit
f35f14ebbe
@ -15,6 +15,11 @@ struct Pet {
|
|||||||
has_furr bool
|
has_furr bool
|
||||||
title JobTitle
|
title JobTitle
|
||||||
address Address
|
address Address
|
||||||
|
// *¹ Currently it is only possible to decode a single nested struct generically.
|
||||||
|
// As soon as we decode another nested struct (e.g. within this struct, like `contact` below)
|
||||||
|
// or only one nested struct within another struct, it results in wrong values or errors.
|
||||||
|
// Related issue: https://github.com/vlang/v/issues/18110
|
||||||
|
// contact Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Address {
|
struct Address {
|
||||||
@ -22,6 +27,12 @@ struct Address {
|
|||||||
city string
|
city string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *¹
|
||||||
|
/*
|
||||||
|
struct Contact {
|
||||||
|
phone string
|
||||||
|
}*/
|
||||||
|
|
||||||
struct Employee {
|
struct Employee {
|
||||||
mut:
|
mut:
|
||||||
name string
|
name string
|
||||||
@ -45,6 +56,8 @@ struct Arrs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_encode_and_decode() {
|
fn test_encode_and_decode() {
|
||||||
|
// *¹
|
||||||
|
// p := Pet{'Mr. Scratchy McEvilPaws', ['Freddy', 'Fred', 'Charles'], 8, -1, 0.8, true, .manager, Address{'1428 Elm Street', 'Springwood'}, Contact{'123-456-7890'}}
|
||||||
p := Pet{'Mr. Scratchy McEvilPaws', ['Freddy', 'Fred', 'Charles'], 8, -1, 0.8, true, .manager, Address{'1428 Elm Street', 'Springwood'}}
|
p := Pet{'Mr. Scratchy McEvilPaws', ['Freddy', 'Fred', 'Charles'], 8, -1, 0.8, true, .manager, Address{'1428 Elm Street', 'Springwood'}}
|
||||||
s := 'name = "Mr. Scratchy McEvilPaws"
|
s := 'name = "Mr. Scratchy McEvilPaws"
|
||||||
nicknames = [
|
nicknames = [
|
||||||
@ -58,6 +71,7 @@ height = 0.8
|
|||||||
has_furr = true
|
has_furr = true
|
||||||
title = 2
|
title = 2
|
||||||
address = { street = "1428 Elm Street", city = "Springwood" }'
|
address = { street = "1428 Elm Street", city = "Springwood" }'
|
||||||
|
// contact = { phone = "123-456-7890" }' // *¹
|
||||||
|
|
||||||
assert toml.encode[Pet](p) == s
|
assert toml.encode[Pet](p) == s
|
||||||
assert toml.decode[Pet](s)! == p
|
assert toml.decode[Pet](s)! == p
|
||||||
|
Loading…
Reference in New Issue
Block a user