diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-08-08 10:56:04 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-08-08 10:56:04 +0530 |
| commit | f9cb560af761e10803128a06599f99bc2292b4be (patch) | |
| tree | 0fad096c2733624560049b3d7841a6a2e8c0e1f8 /spec | |
| parent | 5341ddb9571b306347346f7d2f501bbfc25e7c33 (diff) | |
| download | null-browser-f9cb560af761e10803128a06599f99bc2292b4be.tar.gz null-browser-f9cb560af761e10803128a06599f99bc2292b4be.zip | |
Spec for utils.table_contains
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/lua/utils_spec.lua | 41 |
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) |
