add assert.one_of

This commit is contained in:
TurtleP 2023-03-19 12:19:08 -04:00
parent 2762d4ada2
commit 2c31336210

View File

@ -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)