diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/mktests | 73 |
1 files changed, 62 insertions, 11 deletions
diff --git a/scripts/mktests b/scripts/mktests index 0bf3f64..b36b6dd 100755 --- a/scripts/mktests +++ b/scripts/mktests @@ -6,7 +6,7 @@ -- REQUIREMENTS: Luatex > 0.76, Luaotfload -- AUTHOR: Philipp Gesang (Phg), <phg42.2a@gmail.com> -- VERSION: 2.4 --- MODIFIED: 2013-08-26 09:31:22+0200 +-- MODIFIED: 2014-05-15 22:16:47+0200 ----------------------------------------------------------------------- -- --===================================================================-- @@ -16,15 +16,9 @@ --===================================================================-- -local tests = { } - -config = { luaotfload = { - names_dir = "names", - cache_dir = "fonts", - index_file = "luaotfload-names.lua", - resolver = "normal", - update_live = true, --- suppress db updates -}} +local tests = { } +local lpeg = require "lpeg" +local lpegmatch = lpeg.match kpse.set_program_name "luatex" @@ -32,6 +26,7 @@ require "lualibs" require "luaotfload-basics-gen.lua" require "luaotfload-log.lua" require "luaotfload-parsers" +require "luaotfload-configuration" require "luaotfload-database" local names = fonts.names @@ -66,10 +61,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,12 +277,14 @@ end tests ["resolve_font_name"] = resolve_font_name + ----------------------------------------------------------------------- --- runner ----------------------------------------------------------------------- local main = function () local failed, total = 0, 0 + config.actions.apply_defaults () for name, test in next, tests do texio.write_nl ("[" .. name .. "]") local newfailed, newtotal = test () |