Skip to content

Commit

Permalink
chore(tests):fix test for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvirtin committed Jul 4, 2024
1 parent 49ea924 commit 081077b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lua/vgit/core/icons.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
local has_web_devicons, web_devicons = pcall(require, 'nvim-web-devicons')

local icons = {}

function icons.get(fname, extension)
local has_web_devicons, web_devicons = pcall(require, 'nvim-web-devicons')
if not has_web_devicons or not web_devicons.has_loaded() then return nil, '' end

return web_devicons.get_icon(fname, extension)
end

Expand Down
2 changes: 1 addition & 1 deletion lua/vgit/core/utils/list.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local list = {}

list.is_list = vim.is_list
list.is_list = vim.islist

list.is_empty = vim.tbl_isempty

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/core/icons_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
describe('icons', function()
local icons

before_each(function()
icons = require('vgit.core.icons')
end)

describe('get', function()
it('should return icon and color when nvim-web-devicons is loaded', function()
package.loaded['nvim-web-devicons'] = {
has_loaded = function() return true end,
get_icon = function(fname, ext) return '', 'blue' end,
}
local icon, color = icons.get('icons_spec.lua', 'lua')
assert.equals('', icon)
assert.equals('blue', color)
end)

it('should return nil and empty string when nvim-web-devicons is not loaded', function()
package.loaded['nvim-web-devicons'] = {
has_loaded = function() return false end,
}

local icon, color = icons.get('test.txt', 'txt')
assert.is_nil(icon)
assert.equals('', color)
end)
end)
end)

0 comments on commit 081077b

Please sign in to comment.