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 /scripts/mktests | |
parent | f8d43e62f3927545d06e39d01499442b0f64fe79 (diff) | |
download | luaotfload-70a6425e1b6041d5c476117fa7c5a3acb9bc386a.tar.gz |
[tests] add test for config file syntax
Diffstat (limited to 'scripts/mktests')
-rwxr-xr-x | scripts/mktests | 60 |
1 files changed, 59 insertions, 1 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 ----------------------------------------------------------------------- |