v2 / vlib / toml / tests / nested_test.v
43 lines · 33 sloc · 1018 bytes · 12f04b50a75652ec54ad6f7ead7bdc37eecb8202
Raw
1import toml
2
3const toml_text = '
4[db]
5enabled = true
6
7[servers]
8 # Indentation (tabs and/or spaces) is allowed but not required
9 [servers.alpha]
10 ip = "10.0.0.1"
11 dc = "eqdc10"
12
13 [servers.beta]
14 ip = "10.0.0.2"
15 dc = "eqdc10"
16
17 [servers.alpha.tricky]
18 ip = "10.0.0.100"
19
20[firewall.rules]
21 block = true
22
23 [firewall.rules.limit]
24 ip = "10.0.0.101"
25'
26
27fn test_parse() {
28 toml_doc := toml.parse_text(toml_text) or { panic(err) }
29 // dump(toml_doc.ast)
30 // assert false
31
32 assert toml_doc.value('db.enabled').bool()
33 // TODO: make this work
34 assert toml_doc.value('servers.alpha.ip').string() == '10.0.0.1'
35 assert toml_doc.value('servers.alpha.dc').string() == 'eqdc10'
36
37 assert toml_doc.value('servers.beta.ip').string() == '10.0.0.2'
38 assert toml_doc.value('servers.beta.dc').string() == 'eqdc10'
39
40 assert toml_doc.value('servers.alpha.tricky.ip').string() == '10.0.0.100'
41 assert toml_doc.value('firewall.rules.limit.ip').string() == '10.0.0.101'
42 assert toml_doc.value('firewall.rules.block').bool() == true
43}
44