2015-06-27 19:18:51 -07:00
|
|
|
-- ShaDa history saving/reading support
|
2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2024-04-08 02:03:20 -07:00
|
|
|
local t_shada = require('test.functional.shada.testutil')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
|
|
|
local nvim_command, fn, api, nvim_feed, eq = n.command, n.fn, n.api, n.feed, t.eq
|
|
|
|
local assert_alive = n.assert_alive
|
|
|
|
local expect_exit = n.expect_exit
|
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local reset, clear = t_shada.reset, t_shada.clear
|
2015-06-27 19:18:51 -07:00
|
|
|
|
|
|
|
describe('ShaDa support code', function()
|
|
|
|
before_each(reset)
|
|
|
|
after_each(clear)
|
|
|
|
|
|
|
|
it('is able to dump and read back command-line history', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0")
|
2015-06-27 19:18:51 -07:00
|
|
|
nvim_feed(':" Test\n')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-06-27 19:18:51 -07:00
|
|
|
reset()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0")
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('" Test', fn.histget(':', -1))
|
2015-06-27 19:18:51 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('is able to dump and read back 2 items in command-line history', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0 history=2")
|
2015-06-27 19:18:51 -07:00
|
|
|
nvim_feed(':" Test\n')
|
|
|
|
nvim_feed(':" Test 2\n')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-06-27 19:18:51 -07:00
|
|
|
reset()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0 history=2")
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('" Test 2', fn.histget(':', -1))
|
|
|
|
eq('" Test', fn.histget(':', -2))
|
2015-06-27 19:18:51 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('respects &history when dumping', function()
|
|
|
|
nvim_command("set shada='0 history=1")
|
2015-06-27 19:18:51 -07:00
|
|
|
nvim_feed(':" Test\n')
|
|
|
|
nvim_feed(':" Test 2\n')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-06-27 19:18:51 -07:00
|
|
|
reset()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0 history=2")
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('" Test 2', fn.histget(':', -1))
|
|
|
|
eq('', fn.histget(':', -2))
|
2015-06-27 19:18:51 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('respects &history when loading', function()
|
|
|
|
nvim_command("set shada='0 history=2")
|
2015-06-27 19:18:51 -07:00
|
|
|
nvim_feed(':" Test\n')
|
|
|
|
nvim_feed(':" Test 2\n')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-06-27 19:18:51 -07:00
|
|
|
reset()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0 history=1")
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('" Test 2', fn.histget(':', -1))
|
|
|
|
eq('', fn.histget(':', -2))
|
2015-06-27 19:18:51 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps only requested amount of command-line history items', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0,:1")
|
2015-06-27 19:18:51 -07:00
|
|
|
nvim_feed(':" Test\n')
|
|
|
|
nvim_feed(':" Test 2\n')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-07-10 10:53:34 -07:00
|
|
|
-- Regression test: :wshada should not alter or free history.
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('" Test 2', fn.histget(':', -1))
|
|
|
|
eq('" Test', fn.histget(':', -2))
|
2015-06-27 19:18:51 -07:00
|
|
|
reset()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0")
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('" Test 2', fn.histget(':', -1))
|
|
|
|
eq('', fn.histget(':', -2))
|
2015-06-27 19:18:51 -07:00
|
|
|
end)
|
|
|
|
|
2015-07-05 16:26:44 -07:00
|
|
|
it('does not respect number in &shada when loading history', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0")
|
2015-06-27 19:18:51 -07:00
|
|
|
nvim_feed(':" Test\n')
|
|
|
|
nvim_feed(':" Test 2\n')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-06-27 19:18:51 -07:00
|
|
|
reset()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='0,:1")
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('" Test 2', fn.histget(':', -1))
|
|
|
|
eq('" Test', fn.histget(':', -2))
|
2015-06-27 19:18:51 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps and loads all kinds of histories', function()
|
|
|
|
nvim_command('debuggreedy')
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_feed(':debug echo "Test"\n" Test 2\nc\n') -- Debug history.
|
|
|
|
nvim_feed(':call input("")\nTest 2\n') -- Input history.
|
|
|
|
nvim_feed('"="Test"\nyy') -- Expression history.
|
|
|
|
nvim_feed('/Test\n') -- Search history
|
|
|
|
nvim_feed(':" Test\n') -- Command-line history
|
2015-06-27 19:18:51 -07:00
|
|
|
nvim_command('0debuggreedy')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-06-27 19:18:51 -07:00
|
|
|
reset()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('" Test', fn.histget(':', -1))
|
|
|
|
eq('Test', fn.histget('/', -1))
|
|
|
|
eq('"Test"', fn.histget('=', -1))
|
|
|
|
eq('Test 2', fn.histget('@', -1))
|
|
|
|
eq('c', fn.histget('>', -1))
|
2015-06-27 19:18:51 -07:00
|
|
|
end)
|
2015-06-27 21:36:51 -07:00
|
|
|
|
|
|
|
it('dumps and loads last search pattern with offset', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('wrapscan', false, {})
|
|
|
|
fn.setline('.', { 'foo', 'bar--' })
|
2015-06-27 21:36:51 -07:00
|
|
|
nvim_feed('gg0/a/e+1\n')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 0, 2, 3, 0 }, fn.getpos('.'))
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-06-27 21:36:51 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('wrapscan', false, {})
|
|
|
|
fn.setline('.', { 'foo', 'bar--' })
|
2015-06-27 21:36:51 -07:00
|
|
|
nvim_feed('gg0n')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 0, 2, 3, 0 }, fn.getpos('.'))
|
|
|
|
eq(1, api.nvim_get_vvar('searchforward'))
|
2024-05-22 18:10:16 -07:00
|
|
|
-- Autocommands shouldn't cause search pattern to change
|
|
|
|
nvim_command('autocmd User * :')
|
|
|
|
nvim_command('doautocmd User')
|
|
|
|
nvim_feed('gg0n')
|
|
|
|
eq({ 0, 2, 3, 0 }, fn.getpos('.'))
|
|
|
|
eq(1, api.nvim_get_vvar('searchforward'))
|
2015-11-01 11:26:53 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('dumps and loads last search pattern with offset and backward direction', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('wrapscan', false, {})
|
|
|
|
fn.setline('.', { 'foo', 'bar--' })
|
2015-11-01 11:26:53 -07:00
|
|
|
nvim_feed('G$?a?e+1\n')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 0, 2, 3, 0 }, fn.getpos('.'))
|
2015-11-01 11:26:53 -07:00
|
|
|
nvim_command('wshada')
|
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('wrapscan', false, {})
|
|
|
|
fn.setline('.', { 'foo', 'bar--' })
|
2015-11-01 11:26:53 -07:00
|
|
|
nvim_feed('G$n')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 0, 2, 3, 0 }, fn.getpos('.'))
|
|
|
|
eq(0, api.nvim_get_vvar('searchforward'))
|
2024-05-22 18:10:16 -07:00
|
|
|
-- Autocommands shouldn't cause search pattern to change
|
|
|
|
nvim_command('autocmd User * :')
|
|
|
|
nvim_command('doautocmd User')
|
|
|
|
nvim_feed('G$n')
|
|
|
|
eq({ 0, 2, 3, 0 }, fn.getpos('.'))
|
|
|
|
eq(0, api.nvim_get_vvar('searchforward'))
|
2015-06-27 21:36:51 -07:00
|
|
|
end)
|
|
|
|
|
2015-07-07 13:05:01 -07:00
|
|
|
it('saves v:hlsearch=1', function()
|
2015-08-23 09:41:00 -07:00
|
|
|
nvim_command('set hlsearch shada-=h')
|
2015-07-07 13:05:01 -07:00
|
|
|
nvim_feed('/test\n')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_get_vvar('hlsearch'))
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-07-07 13:05:01 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_get_vvar('hlsearch'))
|
2015-07-07 13:05:01 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('saves v:hlsearch=0 with :nohl', function()
|
2015-08-23 09:41:00 -07:00
|
|
|
nvim_command('set hlsearch shada-=h')
|
2015-07-07 13:05:01 -07:00
|
|
|
nvim_feed('/test\n')
|
|
|
|
nvim_command('nohlsearch')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-07-07 13:05:01 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_vvar('hlsearch'))
|
2015-07-07 13:05:01 -07:00
|
|
|
end)
|
|
|
|
|
2015-08-23 09:41:00 -07:00
|
|
|
it('saves v:hlsearch=0 with default &shada', function()
|
|
|
|
nvim_command('set hlsearch')
|
2015-07-07 13:05:01 -07:00
|
|
|
nvim_feed('/test\n')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_get_vvar('hlsearch'))
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-07-07 13:05:01 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, api.nvim_get_vvar('hlsearch'))
|
2015-07-07 13:05:01 -07:00
|
|
|
end)
|
|
|
|
|
2015-06-27 21:36:51 -07:00
|
|
|
it('dumps and loads last substitute pattern and replacement string', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline('.', { 'foo', 'bar' })
|
2015-06-27 21:36:51 -07:00
|
|
|
nvim_command('%s/f/g/g')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('goo', fn.getline(1))
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-06-27 21:36:51 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline('.', { 'foo', 'bar' })
|
2015-06-27 21:36:51 -07:00
|
|
|
nvim_command('&')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('goo', fn.getline(1))
|
2015-06-27 21:36:51 -07:00
|
|
|
end)
|
2015-07-05 07:24:02 -07:00
|
|
|
|
2015-09-14 04:10:51 -07:00
|
|
|
it('dumps and loads history with UTF-8 characters', function()
|
2015-07-05 07:24:02 -07:00
|
|
|
reset()
|
|
|
|
nvim_feed(':echo "«"\n')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-07-05 07:24:02 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('echo "«"', fn.histget(':', -1))
|
2015-07-05 07:24:02 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('dumps and loads replacement with UTF-8 characters', function()
|
2015-09-14 04:10:51 -07:00
|
|
|
nvim_command('substitute/./«/ge')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall!')
|
2015-07-05 07:24:02 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline('.', { '.' })
|
2015-07-05 07:24:02 -07:00
|
|
|
nvim_command('&')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('«', fn.getline('.'))
|
2015-07-05 07:24:02 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('dumps and loads substitute pattern with UTF-8 characters', function()
|
2015-09-14 04:10:51 -07:00
|
|
|
nvim_command('substitute/«/./ge')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall!')
|
2015-07-05 07:24:02 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline('.', { '«\171' })
|
2015-07-05 07:24:02 -07:00
|
|
|
nvim_command('&')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('.\171', fn.getline('.'))
|
2015-07-05 07:24:02 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('dumps and loads search pattern with UTF-8 characters', function()
|
2015-09-14 04:10:51 -07:00
|
|
|
nvim_command('silent! /«/')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=/0')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall!')
|
2015-07-05 07:24:02 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline('.', { '\171«' })
|
2015-07-05 07:24:02 -07:00
|
|
|
nvim_command('~&')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('\171', fn.getline('.'))
|
|
|
|
eq('', fn.histget('/', -1))
|
2015-07-05 07:24:02 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('dumps and loads search pattern with 8-bit single-byte', function()
|
2015-07-05 07:24:02 -07:00
|
|
|
-- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1
|
2015-09-14 04:10:51 -07:00
|
|
|
nvim_command('silent! /\171/')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('set shada+=/0')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall!')
|
2015-07-05 07:24:02 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline('.', { '\171«' })
|
2015-07-05 07:24:02 -07:00
|
|
|
nvim_command('~&')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('«', fn.getline('.'))
|
|
|
|
eq('', fn.histget('/', -1))
|
2015-07-05 07:24:02 -07:00
|
|
|
end)
|
2015-09-14 04:10:51 -07:00
|
|
|
|
2019-09-07 18:02:29 -07:00
|
|
|
it('does not crash when dumping last search pattern (#10945)', function()
|
|
|
|
nvim_command('edit Xtest-functional-shada-history_spec')
|
|
|
|
-- Save jump list
|
|
|
|
nvim_command('wshada')
|
|
|
|
-- Wipe out buffer list (jump list entry gets removed)
|
|
|
|
nvim_command('%bwipeout')
|
|
|
|
-- Restore jump list
|
|
|
|
nvim_command('rshada')
|
|
|
|
nvim_command('silent! /pat/')
|
|
|
|
nvim_command('au BufNew * echo')
|
|
|
|
nvim_command('wshada')
|
|
|
|
end)
|
|
|
|
|
2020-07-31 07:08:34 -07:00
|
|
|
it('does not crash when number of history save to zero (#11497)', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='10")
|
2020-07-31 07:08:34 -07:00
|
|
|
nvim_feed(':" Test\n')
|
|
|
|
nvim_command('wshada')
|
2024-01-02 18:09:18 -07:00
|
|
|
nvim_command("set shada='10,:0")
|
2020-07-31 07:08:34 -07:00
|
|
|
nvim_command('wshada')
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2020-07-31 07:08:34 -07:00
|
|
|
end)
|
2015-06-27 19:18:51 -07:00
|
|
|
end)
|