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

toml: support implicit array of tables key change (#12580)

This commit is contained in:
Larpon
2021-11-26 14:06:28 +01:00
committed by GitHub
parent 6299a73e90
commit 253e38d9d7
4 changed files with 190 additions and 5 deletions

View File

@ -0,0 +1,18 @@
import os
import toml
import toml.to
fn test_array_of_tables_edge_case_file() {
toml_file :=
os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) +
'.toml'
toml_doc := toml.parse(toml_file) or { panic(err) }
toml_json := to.json(toml_doc)
out_file :=
os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) +
'.out'
out_file_json := os.read_file(out_file) or { panic(err) }
println(toml_json)
assert toml_json == out_file_json
}

View File

@ -0,0 +1 @@
{ "Toml": [ { "ID": "1", "Index": 0, "Range": [ 0, 1, 2, 3 ], "Greeting": "Hello!", "Name": { "First": "Dolores", "Last": "Alvarado" }, "Friends": [ { "ID": 0, "Name": "Tom" }, { "ID": 1, "Name": "Dollie" } ] }, { "ID": "2", "Index": 1, "Range": [ 0, 1, 2, 3 ], "Greeting": "Hep!", "Name": { "First": "Rush", "Last": "Washington" }, "Friends": [ { "ID": 0, "Name": "Staci" }, { "ID": 1, "Name": "Dollie" } ] } ] }

View File

@ -0,0 +1,33 @@
[[Toml]]
ID = "1"
Index = 0
Range = [0, 1, 2, 3]
Greeting = "Hello!"
[Toml.Name]
First = "Dolores"
Last = "Alvarado"
[[Toml.Friends]]
ID = 0
Name = "Tom"
[[Toml.Friends]]
ID = 1
Name = "Dollie"
[[Toml]]
ID = "2"
Index = 1
Range = [0, 1, 2, 3]
Greeting = "Hep!"
[Toml.Name]
First = "Rush"
Last = "Washington"
[[Toml.Friends]]
ID = 0
Name = "Staci"
[[Toml.Friends]]
ID = 1
Name = "Dollie"