aboutsummaryrefslogtreecommitdiff
path: root/test/functional/shada/history_spec.lua
blob: b73a39f116c33939e9fc414fb37de7cdb0326b42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
-- ShaDa history saving/reading support
local helpers = require('test.functional.helpers')
local nvim, nvim_command, nvim_eval, nvim_feed, eq =
  helpers.nvim, helpers.command, helpers.eval, helpers.feed, helpers.eq

local shada_helpers = require('test.functional.shada.helpers')
local reset, set_additional_cmd, clear =
  shada_helpers.reset, shada_helpers.set_additional_cmd,
  shada_helpers.clear

describe('ShaDa support code', function()
  before_each(reset)
  after_each(clear)

  it('is able to dump and read back command-line history', function()
    nvim_command('set viminfo=\'0')
    nvim_feed(':" Test\n')
    nvim_command('wviminfo')
    reset()
    nvim_command('set viminfo=\'0')
    nvim_command('rviminfo')
    eq('" Test', nvim_eval('histget(":", -1)'))
  end)

  it('is able to dump and read back 2 items in command-line history', function()
    nvim_command('set viminfo=\'0 history=2')
    nvim_feed(':" Test\n')
    nvim_feed(':" Test 2\n')
    nvim_command('qall')
    reset()
    nvim_command('set viminfo=\'0 history=2')
    nvim_command('rviminfo')
    eq('" Test 2', nvim_eval('histget(":", -1)'))
    eq('" Test', nvim_eval('histget(":", -2)'))
    nvim_command('qall')
  end)

  it('respects &history when dumping',
  function()
    nvim_command('set viminfo=\'0 history=1')
    nvim_feed(':" Test\n')
    nvim_feed(':" Test 2\n')
    nvim_command('wviminfo')
    reset()
    nvim_command('set viminfo=\'0 history=2')
    nvim_command('rviminfo')
    eq('" Test 2', nvim_eval('histget(":", -1)'))
    eq('', nvim_eval('histget(":", -2)'))
  end)

  it('respects &history when loading',
  function()
    nvim_command('set viminfo=\'0 history=2')
    nvim_feed(':" Test\n')
    nvim_feed(':" Test 2\n')
    nvim_command('wviminfo')
    reset()
    nvim_command('set viminfo=\'0 history=1')
    nvim_command('rviminfo')
    eq('" Test 2', nvim_eval('histget(":", -1)'))
    eq('', nvim_eval('histget(":", -2)'))
  end)

  it('dumps only requested amount of command-line history items', function()
    nvim_command('set viminfo=\'0,:1')
    nvim_feed(':" Test\n')
    nvim_feed(':" Test 2\n')
    nvim_command('wviminfo')
    reset()
    nvim_command('set viminfo=\'0')
    nvim_command('rviminfo')
    eq('" Test 2', nvim_eval('histget(":", -1)'))
    eq('', nvim_eval('histget(":", -2)'))
  end)

  it('does not respect number in &viminfo when loading history', function()
    nvim_command('set viminfo=\'0')
    nvim_feed(':" Test\n')
    nvim_feed(':" Test 2\n')
    nvim_command('wviminfo')
    reset()
    nvim_command('set viminfo=\'0,:1')
    nvim_command('rviminfo')
    eq('" Test 2', nvim_eval('histget(":", -1)'))
    eq('" Test', nvim_eval('histget(":", -2)'))
  end)

  it('dumps and loads all kinds of histories', function()
    nvim_command('debuggreedy')
    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
    nvim_command('0debuggreedy')
    nvim_command('wviminfo')
    reset()
    nvim_command('rviminfo')
    eq('" Test', nvim_eval('histget(":", -1)'))
    eq('Test', nvim_eval('histget("/", -1)'))
    eq('"Test"', nvim_eval('histget("=", -1)'))
    eq('Test 2', nvim_eval('histget("@", -1)'))
    eq('c', nvim_eval('histget(">", -1)'))
  end)
end)