compatibility_spec.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. -- ShaDa compatibility support
  2. local t = require('test.testutil')
  3. local n = require('test.functional.testnvim')()
  4. local t_shada = require('test.functional.shada.testutil')
  5. local nvim_command, fn, eq = n.command, n.fn, t.eq
  6. local exc_exec = n.exc_exec
  7. local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw
  8. local read_shada_file = t_shada.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 t.is_os('win') 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. fn.garbagecollect(1)
  48. fn.garbagecollect(1)
  49. nvim_command('rshada! ' .. shada_fname)
  50. fn.garbagecollect(1)
  51. fn.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. fn.garbagecollect(1)
  79. fn.garbagecollect(1)
  80. nvim_command('rshada!' .. shada_fname)
  81. fn.garbagecollect(1)
  82. fn.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. fn.garbagecollect(1)
  111. fn.garbagecollect(1)
  112. nvim_command('rshada!' .. shada_fname)
  113. fn.garbagecollect(1)
  114. fn.garbagecollect(1)
  115. end)
  116. for _, v in ipairs({
  117. {
  118. name = 'global mark',
  119. mpack = '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161nA',
  120. },
  121. {
  122. name = 'jump',
  123. mpack = '\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002',
  124. },
  125. {
  126. name = 'local mark',
  127. mpack = '\010\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161na',
  128. },
  129. { name = 'change', mpack = '\011\001\015\130\162mX\195\161f\196\006' .. mock_file_path .. 'c' },
  130. }) do
  131. it('works with ' .. v.name .. ' item with BOOL unknown (mX) key value', function()
  132. nvim_command('silent noautocmd edit ' .. mock_file_path .. 'c')
  133. eq('' .. mock_file_path .. 'c', fn.bufname('%'))
  134. fn.setline('.', { '1', '2', '3' })
  135. wshada(v.mpack)
  136. eq(0, exc_exec(sdrcmd(true)))
  137. os.remove(shada_fname)
  138. nvim_command('wshada ' .. shada_fname)
  139. local found = false
  140. for _, subv in ipairs(read_shada_file(shada_fname)) do
  141. if subv.type == v.mpack:byte() then
  142. if subv.value.mX == true then
  143. found = true
  144. end
  145. end
  146. end
  147. eq(true, found)
  148. eq(0, exc_exec(sdrcmd()))
  149. nvim_command('bwipeout!')
  150. fn.setpos("'A", { 0, 1, 1, 0 })
  151. os.remove(shada_fname)
  152. nvim_command('wshada ' .. shada_fname)
  153. found = false
  154. for _, subv in ipairs(read_shada_file(shada_fname)) do
  155. if subv.type == v.mpack:byte() then
  156. if subv.value.mX == true then
  157. found = true
  158. end
  159. end
  160. end
  161. eq(false, found)
  162. fn.garbagecollect(1)
  163. fn.garbagecollect(1)
  164. nvim_command('rshada!' .. shada_fname)
  165. fn.garbagecollect(1)
  166. fn.garbagecollect(1)
  167. end)
  168. if v.name == 'global mark' or v.name == 'local mark' then
  169. it('works with ' .. v.name .. ' item with <C-a> name', function()
  170. nvim_command('silent noautocmd edit ' .. mock_file_path .. 'c')
  171. eq('' .. mock_file_path .. 'c', fn.bufname('%'))
  172. fn.setline('.', { '1', '2', '3' })
  173. wshada(
  174. v.mpack:gsub('n.$', 'n\001')
  175. .. v.mpack:gsub('n.$', 'n\002')
  176. .. v.mpack
  177. :gsub('n.$', 'n\003')
  178. :gsub('' .. mock_file_path .. 'c', '' .. mock_file_path2 .. 'f')
  179. )
  180. eq(0, exc_exec(sdrcmd(true)))
  181. nvim_command('wshada ' .. shada_fname)
  182. local found = 0
  183. for i, subv in ipairs(read_shada_file(shada_fname)) do
  184. if i == 1 then
  185. eq(1, subv.type)
  186. end
  187. if subv.type == v.mpack:byte() then
  188. if subv.value.mX == true and subv.value.n <= 3 then
  189. found = found + 1
  190. end
  191. end
  192. end
  193. eq(3, found)
  194. nvim_command('wshada! ' .. shada_fname)
  195. found = 0
  196. for i, subv in ipairs(read_shada_file(shada_fname)) do
  197. if i == 1 then
  198. eq(1, subv.type)
  199. end
  200. if subv.type == v.mpack:byte() then
  201. if subv.value.mX == true and subv.value.n <= 3 then
  202. found = found + 1
  203. end
  204. end
  205. end
  206. eq(0, found)
  207. fn.garbagecollect(1)
  208. fn.garbagecollect(1)
  209. nvim_command('rshada!' .. shada_fname)
  210. fn.garbagecollect(1)
  211. fn.garbagecollect(1)
  212. end)
  213. end
  214. end
  215. it('works with register item with BOOL unknown (rX) key', function()
  216. wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
  217. eq(0, exc_exec(sdrcmd()))
  218. os.remove(shada_fname)
  219. nvim_command('wshada ' .. shada_fname)
  220. local found = false
  221. for _, v in ipairs(read_shada_file(shada_fname)) do
  222. if v.type == 5 and v.value.rX == false then
  223. found = true
  224. end
  225. end
  226. eq(true, found)
  227. eq(0, exc_exec(sdrcmd()))
  228. os.remove(shada_fname)
  229. nvim_command('let @a = "Test"')
  230. nvim_command('wshada ' .. shada_fname)
  231. found = false
  232. for _, v in ipairs(read_shada_file(shada_fname)) do
  233. if v.type == 5 and v.value.rX == false then
  234. found = true
  235. end
  236. end
  237. eq(false, found)
  238. fn.garbagecollect(1)
  239. fn.garbagecollect(1)
  240. nvim_command('rshada!' .. shada_fname)
  241. fn.garbagecollect(1)
  242. fn.garbagecollect(1)
  243. end)
  244. it('works with register item with <C-a> name', function()
  245. wshada('\005\001\015\131\161n\001\162rX\194\162rc\145\196\001-')
  246. eq(0, exc_exec(sdrcmd(true)))
  247. nvim_command('wshada ' .. shada_fname)
  248. local found = 0
  249. for i, v in ipairs(read_shada_file(shada_fname)) do
  250. if i == 1 then
  251. eq(1, v.type)
  252. end
  253. if v.type == 5 then
  254. if v.value.rX == false and v.value.n == 1 then
  255. found = found + 1
  256. end
  257. end
  258. end
  259. eq(1, found)
  260. nvim_command('wshada! ' .. shada_fname)
  261. found = 0
  262. for i, v in ipairs(read_shada_file(shada_fname)) do
  263. if i == 1 then
  264. eq(1, v.type)
  265. end
  266. if v.type == 5 then
  267. if v.value.rX == false and v.value.n == 1 then
  268. found = found + 1
  269. end
  270. end
  271. end
  272. eq(0, found)
  273. fn.garbagecollect(1)
  274. fn.garbagecollect(1)
  275. nvim_command('rshada!' .. shada_fname)
  276. fn.garbagecollect(1)
  277. fn.garbagecollect(1)
  278. end)
  279. it('works with register item with type 10', function()
  280. wshada('\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010')
  281. eq(0, exc_exec(sdrcmd(true)))
  282. eq({}, fn.getreg('a', 1, 1))
  283. eq('', fn.getregtype('a'))
  284. nvim_command('wshada ' .. shada_fname)
  285. local found = 0
  286. for i, v in ipairs(read_shada_file(shada_fname)) do
  287. if i == 1 then
  288. eq(1, v.type)
  289. end
  290. if v.type == 5 then
  291. if v.value.rX == false and v.value.rt == 10 then
  292. found = found + 1
  293. end
  294. end
  295. end
  296. eq(1, found)
  297. nvim_command('wshada! ' .. shada_fname)
  298. found = 0
  299. for i, v in ipairs(read_shada_file(shada_fname)) do
  300. if i == 1 then
  301. eq(1, v.type)
  302. end
  303. if v.type == 5 then
  304. if v.value.rX == false and v.value.rt == 10 then
  305. found = found + 1
  306. end
  307. end
  308. end
  309. eq(0, found)
  310. fn.garbagecollect(1)
  311. fn.garbagecollect(1)
  312. nvim_command('rshada!' .. shada_fname)
  313. fn.garbagecollect(1)
  314. fn.garbagecollect(1)
  315. end)
  316. it('works with buffer list item with BOOL unknown (bX) key', function()
  317. nvim_command('set shada+=%')
  318. wshada('\009\000\016\145\130\161f\196\006' .. mock_file_path .. 'c\162bX\195')
  319. eq(0, exc_exec(sdrcmd()))
  320. eq(2, fn.bufnr('$'))
  321. eq('' .. mock_file_path .. 'c', fn.bufname(2))
  322. os.remove(shada_fname)
  323. nvim_command('wshada ' .. shada_fname)
  324. local found = false
  325. for _, v in ipairs(read_shada_file(shada_fname)) do
  326. if v.type == 9 and #v.value == 1 and v.value[1].bX == true then
  327. found = true
  328. end
  329. end
  330. eq(true, found)
  331. eq(0, exc_exec(sdrcmd()))
  332. os.remove(shada_fname)
  333. nvim_command('buffer 2')
  334. nvim_command('edit!')
  335. nvim_command('wshada ' .. shada_fname)
  336. found = false
  337. for _, v in ipairs(read_shada_file(shada_fname)) do
  338. if v.type == 5 and v.value.rX == false then
  339. found = true
  340. end
  341. end
  342. eq(false, found)
  343. nvim_command('bwipeout!')
  344. fn.garbagecollect(1)
  345. fn.garbagecollect(1)
  346. nvim_command('rshada!' .. shada_fname)
  347. fn.garbagecollect(1)
  348. fn.garbagecollect(1)
  349. end)
  350. it('works with history item with BOOL additional value in list', function()
  351. wshada('\004\000\006\147\000\196\001-\194')
  352. eq(0, exc_exec(sdrcmd()))
  353. os.remove(shada_fname)
  354. nvim_command('wshada ' .. shada_fname)
  355. local 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(false, v.value[3])
  359. eq(3, #v.value)
  360. found = true
  361. end
  362. end
  363. eq(true, found)
  364. eq(0, exc_exec(sdrcmd()))
  365. os.remove(shada_fname)
  366. fn.histadd(':', '--')
  367. fn.histadd(':', '-')
  368. nvim_command('wshada ' .. shada_fname)
  369. found = false
  370. for _, v in ipairs(read_shada_file(shada_fname)) do
  371. if v.type == 4 and v.value[1] == 0 and v.value[2] == '-' then
  372. eq(2, #v.value)
  373. found = true
  374. end
  375. end
  376. eq(true, found)
  377. fn.garbagecollect(1)
  378. fn.garbagecollect(1)
  379. nvim_command('rshada!' .. shada_fname)
  380. fn.garbagecollect(1)
  381. fn.garbagecollect(1)
  382. end)
  383. it('works with history item with type 10', function()
  384. wshada('\004\000\006\147\010\196\001-\194')
  385. eq(0, exc_exec(sdrcmd()))
  386. nvim_command('wshada ' .. shada_fname)
  387. eq(0, exc_exec(sdrcmd()))
  388. local found = 0
  389. for i, v in ipairs(read_shada_file(shada_fname)) do
  390. if i == 1 then
  391. eq(1, v.type)
  392. end
  393. if v.type == 4 then
  394. if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then
  395. found = found + 1
  396. end
  397. end
  398. end
  399. eq(1, found)
  400. nvim_command('wshada! ' .. shada_fname)
  401. found = 0
  402. for i, v in ipairs(read_shada_file(shada_fname)) do
  403. if i == 1 then
  404. eq(1, v.type)
  405. end
  406. if v.type == 4 then
  407. if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then
  408. found = found + 1
  409. end
  410. end
  411. end
  412. eq(0, found)
  413. fn.garbagecollect(1)
  414. fn.garbagecollect(1)
  415. nvim_command('rshada!' .. shada_fname)
  416. fn.garbagecollect(1)
  417. fn.garbagecollect(1)
  418. end)
  419. it('works with item with 100 type', function()
  420. wshada('\100\000\006\147\010\196\001-\194')
  421. eq(0, exc_exec(sdrcmd()))
  422. nvim_command('wshada ' .. shada_fname)
  423. eq(0, exc_exec(sdrcmd()))
  424. local found = 0
  425. for i, v in ipairs(read_shada_file(shada_fname)) do
  426. if i == 1 then
  427. eq(1, v.type)
  428. end
  429. if v.type == 100 then
  430. if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then
  431. found = found + 1
  432. end
  433. end
  434. end
  435. eq(1, found)
  436. nvim_command('wshada! ' .. shada_fname)
  437. found = 0
  438. for i, v in ipairs(read_shada_file(shada_fname)) do
  439. if i == 1 then
  440. eq(1, v.type)
  441. end
  442. if v.type == 100 then
  443. if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then
  444. found = found + 1
  445. end
  446. end
  447. end
  448. eq(0, found)
  449. fn.garbagecollect(1)
  450. fn.garbagecollect(1)
  451. nvim_command('rshada!' .. shada_fname)
  452. fn.garbagecollect(1)
  453. fn.garbagecollect(1)
  454. end)
  455. end)