Something went wrong. Try again.
Library of 45+ independent Lua modules improving Neovim experience with minimal effort nvim-mini.org/mini.nvim
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554local helpers = dofile('tests/helpers.lua')
local child = helpers.new_child_neovim()local expect, eq = helpers.expect, helpers.expect.equalitylocal new_set = MiniTest.new_set
-- Helpers with child processeslocal load_module = function(config) child.mini_load('jump', config) endlocal unload_module = function() child.mini_unload('jump') endlocal reload_module = function(config) child.mini_reload('jump', config) endlocal set_cursor = function(...) return child.set_cursor(...) endlocal get_cursor = function(...) return child.get_cursor(...) endlocal set_lines = function(...) return child.set_lines(...) endlocal get_lines = function(...) return child.get_lines(...) endlocal type_keys = function(...) return child.type_keys(...) endlocal sleep = function(ms) helpers.sleep(ms, child, true) end
-- Data =======================================================================local example_lines = { 'Lorem ipsum dolor sit amet,', 'consectetur adipiscing elit, sed do eiusmod tempor', 'incididunt ut labore et dolore magna aliqua.', '`!@#$%^&*()_+=.,1234567890',}
-- Time constantslocal default_highlight_delay = 250local reminder_delay = 1000local small_time = helpers.get_time_const(10)
-- Output test set ============================================================local T = new_set({ hooks = { pre_case = function() child.setup() load_module() end, post_once = child.stop, }, n_retry = helpers.get_n_retry(2),})
-- Unit tests =================================================================T['setup()'] = new_set()
T['setup()']['creates side effects'] = function() -- Global variable eq(child.lua_get('type(_G.MiniJump)'), 'table')
-- Autocommand group eq(child.fn.exists('#MiniJump'), 1)
-- Highlight groups child.cmd('hi clear') load_module() expect.match(child.cmd_capture('hi MiniJump'), 'links to SpellRare')end
T['setup()']['creates `config` field'] = function() eq(child.lua_get('type(_G.MiniJump.config)'), 'table')
-- Check default values local expect_config = function(field, value) eq(child.lua_get('MiniJump.config.' .. field), value) end
-- Check default values expect_config('delay.highlight', 250) expect_config('delay.idle_stop', 10000000) expect_config('mappings.forward', 'f') expect_config('mappings.backward', 'F') expect_config('mappings.forward_till', 't') expect_config('mappings.backward_till', 'T') expect_config('mappings.repeat_jump', ';') expect_config('silent', false)end
T['setup()']['respects `config` argument'] = function() unload_module() load_module({ delay = { highlight = 500 } }) eq(child.lua_get('MiniJump.config.delay.highlight'), 500)end
T['setup()']['validates `config` argument'] = function() unload_module()
local expect_config_error = function(config, name, target_type) expect.error(function() load_module(config) end, vim.pesc(name) .. '.*' .. vim.pesc(target_type)) end
expect_config_error('a', 'config', 'table') expect_config_error({ delay = 'a' }, 'delay', 'table') expect_config_error({ delay = { highlight = 'a' } }, 'delay.highlight', 'number') expect_config_error({ delay = { idle_stop = 'a' } }, 'delay.idle_stop', 'number') expect_config_error({ mappings = 'a' }, 'mappings', 'table') expect_config_error({ mappings = { forward = 1 } }, 'mappings.forward', 'string') expect_config_error({ mappings = { backward = 1 } }, 'mappings.backward', 'string') expect_config_error({ mappings = { forward_till = 1 } }, 'mappings.forward_till', 'string') expect_config_error({ mappings = { backward_till = 1 } }, 'mappings.backward_till', 'string') expect_config_error({ mappings = { repeat_jump = 1 } }, 'mappings.repeat_jump', 'string') expect_config_error({ silent = 1 }, 'silent', 'boolean')end
T['setup()']['ensures colors'] = function() child.cmd('colorscheme default') expect.match(child.cmd_capture('hi MiniJump'), 'links to SpellRare')end
T['setup()']['properly handles `config.mappings`'] = function() local has_map = function(lhs, pattern) return child.cmd_capture('nmap ' .. lhs):find(pattern) ~= nil end eq(has_map('f', 'Jump'), true)
unload_module() child.api.nvim_del_keymap('n', 'f')
-- Supplying empty string should mean "don't create keymap" load_module({ mappings = { forward = '' } }) eq(has_map('f', 'Jump'), false)end
T['state'] = new_set({ hooks = { pre_case = function() child.lua('MiniJump.stop_jumping()') set_lines({ '1e2e3e4e' }) set_cursor(1, 0) end, },})
local get_state = function() return child.lua_get('MiniJump.state') end
T['state']['has correct initial values'] = function() eq(get_state(), { target = nil, backward = false, till = false, n_times = 1, mode = nil, jumping = false, })end
T['state']['updates `target`'] = function() type_keys('f', 'e') eq(get_state().target, 'e')
child.lua('MiniJump.stop_jumping()') child.lua([[MiniJump.jump('3e')]]) eq(get_state().target, '3e')end
T['state']['updates `backward`'] = function() set_cursor(1, 7) type_keys('F', 'e') eq(get_state().backward, true)
type_keys('f') eq(get_state().backward, false)end
T['state']['updates `till`'] = function() type_keys('t', 'e') eq(get_state().till, true)
type_keys('f') eq(get_state().till, false)end
T['state']['updates `n_times`'] = function() type_keys('2f', 'e') eq(get_state().n_times, 2)end
T['state']['updates `mode`'] = function() type_keys('t', 'e') eq(get_state().mode, 'n') child.lua('MiniJump.stop_jumping()')
type_keys('V', 't', 'e') eq(get_state().mode, 'V') child.ensure_normal_mode()
type_keys('d', 't', 'e') eq(get_state().mode, 'no')
-- Ensure dot-repeat does not update mode after the jump type_keys('V', 't', 'e') eq(get_state().mode, 'V') child.ensure_normal_mode() type_keys('.') eq(get_state().mode, 'V')end
T['state']['updates `jumping`'] = function() type_keys('f', 'e') eq(get_state().jumping, true)
child.lua('MiniJump.stop_jumping()') eq(get_state().jumping, false)end
T['jump()'] = new_set({ hooks = { pre_case = function() set_lines(example_lines) set_cursor(1, 0) end, },})
local validate_jump = function(args, final_cursor_pos) -- Usage of string arguments is needed because there seems to be no way to -- correctly transfer to `child` `nil` values between non-`nil` ones. Like -- `child.lua('MiniJump.jump(...)', {'m', nil, true})`. Gives `Cannot -- convert given lua table` error. child.lua(('MiniJump.jump(%s)'):format(args)) eq(get_cursor(), final_cursor_pos)end
T['jump()']['respects `target` argument'] = function() -- Can not jump by default without recent target expect.match(child.cmd_capture('lua MiniJump.jump()'), 'no recent `target`')
-- Jump to one letter target validate_jump([['m']], { 1, 4 })
-- By default uses latest used value validate_jump('', { 1, 10 })
-- Accepts more than one letter validate_jump([['sit']], { 1, 18 })
-- Accepts non-letters validate_jump([['!']], { 4, 1 }) validate_jump([['1']], { 4, 16 })end
T['jump()']['respects `backward` argument'] = function() -- Jumps forward by default at first jump validate_jump([['d']], { 1, 12 })
-- Can jump backward validate_jump([['m', true]], { 1, 10 })
-- By default uses latest used value validate_jump([['m']], { 1, 4 })end
T['jump()']['respects `till` argument'] = function() -- Jumps on target by default at first jump validate_jump([['m']], { 1, 4 })
-- Can jump till validate_jump([['m', nil, true]], { 1, 9 })
-- By default uses latest used value validate_jump([['m']], { 1, 22 })end
T['jump()']['respects `n_times` argument'] = function() -- Jumps once by default at first jump validate_jump([['m']], { 1, 4 })
-- Can jump multiple times validate_jump([['m', nil, nil, 2]], { 1, 23 })
-- By default uses latest used value validate_jump([['m']], { 2, 46 })end
T['jump()']['allows matches at end of line when `till=true`'] = function() set_lines({ 'aaa', 'b', 'aaa' })
local validate_t = function(start_pos, end_pos) set_cursor(unpack(start_pos)) validate_jump([['b', false, true, 1]], end_pos) end local validate_T = function(start_pos, end_pos) set_cursor(unpack(start_pos)) validate_jump([['b', true, true, 1]], end_pos) end
-- Normal mode when not allowed to put cursor on end of line validate_t({ 1, 0 }, { 1, 2 }) validate_T({ 3, 2 }, { 2, 0 })
-- Visual mode (allowed to put cursor on end of line) type_keys('v') validate_t({ 1, 0 }, { 1, 3 }) child.ensure_normal_mode()
type_keys('v') validate_T({ 3, 2 }, { 2, 1 }) child.ensure_normal_mode()
-- Normal mode when allowed to put cursor on end of line child.o.virtualedit = 'onemore' validate_t({ 1, 0 }, { 1, 3 }) validate_T({ 3, 2 }, { 2, 1 })end
T['jump()']['does not jump if there is no place to jump'] = function() validate_jump([['x']], { 1, 0 }) end
T['jump()']['opens enough folds'] = function() set_lines({ 'a', 'b', 'c', 'd' })
-- Manually create two nested closed folds set_cursor(3, 0) type_keys('zf', 'G') type_keys('zf', 'gg') eq(child.fn.foldlevel(1), 1) eq(child.fn.foldlevel(3), 2) eq(child.fn.foldclosed(2), 1) eq(child.fn.foldclosed(3), 1)
-- Jumping should open just enough folds set_cursor(1, 0) validate_jump([['b']], { 2, 0 }) eq(child.fn.foldclosed(2), -1) eq(child.fn.foldclosed(3), 3)end
T['smart_jump()'] = new_set({ hooks = { pre_case = function() set_lines(example_lines) end, },})
T['smart_jump()']['works'] = function() child.lua_notify('MiniJump.smart_jump()') child.poke_eventloop() type_keys('m') eq(get_cursor(), { 1, 4 })end
-- Integration tests ==========================================================T['Jumping with f/t/F/T'] = new_set()
T['Jumping with f/t/F/T']['works in Normal and Visual modes'] = new_set({ parametrize = { { 'Normal', 'f', { { 1, 2 }, { 1, 5 }, { 2, 5 }, { 3, 2 } } }, { 'Normal', 't', { { 1, 1 }, { 1, 4 }, { 2, 4 }, { 3, 1 } } }, { 'Normal', 'F', { { 3, 5 }, { 3, 2 }, { 2, 2 }, { 1, 5 } } }, { 'Normal', 'T', { { 3, 6 }, { 3, 3 }, { 2, 3 }, { 1, 6 } } },
{ 'Visual', 'f', { { 1, 2 }, { 1, 5 }, { 2, 5 }, { 3, 2 } } }, { 'Visual', 't', { { 1, 1 }, { 1, 4 }, { 2, 4 }, { 3, 1 } } }, { 'Visual', 'F', { { 3, 5 }, { 3, 2 }, { 2, 2 }, { 1, 5 } } }, { 'Visual', 'T', { { 3, 6 }, { 3, 3 }, { 2, 3 }, { 1, 6 } } }, },}, { test = function(test_mode, key, positions) set_lines({ '11e22e__', '33e44e__', '55e66e__' })
local start_pos = key == key:lower() and { 1, 0 } or { 3, 7 } set_cursor(unpack(start_pos))
if test_mode == 'Visual' then type_keys('v') eq(child.fn.mode(), 'v') end
-- First time should jump and start "jumping" mode type_keys(key, 'e') eq(get_cursor(), positions[1])
-- Typing same key should repeat jump type_keys(key) eq(get_cursor(), positions[2])
-- Prepending with `count` should work type_keys('2', key) eq(get_cursor(), positions[3])
-- Typing same key should ignore previous `count` type_keys(key) eq(get_cursor(), positions[4]) end,})
-- NOTE: for some reason it seems to be very important to do cases for-- Operator-pending mode in parametrized form, because this way child process-- is restarted every time. Otherwise it will lead to hanging process somewhere.T['Jumping with f/t/F/T']['works in Operator-pending mode'] = new_set({ parametrize = { { 'f', { '2e3e4e5e_ ', '4e5e_ ', '_ ' } }, { 't', { 'e2e3e4e5e_ ', 'e4e5e_ ', 'e_ ' } }, { 'F', { ' 1e2e3e4e5', ' 1e2e3', ' 1' } }, { 'T', { ' 1e2e3e4e5e', ' 1e2e3e', ' 1e' } }, },}, { test = function(key, line_seq) set_lines({ ' 1e2e3e4e5e_ ' })
local start_col = key == key:lower() and 0 or 12 set_cursor(1, start_col)
-- Apply once type_keys('d', key, 'e') eq(get_lines(), { line_seq[1] })
-- Prepending with `count` should work type_keys('2d', key, 'e') eq(get_lines(), { line_seq[2] })
-- Another prepending with `count` should work type_keys('d', '2', key, 'e') eq(get_lines(), { line_seq[3] })
-- Just typing `key` shouldn't repeat motion local cur_pos = get_cursor() type_keys(key) eq(get_cursor(), cur_pos) -- Stop asking for user input type_keys('<Esc>') end,})
T['Jumping with f/t/F/T']['works in forced Operator-pending mode'] = function() local validate = function(pos, keys, ref_pos, ref_lines) set_lines({ '__e!!', '@@g##', 'xx' }) set_cursor(unpack(pos)) type_keys(keys) eq(get_cursor(), ref_pos) eq(get_lines(), ref_lines) end
validate({ 1, 0 }, 'dvfg', { 1, 0 }, { '##', 'xx' }) validate({ 1, 0 }, 'dvtg', { 1, 0 }, { 'g##', 'xx' }) validate({ 2, 4 }, 'dvFe', { 1, 1 }, { '__', 'xx' }) validate({ 2, 4 }, 'dvTe', { 1, 2 }, { '__e', 'xx' })
validate({ 1, 0 }, 'dVfg', { 1, 0 }, { 'xx' }) validate({ 1, 0 }, 'dVtg', { 1, 0 }, { 'xx' }) validate({ 2, 4 }, 'dVFe', { 1, 1 }, { 'xx' }) validate({ 2, 4 }, 'dVTe', { 1, 1 }, { 'xx' })
validate({ 1, 0 }, 'd<C-v>fg', { 1, 0 }, { '!!', '##', 'xx' }) validate({ 1, 0 }, 'd<C-v>tg', { 1, 0 }, { 'e!!', 'g##', 'xx' }) validate({ 2, 4 }, 'd<C-v>Fe', { 1, 1 }, { '__', '@@', 'xx' }) validate({ 2, 4 }, 'd<C-v>Te', { 1, 2 }, { '__e', '@@g', 'xx' })end
T['Jumping with f/t/F/T']['allows dot-repeat'] = new_set({ parametrize = { { 'f' }, { 't' }, { 'F' }, { 'T' } },}, { test = function(key) -- Start with two equal lines (with enough targets) to check equal effect set_lines({ ' 1e2e3e4e_ ', ' 1e2e3e4e_ ' })
local lines = get_lines() local start_col = key == key:lower() and 0 or lines[1]:len() set_cursor(1, start_col)
type_keys('2d', key, 'e')
-- Immediate dot-repeat type_keys('.')
-- Not immediate dot-repeat set_cursor(2, start_col) type_keys('.', '.')
-- Check equal effect lines = get_lines() eq(lines[1], lines[2]) end,})
T['Jumping with f/t/F/T']['works with multicursor'] = new_set({ parametrize = { { 'f' }, { 't' }, { 'F' }, { 'T' } },}, { test = function(key) if child.fn.has('nvim-0.13') == 0 then MiniTest.skip('Multicursor is available in Neovim>=0.13') end
-- Start with two equal lines (with enough targets) to check equal effect local lines = { ' 1e2e3e4e_ ', ' 1e2e3e4e_ ' } local start_col = key == key:lower() and 0 or lines[1]:len()
-- Normal mode -- - Extra cursor should follow the main cursor local keys = { 'Qjq=', key, 'e' } local col = ({ f = 2, t = 1, F = 8, T = 9 })[key] child.validate_mc_edit(lines, { 1, start_col }, keys, lines, { 2, col }, { { 1, col } })
-- Visual mode -- TODO: Look into making "semantic Visual dot-repeat" fully work here keys = { 'Qj', 'v', key, 'e', 'd' } local data = ({ f = { l = { '2e3e4e_ ', '2e3e4e_ ' }, c = { 2, 0 }, m = { { 1, 0 } } }, t = { l = { 'e2e3e4e_ ', 'e2e3e4e_ ' }, c = { 2, 0 }, m = { { 1, 0 } } }, F = { l = { ' 1e2e3e4', ' 1e2e3e4' }, c = { 2, 7 }, m = { { 1, 7 } } }, T = { l = { ' 1e2e3e4e', ' 1e2e3e4e' }, c = { 2, 8 }, m = { { 1, 8 } } }, })[key] child.validate_mc_edit(lines, { 1, start_col }, keys, data.l, data.c, data.m)
-- Operator-pending keys = { 'Qj', 'd', key, 'e', '.' } data = ({ f = { l = { '3e4e_ ', '3e4e_ ' }, c = { 2, 0 }, m = { { 1, 0 } } }, t = { l = { 'e3e4e_ ', 'e3e4e_ ' }, c = { 2, 0 }, m = { { 1, 0 } } }, F = { l = { ' 1e2e3', ' 1e2e3' }, c = { 2, 5 }, m = { { 1, 5 } } }, T = { l = { ' 1e2e3e', ' 1e2e3e' }, c = { 2, 6 }, m = { { 1, 6 } } }, })[key] child.validate_mc_edit(lines, { 1, start_col }, keys, data.l, data.c, data.m)
-- TODO: Test `zq` when it works with Lua RHS and/or `<Cmd>...<CR>` end,})
T['Jumping with f/t/F/T']['stops jumping when non-jump movement is done'] = function() set_lines({ 'TF', ' 1e2e3e ', 'ft' })
-- General idea: move once, make non-jump movement 'l', test typing `key` -- twice. Can't test once because it should ask for user input and make an -- actual movement to `key` letter. set_cursor(2, 0) type_keys('f', 'e', 'l', 'f', 'f') eq(get_cursor(), { 3, 0 })
set_cursor(2, 0) type_keys('t', 'e', 'l', 't', 't') eq(get_cursor(), { 3, 0 })
set_cursor(2, 7) type_keys('F', 'e', 'l', 'F', 'F') eq(get_cursor(), { 1, 1 })
set_cursor(2, 7) type_keys('T', 'e', 'l', 'T', 'T') eq(get_cursor(), { 1, 1 })end
T['Jumping with f/t/F/T']['stops jumping when leaving buffer'] = function() -- Set up windows and buffers local buf_id_other = child.api.nvim_create_buf(true, false) child.api.nvim_set_current_buf(buf_id_other) child.lua('_G.buf_id_other = ' .. buf_id_other)
child.cmd('vsplit') local buf_id_cur = child.api.nvim_create_buf(true, false) child.api.nvim_set_current_buf(buf_id_cur) set_lines({ '1e2e3e4e' })
-- Should stop if `BufLeave` is for current buffer set_cursor(1, 0) type_keys('f', 'e') eq(child.lua_get('MiniJump.state.jumping'), true)
child.api.nvim_set_current_buf(buf_id_other) eq(child.lua_get('MiniJump.state.jumping'), false)
-- Should not stop if `BufLeave` is for non-current buffer child.api.nvim_set_current_buf(buf_id_cur) type_keys('f', 'e') eq(child.lua_get('MiniJump.state.jumping'), true)
child.lua('vim.api.nvim_buf_call(_G.buf_id_other, function() vim.cmd("doautocmd BufLeave") end)') eq(child.lua_get('MiniJump.state.jumping'), true)end
T['Jumping with f/t/F/T']['works with different mappings'] = function() for _, key in ipairs({ 'f', 't', 'F', 'T' }) do child.api.nvim_del_keymap('n', key) end reload_module({ mappings = { forward = 'gf', backward = 'gF', forward_till = 'gt', backward_till = 'gT' } }) set_lines({ ' 1e2e3e_ ' })
set_cursor(1, 0) type_keys('gf', 'e') eq(get_cursor(), { 1, 2 })
set_cursor(1, 0) type_keys('gt', 'e') eq(get_cursor(), { 1, 1 })
set_cursor(1, 8) type_keys('gF', 'e') eq(get_cursor(), { 1, 6 })
set_cursor(1, 8) type_keys('gT', 'e') eq(get_cursor(), { 1, 7 })end
T['Jumping with f/t/F/T']['allows changing direction during jumping'] = function() set_lines({ ' 1e2e3e_ ' })
-- After typing either one of ftFt, it should enter "jumping" mode, in -- which typing any of the five jump keys (including `;`) jumps around -- present targets. set_cursor(1, 0) type_keys('f', 'e', 't') eq(get_cursor(), { 1, 3 })
set_cursor(1, 0) type_keys('2f', 'e', 'F') eq(get_cursor(), { 1, 2 })
set_cursor(1, 8) type_keys('F', 'e', 'T') eq(get_cursor(), { 1, 5 })
set_cursor(1, 8) type_keys('2F', 'e', 't') eq(get_cursor(), { 1, 5 })
set_cursor(1, 0) type_keys('f', 'e', 'f', 'T', 't', 'F') eq(get_cursor(), { 1, 4 })end
T['Jumping with f/t/F/T']['enters jumping mode even if first jump is impossible'] = function() set_lines({ '1e2e3e' }) set_cursor(1, 0)
-- There is no target in backward direction... type_keys('F', 'e')
-- ...but it still should enter jumping mode because target is present type_keys('f', 'f') eq(get_cursor(), { 1, 3 })end
T['Jumping with f/t/F/T']['does nothing if there is no place to jump'] = function() local validate_single = function(keys, lines, start_pos, ref_mode) set_lines(lines) set_cursor(unpack(start_pos))
type_keys(keys, 'd')
-- It shouldn't move anywhere and should not modify text eq(get_lines(), lines) eq(get_cursor(), start_pos) eq(child.fn.mode(), ref_mode)
-- The above applies to subsequent dot-repeats as well type_keys('.') eq(get_lines(), lines) eq(get_cursor(), start_pos) eq(child.fn.mode(), ref_mode)
-- Ensure there is no jumping child.lua('MiniJump.stop_jumping()') child.ensure_normal_mode() end
local validate = function(lines, pos_forward, pos_backward) validate_single('f', lines, pos_forward, 'n') validate_single('t', lines, pos_forward, 'n') validate_single('F', lines, pos_backward, 'n') validate_single('T', lines, pos_backward, 'n')
validate_single('vf', lines, pos_forward, 'v') validate_single('vt', lines, pos_forward, 'v') validate_single('vF', lines, pos_backward, 'v') validate_single('vT', lines, pos_backward, 'v')
validate_single('df', lines, pos_forward, 'n') validate_single('dt', lines, pos_forward, 'n') validate_single('dF', lines, pos_backward, 'n') validate_single('dT', lines, pos_backward, 'n') end
-- Target is present but not reachable validate({ 'abcdefg' }, { 1, 4 }, { 1, 2 })
-- Target is not present validate({ 'abcxefg' }, { 1, 4 }, { 1, 2 })
-- Target is not present and cursor is on empty line validate({ 'abcxefg', '' }, { 2, 0 }, { 2, 0 })end
T['Jumping with f/t/F/T']['can be dot-repeated if did not jump at first'] = function() -- Normal mode local validate = function(keys, col_1, col_2, line_2) set_lines({ 'abcdefg' }) set_cursor(1, col_1)
type_keys(keys, 'd') eq(get_cursor(), { 1, col_1 }) eq(get_lines(), { 'abcdefg' })
set_cursor(1, col_2) type_keys('.') eq(get_lines(), { line_2 })
-- Ensure there is no jumping child.lua('MiniJump.stop_jumping()') child.ensure_normal_mode() end
validate('df', 5, 1, 'aefg') validate('dt', 5, 1, 'adefg') validate('dF', 1, 5, 'abcg') validate('dT', 1, 5, 'abcdg')end
T['Jumping with f/t/F/T']['inside dot-repeat is not affected by regular jumping'] = function() local validate = function(keys, key_antagonist, result) local line = '_xdxdx1x1xdxdx_' local tests_forward = key_antagonist == string.upper(key_antagonist)
set_lines({ line }) set_cursor(1, tests_forward and 0 or (string.len(line) - 1))
type_keys(keys) type_keys(tests_forward and '$' or '^') type_keys(key_antagonist, '1') type_keys('.') eq(get_lines(), { result })
-- Ensure there is no jumping child.lua('MiniJump.stop_jumping()') child.ensure_normal_mode() end
validate('2dfd', 'T', 'x1x1x_') validate('2dtd', 'F', 'dx1xdx_') validate('2dFd', 't', '_x1x1x') validate('2dTd', 'f', '_xdx1xd')end
T['Jumping with f/t/F/T']['stops prompting for target if hit `<Esc>` or `<C-c>`'] = new_set({ parametrize = { { 'f', '<Esc>' }, { 't', '<Esc>' }, { 'F', '<Esc>' }, { 'T', '<Esc>' }, { 'f', '<C-c>' }, { 't', '<C-c>' }, { 'F', '<C-c>' }, { 'T', '<C-c>' }, },}, { test = function(key, test_key) set_lines({ 'oooo' }) set_cursor(1, 0) -- Here 'o' should act just like Normal mode 'o' -- Wait after every key to poke eventloop type_keys(1, key, test_key, 'o') eq(get_lines(), { 'oooo', '' })
-- Should also work in Operator-pending mode child.ensure_normal_mode() set_lines({ 'oooo' }) set_cursor(1, 0) type_keys(1, 'd', key, test_key, 'o') eq(get_lines(), { 'oooo', '' })
-- <C-c> should stop even if it doesn't make `getcharstr` error if test_key == '<C-c>' then child.ensure_normal_mode() child.cmd('nnoremap <C-c> <C-\\><C-n>') set_lines({ 'ooo\3ooo' }) set_cursor(1, 0) type_keys(1, key, '<C-c>') eq(get_cursor(), { 1, 0 }) end end,})
T['Jumping with f/t/F/T']['ignores current position if it is acceptable target'] = new_set({ parametrize = { { 'f' }, { 't' }, { 'F' }, { 'T' } },}, { test = function(key) set_lines({ 'xxxx' }) local start_col, finish_col = 0, 1 if key ~= key:lower() then start_col, finish_col = 3, 2 end set_cursor(1, start_col)
type_keys(key, 'x') eq(get_cursor(), { 1, finish_col }) end,})
T['Jumping with f/t/F/T']['for t/T allows matches on end of line'] = function() set_lines({ 'aaa', 'b', 'aaa' })
local validate_t = function(start_pos, end_pos) set_cursor(unpack(start_pos)) type_keys('t', 'b') eq(get_cursor(), end_pos) end local validate_T = function(start_pos, end_pos) set_cursor(unpack(start_pos)) type_keys('T', 'b') eq(get_cursor(), end_pos) end
-- Normal mode when not allowed to put cursor on end of line validate_t({ 1, 0 }, { 1, 2 }) validate_T({ 3, 2 }, { 2, 0 })
-- Visual mode (allowed to put cursor on end of line) type_keys('v') validate_t({ 1, 0 }, { 1, 3 }) child.ensure_normal_mode()
type_keys('v') validate_T({ 3, 2 }, { 2, 1 }) child.ensure_normal_mode()
-- Normal mode when allowed to put cursor on end of line child.o.virtualedit = 'onemore' validate_t({ 1, 0 }, { 1, 3 }) validate_T({ 3, 2 }, { 2, 1 })end
T['Jumping with f/t/F/T']['shows reminder after one idle second'] = function() child.set_size(10, 40)
-- Execute one time to test if 'needs help message' flag is set per call set_lines(example_lines) set_cursor(1, 0) type_keys('f', 'e') sleep(0.5 * reminder_delay)
-- Start another jump type_keys('h', 'f') sleep(reminder_delay + small_time) -- Should show colored helper message without adding it to `:messages` and -- causing hit-enter-prompt child.expect_screenshot() eq(child.cmd_capture('1messages'), '')
-- Should clean command line after starting jumping type_keys('m') child.expect_screenshot()end
T['Jumping with f/t/F/T']['stops jumping if no target is found'] = function() set_lines('ooo')
-- General idea: there was a bug which didn't reset jumping state if target -- was not found by `vim.fn.search()`. In that case, next typing of jumping -- key wouldn't make effect, but it should. -- Related test case: 'enters jumping mode even if first jump is impossible' for _, key in ipairs({ 'f', 't', 'F', 'T' }) do local start_col = key == key:lower() and 0 or 3 set_cursor(1, start_col) type_keys(key, 'e', key, 'o') eq(get_cursor(), { 1, 1 }) -- Ensure no jumping mode child.lua('MiniJump.stop_jumping()') endend
T['Jumping with f/t/F/T']['stops jumping on next non-jump movement if no target is found'] = function() local validate = function(key) set_lines({ 'doooe' }) set_cursor(1, 2)
-- Choose a target that is not reachable in the direction local target = key == key:lower() and 'd' or 'e' type_keys(key, target) eq(get_cursor(), { 1, 2 }) eq(get_state().jumping, true)
type_keys('l') expect.no_equality(get_cursor(), { 1, 2 }) eq(get_state().jumping, false) end
validate('f') validate('t') validate('F') validate('T')end
T['Jumping with f/t/F/T']['jumps as far as it can with big `count`'] = function() set_lines({ ' 1e2e3e4e_ ' })
set_cursor(1, 0) type_keys('10f', 'e') eq(get_cursor(), { 1, 8 })
set_cursor(1, 0) type_keys('10t', 'e') eq(get_cursor(), { 1, 7 })
set_cursor(1, 10) type_keys('10F', 'e') eq(get_cursor(), { 1, 2 })
set_cursor(1, 10) type_keys('10T', 'e') eq(get_cursor(), { 1, 3 })end
T['Jumping with f/t/F/T']['respects `vim.{g,b}.minijump_disable`'] = new_set({ parametrize = { { 'g' }, { 'b' } },}, { test = function(var_type) child[var_type].minijump_disable = true set_lines({ '1e2e3e4e' }) set_cursor(1, 0) type_keys('f', 'e') -- `f` does nothing, while `e` jumps to end of word (otherwise it would -- have been `{1, 1}`) eq(get_cursor(), { 1, 7 }) end,})
T['Jumping with f/t/F/T']['respects `config.silent`'] = function() child.lua('MiniJump.config.silent = true') child.set_size(10, 20)
-- Execute one time to test if 'needs help message' flag is set per call set_lines({ '1e2e3e4e' }) set_cursor(1, 0) type_keys('f') sleep(reminder_delay + small_time)
-- Should not show helper message child.expect_screenshot()end
T['Jumping with f/t/F/T']["respects 'ignorecase'"] = function() child.o.ignorecase = true set_lines({ ' 1e2E3E4e_ ' })
set_cursor(1, 0) type_keys('2f', 'E') eq(get_cursor(), { 1, 4 })
set_cursor(1, 0) type_keys('2t', 'E') eq(get_cursor(), { 1, 3 })
set_cursor(1, 10) type_keys('2F', 'E') eq(get_cursor(), { 1, 6 })
set_cursor(1, 10) type_keys('2T', 'E') eq(get_cursor(), { 1, 7 })end
T['Jumping with f/t/F/T']["respects 'smartcase'"] = function() child.o.ignorecase = true child.o.smartcase = true set_lines({ ' 1e2E3E4e_ ' })
set_cursor(1, 0) type_keys('2f', 'E') eq(get_cursor(), { 1, 6 })
set_cursor(1, 0) type_keys('2t', 'E') eq(get_cursor(), { 1, 5 })
set_cursor(1, 10) type_keys('2F', 'E') eq(get_cursor(), { 1, 4 })
set_cursor(1, 10) type_keys('2T', 'E') eq(get_cursor(), { 1, 5 })end
T['Jumping with f/t/F/T']["respects 'selection=exclusive'"] = function() child.o.selection = 'exclusive' set_lines({ ' 1e2e' })
set_cursor(1, 0) type_keys('v', 'f', 'e') eq({ child.fn.col('v'), child.fn.col('.') }, { 1, 4 })
type_keys('d') eq(get_lines(), { '2e' })end
T['Jumping with f/t/F/T']['can be used with `:normal-range`'] = function() -- Basically, it should check that jumping state is restarted even outside of -- `CursorMoved` event (which is not issued in this case) set_lines({ '11e22e', '11e22e', '11e22e' }) set_cursor(1, 0) type_keys('vip', ':normal fefx<CR>') eq(get_lines(), { '11e22', '11e22', '11e22' })end
T['Repeat jump with ;'] = new_set()
T['Repeat jump with ;']['works'] = function() set_lines({ ' 1e2e3e4e_ ' })
set_cursor(1, 0) type_keys('f', 'e', ';') eq(get_cursor(), { 1, 4 })
set_cursor(1, 0) type_keys('t', 'e', ';') eq(get_cursor(), { 1, 3 })
set_cursor(1, 10) type_keys('F', 'e', ';') eq(get_cursor(), { 1, 6 })
set_cursor(1, 10) type_keys('T', 'e', ';') eq(get_cursor(), { 1, 7 })end
-- Other tests are done with 'f' in hope that others keys act the sameT['Repeat jump with ;']['works in Normal and Visual mode'] = new_set({ parametrize = { { 'Normal' }, { 'Visual' } },}, { test = function(test_mode) set_lines({ '1e2e3e4e' })
if test_mode == 'Visual' then type_keys('v') eq(child.fn.mode(), 'v') end
-- Repeats simple motion set_cursor(1, 0) type_keys('f', 'e', ';') eq(get_cursor(), { 1, 3 })
-- Repeats not immediately set_cursor(1, 0) type_keys(';') eq(get_cursor(), { 1, 1 })
-- Repeats with `count` set_cursor(1, 0) type_keys('2f', 'e', ';') eq(get_cursor(), { 1, 7 }) end,})
T['Repeat jump with ;']['works after jump in Operator-pending mode'] = function() -- It doesn't repeat actual operation, just performs same jump set_lines({ '1e2e3e4e5e' }) set_cursor(1, 0)
type_keys('d', 'f', 'e', ';') eq(get_lines(), { '2e3e4e5e' }) eq(get_cursor(), { 1, 1 })
-- It jumps preserving `count` set_lines({ '1e2e3e4e5e' }) set_cursor(1, 0)
type_keys('d', '2f', 'e', ';') eq(get_lines(), { '3e4e5e' }) eq(get_cursor(), { 1, 3 })
-- Should not use the latest dot repeat (like in `nvim --clean`) set_lines({ '1e2e__3e4e5e6e' }) set_cursor(1, 0)
type_keys('d', '2f', 'e') eq(get_lines(), { '__3e4e5e6e' }) eq(get_cursor(), { 1, 0 })
type_keys('$', 'T', '_') eq(get_lines(), { '__3e4e5e6e' }) eq(get_cursor(), { 1, 2 })
-- - Should reuse initial Operator-pending mode state and not the latest one type_keys('.') eq(get_lines(), { '__5e6e' }) eq(get_cursor(), { 1, 2 })
-- - The latest one should still be preserved for regular jumping type_keys(';') eq(get_lines(), { '__5e6e' }) eq(get_cursor(), { 1, 1 })end
T['Repeat jump with ;']['works in Operator-pending mode'] = function() set_lines({ '1e2e3e4e5e_' }) set_cursor(1, 0)
-- Should repeat without asking for target type_keys('f', 'e', 'd', ';') eq(get_lines(), { '13e4e5e_' }) eq(get_cursor(), { 1, 1 })
-- Should work with dot-repeat as in `nvim --clean`, i.e. use target from the -- latest jump, as `;` is exactly for that type_keys('.') eq(get_lines(), { '14e5e_' }) eq(get_cursor(), { 1, 1 })
type_keys('f', '_', '^') type_keys('.') eq(get_lines(), { '' }) eq(get_cursor(), { 1, 0 })end
T['Repeat jump with ;']['works with multicursor'] = function() if child.fn.has('nvim-0.13') == 0 then MiniTest.skip('Multicursor is available in Neovim>=0.13') end
-- Start with two equal lines (with enough targets) to check equal effect local lines = { ' 1e2e3e4e_ ', ' 1e2e3e4e_ ' }
-- Normal mode child.validate_mc_edit(lines, { 1, 0 }, { 'Qjq=', 'f', 'e', ';' }, lines, { 2, 4 }, { { 1, 4 } })
-- Visual mode local keys = { 'Qjq=', 'f', 'e', 'v', ';', 'd' } child.validate_mc_edit(lines, { 1, 0 }, keys, { ' 13e4e_ ', ' 13e4e_ ' }, { 2, 2 }, { { 1, 2 } })
-- Operator-pending keys = { 'Qjq=', 'f', 'e', 'd', ';' } child.validate_mc_edit(lines, { 1, 0 }, keys, { ' 13e4e_ ', ' 13e4e_ ' }, { 2, 2 }, { { 1, 2 } })
-- TODO: Test `zq` when it works with Lua RHS and/or `<Cmd>...<CR>`end
T['Repeat jump with ;']['works with different mapping'] = function() child.api.nvim_del_keymap('n', ';') reload_module({ mappings = { repeat_jump = 'g;' } })
set_lines({ '1e2e' }) type_keys('f', 'e', 'g;') eq(get_cursor(), { 1, 3 })end
T['Repeat jump with ;']['works not immediately after failed first jump'] = function() set_lines({ 'aaa' }) set_cursor(1, 0) type_keys('f', 'e') eq(get_cursor(), { 1, 0 })
set_lines({ 'aaa', 'eee' }) set_cursor(1, 0) type_keys(';') eq(get_cursor(), { 2, 0 })end
T['Repeat jump with ;']['respects `vim.{g,b}.minijump_disable`'] = new_set({ parametrize = { { 'g' }, { 'b' } },}, { test = function(var_type) set_lines({ '1e2e3e4e' }) set_cursor(1, 0) type_keys('f', 'e')
child[var_type].minijump_disable = true type_keys(';') eq(get_cursor(), { 1, 1 }) end,})
T['Delayed highlighting'] = new_set({ hooks = { pre_case = function() set_lines({ '1e2e', 'e4e5e_' }) child.set_size(5, 12) end, },})
-- NOTE: Don't use `'f', 't', 'F', 'T'` as parameters because this will lead to-- conflicting file names for reference screenshots in case-insensitive OST['Delayed highlighting']['works'] = new_set( { parametrize = { { 'forward' }, { 'forward_till' }, { 'backward' }, { 'backward_till' } } }, { test = function(direction) local key = vim.endswith(direction, '_till') and 't' or 'f' key = vim.startswith(direction, 'backward') and key:upper() or key
set_cursor(1, key == key:lower() and 0 or 3) type_keys(key, 'e')
sleep(default_highlight_delay - small_time) -- Nothing should yet be shown child.expect_screenshot() sleep(small_time) -- Everything should be shown child.expect_screenshot() end, })
T['Delayed highlighting']['respects `config.delay.highlight`'] = new_set( { parametrize = { { 'forward' }, { 'forward_till' }, { 'backward' }, { 'backward_till' } } }, { test = function(direction) local key = vim.endswith(direction, '_till') and 't' or 'f' key = vim.startswith(direction, 'backward') and key:upper() or key
local new_highlight_delay = 5 * small_time child.lua('MiniJump.config.delay.highlight = ' .. new_highlight_delay)
set_cursor(1, key == key:lower() and 0 or 3) type_keys(key, 'e')
sleep(new_highlight_delay - small_time) -- Nothing should yet be shown child.expect_screenshot() sleep(small_time) -- Everything should be shown child.expect_screenshot() end, })
T['Delayed highlighting']['respects `vim.b.minijump_config`'] = function() child.lua('MiniJump.config.delay.highlight = ' .. (5 * small_time)) local new_highlight_delay = 3 * small_time child.b.minijump_config = { delay = { highlight = new_highlight_delay } }
set_cursor(1, 0) type_keys('f', 'e')
sleep(new_highlight_delay - small_time) -- Nothing should yet be shown child.expect_screenshot() sleep(small_time) -- Everything should be shown child.expect_screenshot()end
T['Delayed highlighting']['implements debounce-style delay'] = function() set_lines('1e2e3e') set_cursor(1, 0)
type_keys('f', 'e') sleep(default_highlight_delay - small_time) -- Nothing should yet be shown child.expect_screenshot()
type_keys('f') sleep(default_highlight_delay - small_time) -- Nothing should yet be shown (because debounce-style) child.expect_screenshot()
sleep(small_time) -- Everything should be shown child.expect_screenshot()end
T['Delayed highlighting']['stops immediately when not jumping'] = function() type_keys('f', 'e') sleep(default_highlight_delay) -- Should be highlighted child.expect_screenshot()
type_keys('l') -- Should stop highlighting immediately child.expect_screenshot()end
T['Delayed highlighting']['updates immediately within same jumping'] = function() set_lines({ 'e1e2', 'ee' })
set_cursor(1, 0) type_keys('f', 'e')
sleep(default_highlight_delay) child.expect_screenshot() type_keys('t') child.expect_screenshot() type_keys('T') -- Last `T` match is highlighted because there is an end of line after it child.expect_screenshot()end
T['Delayed highlighting']['never highlights in Insert mode'] = function() child.set_size(5, 15)
set_lines({ '1e2f' })
set_cursor(1, 0) type_keys('f', 'e')
sleep(default_highlight_delay) child.expect_screenshot()
type_keys('ct', 'f') sleep(default_highlight_delay + small_time) -- Shouldn't start highlighting child.expect_screenshot()end
T['Delayed highlighting']['done only if actually jumping'] = function() child.lua('MiniJump.config.delay.highlight = 0')
-- Mock conditions for automatically stopping jumping child.lua([[ local force_jump_stop = vim.schedule_wrap(function(ev) vim.cmd('doautocmd BufLeave') end) vim.api.nvim_create_autocmd('CursorMoved', { once = true, callback = force_jump_stop }) ]])
set_cursor(1, 0) type_keys('f', 'e')
eq(child.lua_get('MiniJump.state.jumping'), false) -- Nothing should be shown child.expect_screenshot()end
T['Delayed highlighting']["respects 'ignorecase'"] = function() child.o.ignorecase = true set_lines({ '1e2E' })
set_cursor(1, 0) type_keys('f', 'e')
sleep(default_highlight_delay) -- Should highlight both 'e'and 'E' child.expect_screenshot()end
T['Delayed highlighting']["respects 'smartcase'"] = function() child.o.ignorecase = true child.o.smartcase = true set_lines({ '1e2E3e4E' })
set_cursor(1, 0) type_keys('f', 'E')
sleep(default_highlight_delay) -- Should highlight only 'E' child.expect_screenshot()end
T['Stop jumping after idle'] = new_set({ hooks = { pre_case = function() child.lua('MiniJump.config.delay.idle_stop = ' .. (default_highlight_delay + 2 * small_time)) set_lines({ '1e2e3e4e', 'ff' }) set_cursor(1, 0) child.set_size(5, 12) end, },})
T['Stop jumping after idle']['works'] = function() local idle_stop_delay = child.lua_get('MiniJump.config.delay.idle_stop') type_keys('f', 'e') eq(get_cursor(), { 1, 1 })
-- It works sleep(idle_stop_delay - small_time) type_keys('f') eq(get_cursor(), { 1, 3 }) -- Should highlight (as idle delay is bigger than highlight delay) child.expect_screenshot()
-- It implements debounce-style delay sleep(idle_stop_delay + small_time) -- It should have stopped jumping and this should initiate new jump type_keys('f', 'f') eq(get_cursor(), { 2, 0 }) -- Should also stop highlighting child.expect_screenshot()end
T['Stop jumping after idle']['works if should be done before target highlighting'] = function() child.lua('MiniJump.config.delay.idle_stop = ' .. (default_highlight_delay - small_time))
type_keys('f', 'e') eq(get_cursor(), { 1, 1 }) sleep(default_highlight_delay + small_time) -- Should also not trigger highlighting child.expect_screenshot()end
T['Stop jumping after idle']['respects `vim.b.minijump_config`'] = function() local idle_stop_delay = child.lua_get('MiniJump.config.delay.idle_stop') local new_idle_stop_delay = idle_stop_delay - 2 * small_time child.b.minijump_config = { delay = { idle_stop = new_idle_stop_delay } } type_keys('f', 'e') sleep(new_idle_stop_delay)
-- It should have stopped jumping and this should initiate new jump type_keys('f', 'f') eq(get_cursor(), { 2, 0 })end
T['Events'] = new_set({ hooks = { pre_case = function() child.lua([[ _G.log = {} local pattern = { 'MiniJumpGetTarget', 'MiniJumpStart', 'MiniJumpJump', 'MiniJumpStop' } local add_to_log = function(ev) table.insert(_G.log, { event = ev.match, data = ev.data, state = vim.deepcopy(MiniJump.state) }) end vim.api.nvim_create_autocmd('User', { pattern = pattern, callback = add_to_log }) ]])
set_lines({ '11e22e__', '33e44e__', '55e66e__' }) end, },})
local validate_log_and_clean = function(ref_log) eq(child.lua_get('_G.log'), ref_log) child.lua('_G.log = {}')end
T['Events']['work'] = function() local state = { mode = 'n', jumping = false, backward = false, till = false, n_times = 1 } type_keys('f') validate_log_and_clean({ { event = 'MiniJumpGetTarget', state = state } })
type_keys('e') state.jumping, state.target = true, 'e' validate_log_and_clean({ { event = 'MiniJumpStart', state = state }, { event = 'MiniJumpJump', state = state }, })
local validate_key = function(keys, ref_backward, ref_till) state.backward, state.till = ref_backward, ref_till type_keys(keys) validate_log_and_clean({ { event = 'MiniJumpJump', state = state } }) end validate_key('f', false, false) validate_key('F', true, false) validate_key('t', false, true) validate_key('T', true, true)
state.backward, state.till, state.n_times = false, false, 2 type_keys('2f') validate_log_and_clean({ { event = 'MiniJumpJump', state = state } })
child.lua('MiniJump.stop_jumping()') state.jumping = false validate_log_and_clean({ { event = 'MiniJumpStop', state = state } })end
T['Events']['work in Visual and Operator-pending modes'] = function() local validate = function(mode, ref_init_target) local state = { mode = mode, jumping = false, backward = false, till = false, n_times = 1 } state.target = ref_init_target
local mode_key = mode == 'v' and 'v' or 'd' type_keys(mode_key, 'f') validate_log_and_clean({ { event = 'MiniJumpGetTarget', state = state } })
type_keys('e') state.mode = mode == 'v' and 'v' or 'no' state.jumping, state.target = true, 'e' validate_log_and_clean({ { event = 'MiniJumpStart', state = state }, { event = 'MiniJumpJump', state = state }, })
child.lua('MiniJump.stop_jumping()') state.jumping = false validate_log_and_clean({ { event = 'MiniJumpStop', state = state } })
type_keys('<Esc>') end
-- Visual mode validate('v', nil)
-- Operator-pending mode. In `state` target is preserved as it is cached for -- possible future `;`. validate('no', 'e')end
T['Events']['work for automatic jump stop'] = function() -- Moving cursor outside of jumping type_keys('f', 'e') child.lua('_G.log = {}')
type_keys('l') local state = { target = 'e', mode = 'n', jumping = false, backward = false, till = false, n_times = 1 } validate_log_and_clean({ { event = 'MiniJumpStop', state = state } })
-- Enter Insert mode type_keys('f', 'e') child.lua('_G.log = {}')
type_keys('i') validate_log_and_clean({ { event = 'MiniJumpStop', state = state } }) type_keys('<Esc>')
-- Idle stop local idle_stop = 10 * small_time child.lua('MiniJump.config.delay.idle_stop = ' .. idle_stop) type_keys('f', 'e') child.lua('_G.log = {}')
sleep(idle_stop - small_time) validate_log_and_clean({}) sleep(small_time + small_time) validate_log_and_clean({ { event = 'MiniJumpStop', state = state } })end
T['Events']['have up to date state before asking for target'] = function() local validate = function(keys, ref_state) type_keys(keys) validate_log_and_clean({ { event = 'MiniJumpGetTarget', state = ref_state } }) type_keys('<Esc>', '<Esc>') end
local state = { mode = 'n', jumping = false, backward = false, till = false, n_times = 1 } validate('f', state)
state.n_times = 2 validate('2f', state) state.n_times = 1
state.mode, state.backward, state.till = 'v', true, false validate('vF', state)
state.mode, state.backward, state.till = 'no', false, true validate('dt', state)end
T['Events']['work during repeat with `;`'] = function() type_keys('f', 'e') child.lua('MiniJump.stop_jumping()') child.lua('_G.log = {}')
eq(child.lua_get('MiniJump.state.jumping'), false)
local state = { mode = 'n', jumping = true, target = 'e', backward = false, till = false, n_times = 1 } type_keys(';') validate_log_and_clean({ { event = 'MiniJumpStart', state = state }, { event = 'MiniJumpJump', state = state }, })
type_keys(';') validate_log_and_clean({ { event = 'MiniJumpJump', state = state } })
type_keys('T') state.backward, state.till = true, true validate_log_and_clean({ { event = 'MiniJumpJump', state = state } })
type_keys(';') validate_log_and_clean({ { event = 'MiniJumpJump', state = state } })end
T['Events']['work with dot-repeat'] = function() type_keys('df', 'e') child.lua('MiniJump.stop_jumping()') child.lua('_G.log = {}')
type_keys('.') local state = { mode = 'no', jumping = true, target = 'e', backward = false, till = false, n_times = 1 } validate_log_and_clean({ { event = 'MiniJumpStart', state = state }, { event = 'MiniJumpJump', state = state }, })end
return T