elegaanz / toml-glib

TOML library for Vala and GLib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to access nested tables

Lucki opened this issue · comments

commented

This example is directly from the toml.io page:

[dog."tater.man"]
type.name = "pug"

But trying to access them with doc["dog"]["tater.man"]["type"]["name"].as<string> () fails with:

[ERROR] Nothing at `dog`.

Here's a simple example for your tests which outputs the error in the log.

diff --git a/tests/toml-glib.vala b/tests/toml-glib.vala
index a5e0491..2c6b8b6 100644
--- a/tests/toml-glib.vala
+++ b/tests/toml-glib.vala
@@ -36,12 +36,16 @@ date-of-birth = 1975-05-07T08:34:45
 
 [hello]
 description = "Something really cool"
+
+[dog."tater.man"]
+type.name = "pug"
 """).parse ();
             var test = Toml.Serialization.deserialize<SerializationTester> (doc);
             assert_true (doc["name"].as<string> () == test.name);
             assert_true (doc["age"].as<int> () == test.age);
             assert_true (doc["date-of-birth"].as<DateTime> () == test.date_of_birth);
             assert_true (doc["hello"]["description"].as<string> () == test.hello.description);
+            assert_true (doc["dog"]["tater.man"]["type"]["name"].as<string> () == "pug");
         } catch (Error err) {
             print ("ERROR: %s\n", err.message);
             Test.fail ();
…
# Start of toml-glib tests
ok 1 /toml-glib/parser
ok 2 /toml-glib/serialize
ERROR: Nothing at `dog`.
not ok 3 /toml-glib/deserialize
# Start of lexer tests
…

Bonus issue:
You're not using your environment variable G_TEST_SRCDIR inside your tests so the tests /toml-glib/parser/file and /toml-glib/parser/whole-spec fail with

[ERROR] Failed to open file ?test.toml?: No such file or directory
not ok 12 /toml-glib/parser/file
[ERROR] Failed to open file ?all.toml?: No such file or directory
not ok 13 /toml-glib/parser/whole-spec

Bonus issue:
With the above file issue fixed I expect all.toml to fail or throw errors because it contains invalid configurations but it doesn't.

I'm no longer maintaining this library to be honest, but if you want to submit a patch I will accept it.