aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/lua/utils_spec.lua41
1 files changed, 41 insertions, 0 deletions
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)