repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
neovim/tests/bugabinga/pivi/editor/guide_spec.lua
Raw---@diagnostic disable: duplicate-set-field, need-check-nil, param-type-mismatch, assign-type-mismatch, redundant-parameter
-- Every module that binds a key registers its hook on load, and a hook only
-- reaches buffers created after it, so they all load before the first one.
require 'bugabinga.pivi.fold'
require 'bugabinga.pivi.navigate'
require 'bugabinga.pivi.detail'
require 'bugabinga.pivi.diff'
require 'bugabinga.pivi_keys'
local guide = require 'bugabinga.pivi.guide'
local transcript = require 'bugabinga.pivi.transcript'
local fake = dofile 'tests/helpers/pivi_fake.lua'
local text_of = function( lines ) return table.concat( lines, '\n' ) end
describe( 'pivi guide', function()
local bufnr
before_each( function()
bufnr = transcript.ensure 'guided'
transcript.clear( bufnr )
end )
after_each( function()
transcript.forget_all()
fake.close_extra_windows()
end )
it( 'reads the keys that actually exist in the buffer', function()
local described = {}
for _, mapping in ipairs( guide.describe( bufnr ) ) do
described[mapping.keys] = mapping.what
end
-- The keys are the configuration's choice, so the guide reports those.
for _, keys in ipairs { '<CR>', 'K', ']]', '[[', } do
assert.is_string( described[keys], keys .. ' is missing from the guide' )
end
end )
it( 'drops the plug mappings a reader cannot type', function()
for _, mapping in ipairs( guide.describe( bufnr ) ) do
assert.is_nil( mapping.keys:find( 'Plug', 1, true ) )
end
end )
it( 'lists every command the user command offers', function()
local written = text_of( guide.lines( bufnr ) )
for _, name in ipairs { 'ask', 'help', 'prompt', 'diff', 'guide', } do
assert.is_true( written:find( ':Pi ' .. name, 1, true ) ~= nil, name .. ' is missing' )
end
assert.is_true( written:find( 'Bare `:Pi` opens the prompt', 1, true ) ~= nil )
end )
it( 'explains what each key does, not only that it exists', function()
local written = text_of( guide.lines( bufnr ) )
assert.is_true( written:lower():find( 'next entry', 1, true ) ~= nil )
assert.is_true( written:lower():find( 'compare', 1, true ) ~= nil )
assert.is_true( written:find( 'za', 1, true ) ~= nil )
end )
it( 'shows itself without leaving the transcript', function()
local win = transcript.show( bufnr )
vim.api.nvim_set_current_win( win )
local float, floating = guide.show( bufnr )
assert.is_number( float )
assert.equal( win, vim.api.nvim_get_current_win() )
assert.is_true( vim.api.nvim_buf_get_name( float ):find( 'pivi://guide', 1, true ) ~= nil )
if floating and vim.api.nvim_win_is_valid( floating ) then
vim.api.nvim_win_close( floating, true )
end
end )
it( 'leaves a backwards search alone everywhere', function()
for _, mapping in ipairs( vim.api.nvim_buf_get_keymap( bufnr, 'n' ) ) do
assert.is_not.equal( '?', mapping.lhs )
end
for _, mapping in ipairs( vim.api.nvim_get_keymap 'n' ) do
assert.is_not.equal( '?', mapping.lhs )
end
end )
end )