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

toml: add support for arrays and maps of primitives in reflect<T> (#13245)

This commit is contained in:
Larpon
2022-01-21 20:20:44 +01:00
committed by GitHub
parent 36c9ed6889
commit 7ae96f0e38
2 changed files with 166 additions and 0 deletions

View File

@@ -7,6 +7,19 @@ height = 1.97
birthday = 1980-04-23
strings = [
"v matures",
"like rings",
"spread in the",
"water"
]
bools = [true, false, true, true]
floats = [0.0, 1.0, 2.0, 3.0]
int_map = {"a" = 0, "b" = 1, "c" = 2, "d" = 3}
[bio]
text = "Tom has done many great things"
years_of_service = 5
@@ -26,6 +39,10 @@ struct User {
age int
height f64
birthday toml.Date
strings []string
bools []bool
floats []f32
int_map map[string]int
config toml.Any
mut:
@@ -42,6 +59,15 @@ fn test_reflect() {
assert user.age == 45
assert user.height == 1.97
assert user.birthday.str() == '1980-04-23'
assert user.strings == ['v matures', 'like rings', 'spread in the', 'water']
assert user.bools == [true, false, true, true]
assert user.floats == [f32(0.0), 1.0, 2.0, 3.0]
assert user.int_map == {
'a': 0
'b': 1
'c': 2
'd': 3
}
assert user.bio.text == 'Tom has done many great things'
assert user.bio.years_of_service == 5