summaryrefslogtreecommitdiff
path: root/test/test-clod.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-clod.lua')
-rw-r--r--test/test-clod.lua75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/test-clod.lua b/test/test-clod.lua
index d64587c..f8baa77 100644
--- a/test/test-clod.lua
+++ b/test/test-clod.lua
@@ -181,6 +181,81 @@ function suite.insert_into_blank_two_similar_one_dissimilar_variant()
assert(conf:serialise() == 'person.name "Lars"\nperson.age = 42\n\npants.style "Y-Front"\n')
end
+function suite.parse_wild_key()
+ local conf = assert(clod.parse('foo["*"] "bar"'))
+ assert(conf.settings.foo.i_1 == "bar")
+end
+
+function suite.insert_wild_key()
+ local conf = assert(clod.parse(""))
+ conf.settings["foo.*"] = "bar"
+ assert(conf.settings.foo.i_1 == "bar")
+end
+
+function suite.insert_two_wild_keys()
+ local conf = assert(clod.parse(""))
+ conf.settings["foo.*"] = "bar"
+ conf.settings["foo.*"] = "baz"
+ assert(conf.settings.foo.i_1 == "bar")
+ assert(conf.settings.foo.i_2 == "baz")
+end
+
+function suite.serialise_wild_keys()
+ local input_str = 'foo["*"] "bar"\n'
+ local conf = assert(clod.parse(input_str))
+ assert(conf:serialise() == input_str)
+end
+
+function suite.iterate_all()
+ local input_str = [[
+project.name "Clod"
+project.description "Badgering stoats"
+
+owner.name "Daniel"
+]]
+ local conf = assert(clod.parse(input_str))
+ local had_name, had_desc, had_owner
+ for k, v in conf:each() do
+ if k == "project.name" then
+ had_name = true
+ elseif k == "project.description" then
+ had_desc = true
+ elseif k == "owner.name" then
+ had_owner = true
+ else
+ assert(false)
+ end
+ end
+ assert(had_name)
+ assert(had_desc)
+ assert(had_owner)
+end
+
+function suite.iterate_subset()
+ local input_str = [[
+project.name "Clod"
+project.description "Badgering stoats"
+
+owner.name "Daniel"
+]]
+ local conf = assert(clod.parse(input_str))
+ local had_name, had_desc, had_owner
+ for k, v in conf:each("project") do
+ if k == "project.name" then
+ had_name = true
+ elseif k == "project.description" then
+ had_desc = true
+ elseif k == "owner.name" then
+ had_owner = true
+ else
+ assert(false)
+ end
+ end
+ assert(had_name)
+ assert(had_desc)
+ assert(not had_owner)
+end
+
local count_ok = 0
for _, testname in ipairs(testnames) do
-- print("Run: " .. testname)