Added type check in lume.fn() and additional tests

This commit is contained in:
rxi 2014-04-04 18:30:24 +01:00
parent 1a087efe99
commit 3a4ce4fe3b
2 changed files with 3 additions and 0 deletions

View File

@ -235,6 +235,7 @@ end
function lume.fn(fn, ...)
assert(isfunction(fn), "expected a function as the first argument")
local args = {...}
return function(...)
local a = lume.merge(lume.clone(args), {...})

View File

@ -258,6 +258,7 @@ end
tests["lume.fn"] = function()
local f = lume.fn(function(a, b) return a + b end, 10)
testeq( f(5), 15 )
tester.test.error( lume.fn, 123 )
end
-- lume.once
@ -265,6 +266,7 @@ tests["lume.once"] = function()
local f = lume.once(function(a, b) return a + b end, 10)
testeq( f(5), 15 )
testeq( f(5), nil )
tester.test.error( lume.once, 123 )
end
-- lume.time