From f9cb560af761e10803128a06599f99bc2292b4be Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Fri, 8 Aug 2025 10:56:04 +0530 Subject: Spec for utils.table_contains --- spec/lua/utils_spec.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'spec') diff --git a/spec/lua/utils_spec.lua b/spec/lua/utils_spec.lua index de90ef5..b115498 100644 --- a/spec/lua/utils_spec.lua +++ b/spec/lua/utils_spec.lua @@ -88,3 +88,44 @@ describe('web.inspect', function() assert.are.equal(web.inspect({ a = '200', b = 5 }), '{\n a = "200",\n b = 5\n}') end) end) + +describe('web.utils.table_contains', function() + context('when table is empty', function() + it('returns true', function() + local result = web.utils.table_contains({}, 2) + assert.is_false(result) + end) + end) + + context('when table is a list', function() + context('when list contains given value', function() + it('returns true', function() + local result = web.utils.table_contains({ 1, 2 }, 2) + assert.is_true(result) + end) + end) + + context('when table does not contain given value', function() + it('returns false', function() + local result = web.utils.table_contains({ 1, 2 }, 99) + assert.is_false(result) + end) + end) + end) + + context('when table is a table with keys', function() + context('when table contains given value', function() + it('returns true', function() + local result = web.utils.table_contains({ a = 1, b = 2 }, 2) + assert.is_true(result) + end) + end) + + context('when table does not contain given value', function() + it('returns false', function() + local result = web.utils.table_contains({ a = 1, b = 2 }, 99) + assert.is_false(result) + end) + end) + end) +end) -- cgit v1.3.1