From 2c313362106fd522cf88f2e4da3fb63bf813ce07 Mon Sep 17 00:00:00 2001 From: TurtleP Date: Sun, 19 Mar 2023 12:19:08 -0400 Subject: [PATCH] add assert.one_of --- assert.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/assert.lua b/assert.lua index 8998452..2951633 100644 --- a/assert.lua +++ b/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)