repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
neovim/tests/std/cheatsheet_spec.lua
Raw-- Replicate the private functions from lua/std/cheatsheet.lua for testing
local categories = {
lsp = 'LSP',
fuzzy = 'FZF',
files = 'FILE',
terminal = 'TERM',
editing = 'EDIT',
search = 'FIND',
session = 'SESS',
diff = 'DIFF',
operator = 'OP',
fun = 'FUN',
}
local category_patterns = {
'^lsp: ', 'lsp',
'^fuzzy: ', 'fuzzy',
'^files: ', 'files',
'^terminal: ', 'terminal',
'^editing: ', 'editing',
'^search: ', 'search',
'^session: ', 'session',
'^diff: ', 'diff',
'^operator: ', 'operator',
'^fun: ', 'fun',
}
local get_category_icon = function(category)
return categories[category] or category:upper()
end
local parse_description = function(desc)
if not desc or desc == '' then
return 'general', '*no description*'
end
for i = 1, #category_patterns, 2 do
local pattern, category = category_patterns[i], category_patterns[i + 1]
if desc:match(pattern) then
return category, desc:gsub(pattern, '')
end
end
return 'general', desc
end
describe('std.cheatsheet helpers', function()
describe('get_category_icon', function()
it('should return LSP for lsp', function()
assert.equals('LSP', get_category_icon('lsp'))
end)
it('should return FZF for fuzzy', function()
assert.equals('FZF', get_category_icon('fuzzy'))
end)
it('should return FILE for files', function()
assert.equals('FILE', get_category_icon('files'))
end)
it('should return uppercase fallback for unknown category', function()
assert.equals('UNKNOWN', get_category_icon('unknown'))
end)
end)
describe('parse_description', function()
it('should parse lsp: hover', function()
local cat, desc = parse_description('lsp: hover')
assert.equals('lsp', cat)
assert.equals('hover', desc)
end)
it('should parse fuzzy: find files', function()
local cat, desc = parse_description('fuzzy: find files')
assert.equals('fuzzy', cat)
assert.equals('find files', desc)
end)
it('should parse files: open', function()
local cat, desc = parse_description('files: open')
assert.equals('files', cat)
assert.equals('open', desc)
end)
it('should parse terminal: new terminal', function()
local cat, desc = parse_description('terminal: new terminal')
assert.equals('terminal', cat)
assert.equals('new terminal', desc)
end)
it('should parse editing: something', function()
local cat, desc = parse_description('editing: something')
assert.equals('editing', cat)
assert.equals('something', desc)
end)
it('should parse search: grep', function()
local cat, desc = parse_description('search: grep')
assert.equals('search', cat)
assert.equals('grep', desc)
end)
it('should parse session: save', function()
local cat, desc = parse_description('session: save')
assert.equals('session', cat)
assert.equals('save', desc)
end)
it('should parse diff: show', function()
local cat, desc = parse_description('diff: show')
assert.equals('diff', cat)
assert.equals('show', desc)
end)
it('should parse operator: move', function()
local cat, desc = parse_description('operator: move')
assert.equals('operator', cat)
assert.equals('move', desc)
end)
it('should parse fun: easter egg', function()
local cat, desc = parse_description('fun: easter egg')
assert.equals('fun', cat)
assert.equals('easter egg', desc)
end)
it('should return general for text without prefix', function()
local cat, desc = parse_description('no prefix text')
assert.equals('general', cat)
assert.equals('no prefix text', desc)
end)
it('should return *no description* for empty string', function()
local cat, desc = parse_description('')
assert.equals('general', cat)
assert.equals('*no description*', desc)
end)
it('should return *no description* for nil', function()
local cat, desc = parse_description(nil)
assert.equals('general', cat)
assert.equals('*no description*', desc)
end)
end)
end)