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" can call nop() to dummy out everything for "release mode"
(if you're worried about that sort of thing) (if you're worried about that sort of thing)
]] ]]
local _assert = assert local _assert = assert
--proxy calls to global assert --proxy calls to global assert
@ -82,6 +81,20 @@ function assert:type_or_nil(a, t, msg, stack_level)
return a return a
end 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 --replace everything in assert with nop functions that just return their second argument, for near-zero overhead on release
function assert:nop() function assert:nop()
local nop = function(_, a) local nop = function(_, a)