robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.7 KiB157 linesraw
1-- Tests for storing global variables in the .shada file
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5
6local describe, it, setup, teardown = t.describe, t.it, t.setup, t.teardown
7local clear, command, eq, neq, eval, poke_eventloop =
8  n.clear, n.command, t.eq, t.neq, n.eval, n.poke_eventloop
9
10describe('storing global variables in ShaDa files', function()
11  local tempname = 'Xtest-functional-legacy-074'
12  setup(function()
13    clear()
14    os.remove(tempname)
15  end)
16
17  it('is working', function()
18    clear { args_rm = { '-i' }, args = { '-i', 'Xviminfo' } }
19
20    local test_dict = { foo = 1, bar = 0, longvarible = 1000 }
21    local test_list = {
22      1,
23      2,
24      3,
25      4,
26      5,
27      6,
28      7,
29      8,
30      9,
31      10,
32      11,
33      12,
34      13,
35      14,
36      15,
37      16,
38      17,
39      18,
40      19,
41      20,
42      21,
43      22,
44      23,
45      24,
46      25,
47      26,
48      27,
49      28,
50      29,
51      30,
52      31,
53      32,
54      33,
55      34,
56      35,
57      36,
58      37,
59      38,
60      39,
61      40,
62      41,
63      42,
64      43,
65      44,
66      45,
67      46,
68      47,
69      48,
70      49,
71      50,
72      51,
73      52,
74      53,
75      54,
76      55,
77      56,
78      57,
79      58,
80      59,
81      60,
82      61,
83      62,
84      63,
85      64,
86      65,
87      66,
88      67,
89      68,
90      69,
91      70,
92      71,
93      72,
94      73,
95      74,
96      75,
97      76,
98      77,
99      78,
100      79,
101      80,
102      81,
103      82,
104      83,
105      84,
106      85,
107      86,
108      87,
109      88,
110      89,
111      90,
112      91,
113      92,
114      93,
115      94,
116      95,
117      96,
118      97,
119      98,
120      99,
121      100,
122    }
123
124    command('set visualbell')
125    command('set shada+=!')
126    command("let MY_GLOBAL_DICT={'foo': 1, 'bar': 0, 'longvarible': 1000}")
127    -- Store a really long list. Initially this was testing line wrapping in
128    -- viminfo, but shada files has no line wrapping, no matter how long the
129    -- list is.
130    command('let MY_GLOBAL_LIST=range(1, 100)')
131
132    eq(test_dict, eval('MY_GLOBAL_DICT'))
133    eq(test_list, eval('MY_GLOBAL_LIST'))
134
135    command('wsh! ' .. tempname)
136    poke_eventloop()
137
138    -- Assert that the shada file exists.
139    neq(nil, vim.uv.fs_stat(tempname))
140    command('unlet MY_GLOBAL_DICT')
141    command('unlet MY_GLOBAL_LIST')
142    -- Assert that the variables where deleted.
143    eq(0, eval('exists("MY_GLOBAL_DICT")'))
144    eq(0, eval('exists("MY_GLOBAL_LIST")'))
145
146    command('rsh! ' .. tempname)
147
148    eq(test_list, eval('MY_GLOBAL_LIST'))
149    eq(test_dict, eval('MY_GLOBAL_DICT'))
150  end)
151
152  teardown(function()
153    os.remove(tempname)
154    command('set shadafile=NONE')
155    os.remove('Xviminfo')
156  end)
157end)