From 3a4ce4fe3b3875ea21fc0add2e3f426c13747d3a Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 4 Apr 2014 18:30:24 +0100 Subject: [PATCH] Added type check in lume.fn() and additional tests --- lume.lua | 1 + test/test_lume.lua | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lume.lua b/lume.lua index a0b75fc..73c2b33 100644 --- a/lume.lua +++ b/lume.lua @@ -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), {...}) diff --git a/test/test_lume.lua b/test/test_lume.lua index ee1e191..57ac598 100644 --- a/test/test_lume.lua +++ b/test/test_lume.lua @@ -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