compatibility_spec.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. -- ShaDa compatibility support
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq
  4. local exc_exec = helpers.exc_exec
  5. local shada_helpers = require('test.functional.shada.helpers')
  6. local reset, clear, get_shada_rw = shada_helpers.reset, shada_helpers.clear,
  7. shada_helpers.get_shada_rw
  8. local read_shada_file = shada_helpers.read_shada_file
  9. local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-compatibility.shada')
  10. local mock_file_path = '/a/b/'
  11. local mock_file_path2 = '/d/e/'
  12. if helpers.iswin() then
  13. mock_file_path = 'C:/a/'
  14. mock_file_path2 = 'C:/d/'
  15. end
  16. describe('ShaDa forward compatibility support code', function()
  17. before_each(reset)
  18. after_each(function()
  19. clear()
  20. os.remove(shada_fname)
  21. end)
  22. it('works with search pattern item with BOOL unknown (sX) key value', function()
  23. wshada('\002\001\011\130\162sX\194\162sp\196\001-')
  24. eq(0, exc_exec(sdrcmd()))
  25. os.remove(shada_fname)
  26. nvim_command('wshada ' .. shada_fname)
  27. local found = false
  28. for _, v in ipairs(read_shada_file(shada_fname)) do
  29. if v.type == 2 and not v.value.ss then
  30. eq(false, v.value.sX)
  31. found = true
  32. end
  33. end
  34. eq(true, found)
  35. eq(0, exc_exec(sdrcmd()))
  36. os.remove(shada_fname)
  37. nvim_command('silent! /---/')
  38. nvim_command('wshada ' .. shada_fname)
  39. found = false
  40. for _, v in ipairs(read_shada_file(shada_fname)) do
  41. if v.type == 2 and not v.value.ss then
  42. eq(nil, v.value.sX)
  43. found = true
  44. end
  45. end
  46. eq(true, found)
  47. funcs.garbagecollect(1)
  48. funcs.garbagecollect(1)
  49. nvim_command('rshada! ' .. shada_fname)
  50. funcs.garbagecollect(1)
  51. funcs.garbagecollect(1)
  52. end)
  53. it('works with s/search pattern item with BOOL unknown (sX) key value', function()
  54. wshada('\002\001\015\131\162sX\194\162ss\195\162sp\196\001-')
  55. eq(0, exc_exec(sdrcmd()))
  56. os.remove(shada_fname)
  57. nvim_command('wshada ' .. shada_fname)
  58. local found = false
  59. for _, v in ipairs(read_shada_file(shada_fname)) do
  60. if v.type == 2 and v.value.ss then
  61. eq(false, v.value.sX)
  62. found = true
  63. end
  64. end
  65. eq(true, found)
  66. eq(0, exc_exec(sdrcmd()))
  67. os.remove(shada_fname)
  68. nvim_command('silent! s/--/---/ge')
  69. nvim_command('wshada ' .. shada_fname)
  70. found = false
  71. for _, v in ipairs(read_shada_file(shada_fname)) do
  72. if v.type == 2 and v.value.ss then
  73. eq(nil, v.value.sX)
  74. found = true
  75. end
  76. end
  77. eq(true, found)
  78. funcs.garbagecollect(1)
  79. funcs.garbagecollect(1)
  80. nvim_command('rshada!' .. shada_fname)
  81. funcs.garbagecollect(1)
  82. funcs.garbagecollect(1)
  83. end)
  84. it('works with replacement item with BOOL additional value in list', function()
  85. wshada('\003\000\005\146\196\001-\194')
  86. eq(0, exc_exec(sdrcmd()))
  87. os.remove(shada_fname)
  88. nvim_command('wshada ' .. shada_fname)
  89. local found = false
  90. for _, v in ipairs(read_shada_file(shada_fname)) do
  91. if v.type == 3 then
  92. eq(2, #v.value)
  93. eq(false, v.value[2])
  94. found = true
  95. end
  96. end
  97. eq(true, found)
  98. eq(0, exc_exec(sdrcmd()))
  99. os.remove(shada_fname)
  100. nvim_command('silent! s/--/---/ge')
  101. nvim_command('wshada ' .. shada_fname)
  102. found = false
  103. for _, v in ipairs(read_shada_file(shada_fname)) do
  104. if v.type == 3 then
  105. eq(1, #v.value)
  106. found = true
  107. end
  108. end
  109. eq(true, found)
  110. funcs.garbagecollect(1)
  111. funcs.garbagecollect(1)
  112. nvim_command('rshada!' .. shada_fname)
  113. funcs.garbagecollect(1)
  114. funcs.garbagecollect(1)
  115. end)
  116. for _, v in ipairs({{name='global mark', mpack='\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161nA'},
  117. {name='jump', mpack='\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002'},
  118. {name='local mark', mpack='\010\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161na'},
  119. {name='change', mpack='\011\001\015\130\162mX\195\161f\196\006' .. mock_file_path .. 'c'},
  120. }) do
  121. it('works with ' .. v.name .. ' item with BOOL unknown (mX) key value', function()
  122. nvim_command('silent noautocmd edit ' .. mock_file_path .. 'c')
  123. eq('' .. mock_file_path .. 'c', funcs.bufname('%'))
  124. funcs.setline('.', {'1', '2', '3'})
  125. wshada(v.mpack)
  126. eq(0, exc_exec(sdrcmd(true)))
  127. os.remove(shada_fname)
  128. nvim_command('wshada ' .. shada_fname)
  129. local found = false
  130. for _, subv in ipairs(read_shada_file(shada_fname)) do
  131. if subv.type == v.mpack:byte() then
  132. if subv.value.mX == true then
  133. found = true
  134. end
  135. end
  136. end
  137. eq(true, found)
  138. eq(0, exc_exec(sdrcmd()))
  139. nvim_command('bwipeout!')
  140. funcs.setpos('\'A', {0, 1, 1, 0})
  141. os.remove(shada_fname)
  142. nvim_command('wshada ' .. shada_fname)
  143. found = false
  144. for _, subv in ipairs(read_shada_file(shada_fname)) do
  145. if subv.type == v.mpack:byte() then
  146. if subv.value.mX == true then
  147. found = true
  148. end
  149. end
  150. end
  151. eq(false, found)
  152. funcs.garbagecollect(1)
  153. funcs.garbagecollect(1)
  154. nvim_command('rshada!' .. shada_fname)
  155. funcs.garbagecollect(1)
  156. funcs.garbagecollect(1)
  157. end)
  158. if v.name == 'global mark' or v.name == 'local mark' then
  159. it('works with ' .. v.name .. ' item with <C-a> name', function()
  160. nvim_command('silent noautocmd edit ' .. mock_file_path .. 'c')
  161. eq('' .. mock_file_path .. 'c', funcs.bufname('%'))
  162. funcs.setline('.', {'1', '2', '3'})
  163. wshada(v.mpack:gsub('n.$', 'n\001')
  164. .. v.mpack:gsub('n.$', 'n\002')
  165. .. v.mpack:gsub('n.$', 'n\003'):gsub('' .. mock_file_path .. 'c', '' .. mock_file_path2 .. 'f'))
  166. eq(0, exc_exec(sdrcmd(true)))
  167. nvim_command('wshada ' .. shada_fname)
  168. local found = 0
  169. for i, subv in ipairs(read_shada_file(shada_fname)) do
  170. if i == 1 then
  171. eq(1, subv.type)
  172. end
  173. if subv.type == v.mpack:byte() then
  174. if subv.value.mX == true and subv.value.n <= 3 then
  175. found = found + 1
  176. end
  177. end
  178. end
  179. eq(3, found)
  180. nvim_command('wshada! ' .. shada_fname)
  181. found = 0
  182. for i, subv in ipairs(read_shada_file(shada_fname)) do
  183. if i == 1 then
  184. eq(1, subv.type)
  185. end
  186. if subv.type == v.mpack:byte() then
  187. if subv.value.mX == true and subv.value.n <= 3 then
  188. found = found + 1
  189. end
  190. end
  191. end
  192. eq(0, found)
  193. funcs.garbagecollect(1)
  194. funcs.garbagecollect(1)
  195. nvim_command('rshada!' .. shada_fname)
  196. funcs.garbagecollect(1)
  197. funcs.garbagecollect(1)
  198. end)
  199. end
  200. end
  201. it('works with register item with BOOL unknown (rX) key', function()
  202. wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
  203. eq(0, exc_exec(sdrcmd()))
  204. os.remove(shada_fname)
  205. nvim_command('wshada ' .. shada_fname)
  206. local found = false
  207. for _, v in ipairs(read_shada_file(shada_fname)) do
  208. if v.type == 5 and v.value.rX == false then
  209. found = true
  210. end
  211. end
  212. eq(true, found)
  213. eq(0, exc_exec(sdrcmd()))
  214. os.remove(shada_fname)
  215. nvim_command('let @a = "Test"')
  216. nvim_command('wshada ' .. shada_fname)
  217. found = false
  218. for _, v in ipairs(read_shada_file(shada_fname)) do
  219. if v.type == 5 and v.value.rX == false then
  220. found = true
  221. end
  222. end
  223. eq(false, found)
  224. funcs.garbagecollect(1)
  225. funcs.garbagecollect(1)
  226. nvim_command('rshada!' .. shada_fname)
  227. funcs.garbagecollect(1)
  228. funcs.garbagecollect(1)
  229. end)
  230. it('works with register item with <C-a> name', function()
  231. wshada('\005\001\015\131\161n\001\162rX\194\162rc\145\196\001-')
  232. eq(0, exc_exec(sdrcmd(true)))
  233. nvim_command('wshada ' .. shada_fname)
  234. local found = 0
  235. for i, v in ipairs(read_shada_file(shada_fname)) do
  236. if i == 1 then
  237. eq(1, v.type)
  238. end
  239. if v.type == 5 then
  240. if v.value.rX == false and v.value.n == 1 then
  241. found = found + 1
  242. end
  243. end
  244. end
  245. eq(1, found)
  246. nvim_command('wshada! ' .. shada_fname)
  247. found = 0
  248. for i, v in ipairs(read_shada_file(shada_fname)) do
  249. if i == 1 then
  250. eq(1, v.type)
  251. end
  252. if v.type == 5 then
  253. if v.value.rX == false and v.value.n == 1 then
  254. found = found + 1
  255. end
  256. end
  257. end
  258. eq(0, found)
  259. funcs.garbagecollect(1)
  260. funcs.garbagecollect(1)
  261. nvim_command('rshada!' .. shada_fname)
  262. funcs.garbagecollect(1)
  263. funcs.garbagecollect(1)
  264. end)
  265. it('works with register item with type 10', function()
  266. wshada('\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010')
  267. eq(0, exc_exec(sdrcmd(true)))
  268. eq({}, funcs.getreg('a', 1, 1))
  269. eq('', funcs.getregtype('a'))
  270. nvim_command('wshada ' .. shada_fname)
  271. local found = 0
  272. for i, v in ipairs(read_shada_file(shada_fname)) do
  273. if i == 1 then
  274. eq(1, v.type)
  275. end
  276. if v.type == 5 then
  277. if v.value.rX == false and v.value.rt == 10 then
  278. found = found + 1
  279. end
  280. end
  281. end
  282. eq(1, found)
  283. nvim_command('wshada! ' .. shada_fname)
  284. found = 0
  285. for i, v in ipairs(read_shada_file(shada_fname)) do
  286. if i == 1 then
  287. eq(1, v.type)
  288. end
  289. if v.type == 5 then
  290. if v.value.rX == false and v.value.rt == 10 then
  291. found = found + 1
  292. end
  293. end
  294. end
  295. eq(0, found)
  296. funcs.garbagecollect(1)
  297. funcs.garbagecollect(1)
  298. nvim_command('rshada!' .. shada_fname)
  299. funcs.garbagecollect(1)
  300. funcs.garbagecollect(1)
  301. end)
  302. it('works with buffer list item with BOOL unknown (bX) key', function()
  303. nvim_command('set shada+=%')
  304. wshada('\009\000\016\145\130\161f\196\006' .. mock_file_path .. 'c\162bX\195')
  305. eq(0, exc_exec(sdrcmd()))
  306. eq(2, funcs.bufnr('$'))
  307. eq('' .. mock_file_path .. 'c', funcs.bufname(2))
  308. os.remove(shada_fname)
  309. nvim_command('wshada ' .. shada_fname)
  310. local found = false
  311. for _, v in ipairs(read_shada_file(shada_fname)) do
  312. if v.type == 9 and #v.value == 1 and v.value[1].bX == true then
  313. found = true
  314. end
  315. end
  316. eq(true, found)
  317. eq(0, exc_exec(sdrcmd()))
  318. os.remove(shada_fname)
  319. nvim_command('buffer 2')
  320. nvim_command('edit!')
  321. nvim_command('wshada ' .. shada_fname)
  322. found = false
  323. for _, v in ipairs(read_shada_file(shada_fname)) do
  324. if v.type == 5 and v.value.rX == false then
  325. found = true
  326. end
  327. end
  328. eq(false, found)
  329. nvim_command('bwipeout!')
  330. funcs.garbagecollect(1)
  331. funcs.garbagecollect(1)
  332. nvim_command('rshada!' .. shada_fname)
  333. funcs.garbagecollect(1)
  334. funcs.garbagecollect(1)
  335. end)
  336. it('works with history item with BOOL additional value in list', function()
  337. wshada('\004\000\006\147\000\196\001-\194')
  338. eq(0, exc_exec(sdrcmd()))
  339. os.remove(shada_fname)
  340. nvim_command('wshada ' .. shada_fname)
  341. local found = false
  342. for _, v in ipairs(read_shada_file(shada_fname)) do
  343. if v.type == 4 and v.value[1] == 0 and v.value[2] == '-' then
  344. eq(false, v.value[3])
  345. eq(3, #v.value)
  346. found = true
  347. end
  348. end
  349. eq(true, found)
  350. eq(0, exc_exec(sdrcmd()))
  351. os.remove(shada_fname)
  352. funcs.histadd(':', '--')
  353. funcs.histadd(':', '-')
  354. nvim_command('wshada ' .. shada_fname)
  355. found = false
  356. for _, v in ipairs(read_shada_file(shada_fname)) do
  357. if v.type == 4 and v.value[1] == 0 and v.value[2] == '-' then
  358. eq(2, #v.value)
  359. found = true
  360. end
  361. end
  362. eq(true, found)
  363. funcs.garbagecollect(1)
  364. funcs.garbagecollect(1)
  365. nvim_command('rshada!' .. shada_fname)
  366. funcs.garbagecollect(1)
  367. funcs.garbagecollect(1)
  368. end)
  369. it('works with history item with type 10', function()
  370. wshada('\004\000\006\147\010\196\001-\194')
  371. eq(0, exc_exec(sdrcmd()))
  372. nvim_command('wshada ' .. shada_fname)
  373. eq(0, exc_exec(sdrcmd()))
  374. local found = 0
  375. for i, v in ipairs(read_shada_file(shada_fname)) do
  376. if i == 1 then
  377. eq(1, v.type)
  378. end
  379. if v.type == 4 then
  380. if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then
  381. found = found + 1
  382. end
  383. end
  384. end
  385. eq(1, found)
  386. nvim_command('wshada! ' .. shada_fname)
  387. found = 0
  388. for i, v in ipairs(read_shada_file(shada_fname)) do
  389. if i == 1 then
  390. eq(1, v.type)
  391. end
  392. if v.type == 4 then
  393. if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then
  394. found = found + 1
  395. end
  396. end
  397. end
  398. eq(0, found)
  399. funcs.garbagecollect(1)
  400. funcs.garbagecollect(1)
  401. nvim_command('rshada!' .. shada_fname)
  402. funcs.garbagecollect(1)
  403. funcs.garbagecollect(1)
  404. end)
  405. it('works with item with 100 type', function()
  406. wshada('\100\000\006\147\010\196\001-\194')
  407. eq(0, exc_exec(sdrcmd()))
  408. nvim_command('wshada ' .. shada_fname)
  409. eq(0, exc_exec(sdrcmd()))
  410. local found = 0
  411. for i, v in ipairs(read_shada_file(shada_fname)) do
  412. if i == 1 then
  413. eq(1, v.type)
  414. end
  415. if v.type == 100 then
  416. if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then
  417. found = found + 1
  418. end
  419. end
  420. end
  421. eq(1, found)
  422. nvim_command('wshada! ' .. shada_fname)
  423. found = 0
  424. for i, v in ipairs(read_shada_file(shada_fname)) do
  425. if i == 1 then
  426. eq(1, v.type)
  427. end
  428. if v.type == 100 then
  429. if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then
  430. found = found + 1
  431. end
  432. end
  433. end
  434. eq(0, found)
  435. funcs.garbagecollect(1)
  436. funcs.garbagecollect(1)
  437. nvim_command('rshada!' .. shada_fname)
  438. funcs.garbagecollect(1)
  439. funcs.garbagecollect(1)
  440. end)
  441. end)