mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +00:00
add assert.one_of
This commit is contained in:
parent
2762d4ada2
commit
2c31336210
15
assert.lua
15
assert.lua
@ -10,7 +10,6 @@
|
||||
can call nop() to dummy out everything for "release mode"
|
||||
(if you're worried about that sort of thing)
|
||||
]]
|
||||
|
||||
local _assert = assert
|
||||
|
||||
--proxy calls to global assert
|
||||
@ -82,6 +81,20 @@ function assert:type_or_nil(a, t, msg, stack_level)
|
||||
return a
|
||||
end
|
||||
|
||||
--assert a value is one of those in a table of options
|
||||
function assert:one_of(a, t, msg, stack_level)
|
||||
local pass = false
|
||||
for index = 1, #t do
|
||||
if t[index] == a then
|
||||
pass = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
assert:equal(pass, true, msg, stack_level)
|
||||
return a
|
||||
end
|
||||
|
||||
--replace everything in assert with nop functions that just return their second argument, for near-zero overhead on release
|
||||
function assert:nop()
|
||||
local nop = function(_, a)
|
||||
|
Loading…
Reference in New Issue
Block a user