diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-04-21 18:22:24 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-04-21 18:22:24 +0200 |
commit | 70a6425e1b6041d5c476117fa7c5a3acb9bc386a (patch) | |
tree | 1337c27bb849cb6440298fb808f0d2024cf4741d | |
parent | f8d43e62f3927545d06e39d01499442b0f64fe79 (diff) | |
download | luaotfload-70a6425e1b6041d5c476117fa7c5a3acb9bc386a.tar.gz |
[tests] add test for config file syntax
-rwxr-xr-x | scripts/mktests | 60 | ||||
-rw-r--r-- | src/luaotfload-parsers.lua | 4 |
2 files changed, 61 insertions, 3 deletions
diff --git a/scripts/mktests b/scripts/mktests index 0bf3f64..2fed723 100755 --- a/scripts/mktests +++ b/scripts/mktests @@ -26,6 +26,9 @@ config = { luaotfload = { update_live = true, --- suppress db updates }} +local lpeg = require "lpeg" +local lpegmatch = lpeg.match + kpse.set_program_name "luatex" require "lualibs" @@ -66,10 +69,64 @@ local pprint_spec = function (spec) end ----------------------------------------------------------------------- ---- tool tests +--- parser tests ----------------------------------------------------------------------- +local test_config_input = [==[ + + +[foo] +bar = baz +xyzzy = no +buzz + +[lavernica "brutalitops"] +# It’s a locomotive that runs on us. + laan-ev = zip zop zooey ; jib-jab +Crouton = "Fibrosis \"\\ # " +]==] + +local test_config_output = { + { section = { title = "foo" }, + variables = { bar = "baz", + xyzzy = false, + buzz = true } }, + { section = { title = "lavernica", + subtitle = "brutalitops" }, + variables = { ["laan-ev"] = "zip zop zooey", + crouton = "Fibrosis \"\\ # " } } +} + +local parse_config = function () + local parser = luaotfload.parsers.config + local result = lpegmatch (parser, test_config_input) + --- compare values recursively + local aux aux = function (t1, t2) + --- cheaply non-tail recursive + local k1 = table.keys (t1) + local k2 = table.keys (t2) + if #k1 ~= #k2 then + return false + end + for i = 1, #k1 do + local k = k1[i] + local v1 = t1[k] + local v2 = t2[k] + if type (v1) == "table" then + if type (v2) ~= "table" or not aux (v1, v2) then + return false + end + elseif v1 ~= v2 then + return false + end + end + return true + end + return aux (result, test_config_output) and 0 or 1, 1 +end + +tests["parse_config"] = parse_config ----------------------------------------------------------------------- --- font tests @@ -228,6 +285,7 @@ end tests ["resolve_font_name"] = resolve_font_name + ----------------------------------------------------------------------- --- runner ----------------------------------------------------------------------- diff --git a/src/luaotfload-parsers.lua b/src/luaotfload-parsers.lua index a45fcb8..6a99ad7 100644 --- a/src/luaotfload-parsers.lua +++ b/src/luaotfload-parsers.lua @@ -662,7 +662,7 @@ local ini_section = Ct (ini_heading * ini_variables) local ini_sections = skip_line^0 * ini_section^0 local config = Ct (ini_sections) ---[[doc-- +--[=[doc-- The INI parser converts an input of the form @@ -690,7 +690,7 @@ local config = Ct (ini_sections) variables = { ["laan-ev"] = "zip zop zooey", crouton = "Fibrosis \"\\ # " } } } ---doc]]-- +--doc]=]-- luaotfload.parsers.config = config |