aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-08-08 10:56:04 +0530
committerAkshay Nair <phenax5@gmail.com>2025-08-08 10:56:04 +0530
commitf9cb560af761e10803128a06599f99bc2292b4be (patch)
tree0fad096c2733624560049b3d7841a6a2e8c0e1f8
parent5341ddb9571b306347346f7d2f501bbfc25e7c33 (diff)
downloadnull-browser-f9cb560af761e10803128a06599f99bc2292b4be.tar.gz
null-browser-f9cb560af761e10803128a06599f99bc2292b4be.zip
Spec for utils.table_contains
-rw-r--r--TODO.org2
-rw-r--r--lua/null-browser/utils.lua2
-rw-r--r--spec/lua/utils_spec.lua41
3 files changed, 43 insertions, 2 deletions
diff --git a/TODO.org b/TODO.org
index 032946b..92eaf8a 100644
--- a/TODO.org
+++ b/TODO.org
@@ -19,7 +19,7 @@
- [ ] Update all api to use opts table pattern
- [ ] web.decorations.*.set_size()
- [ ] web.keymap.configure_mode(modename, { passthrough = false })
-- [ ] Vertical tabline ui
+- [X] Vertical tabline ui
- [ ] Fullscreen
- [ ] Zoom in/out/reset
- [ ] Remove unwanted "async"-ness in lua calls
diff --git a/lua/null-browser/utils.lua b/lua/null-browser/utils.lua
index 2e42edb..73c0499 100644
--- a/lua/null-browser/utils.lua
+++ b/lua/null-browser/utils.lua
@@ -85,7 +85,7 @@ end
--- @param value any
--- @return boolean
function web.utils.table_contains(tbl, value)
- for _, tbl_val in ipairs(tbl) do
+ for _, tbl_val in pairs(tbl) do
if tbl_val == value then
return true
end
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)