From 5b497fab972a8f22963b9c76b36b7d2ed6689711 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 13 May 2012 21:01:43 +0100 Subject: Change builtin default to store a _return rule ready for use --- lib/lace/builtin.lua | 2 +- test/test-lace.builtin.lua | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/lace/builtin.lua b/lib/lace/builtin.lua index 289f688..ff1cfd2 100644 --- a/lib/lace/builtin.lua +++ b/lib/lace/builtin.lua @@ -81,7 +81,7 @@ function builtin.default(compcontext, def, result, reason, unwanted) return compiler().error("Cannot change the default") end - compcontext[".lace"].default = { result, reason } + compcontext[".lace"].default = _return(compcontext, result, reason) return { fn = function() return true end, diff --git a/test/test-lace.builtin.lua b/test/test-lace.builtin.lua index 4da3bb2..558f15a 100644 --- a/test/test-lace.builtin.lua +++ b/test/test-lace.builtin.lua @@ -135,9 +135,7 @@ function suite.compile_builtin_default_ok() assert(type(cmdtab.args) == "table", "And an arg table") assert(cmdtab.fn() == true, "Default command should always return true") assert(type(compctx[".lace"].default) == "table", "Default should always set up the context") - assert(#compctx[".lace"].default == 2, "Default table should consist of two entries") - assert(compctx[".lace"].default[1] == "allow", "First entry should be the result") - assert(compctx[".lace"].default[2] == "because", "Second entry should be the reason") + assert(type(compctx[".lace"].default.fn) == "function", "Default table should have a function like a rule") end function suite.compile_builtin_default_twice() @@ -159,9 +157,7 @@ function suite.compile_builtin_default_noreason() assert(type(cmdtab.args) == "table", "And an arg table") assert(cmdtab.fn() == true, "Default command should always return true") assert(type(compctx[".lace"].default) == "table", "Default should always set up the context") - assert(#compctx[".lace"].default == 2, "Default table should consist of two entries") - assert(compctx[".lace"].default[1] == "allow", "First entry should be the result") - assert(compctx[".lace"].default[2] == "Default behaviour", "Second entry should be the reason") + assert(type(compctx[".lace"].default.fn) == "function", "Default table should have a function like a rule") end -- cgit v1.2.1