diff_spec.lua 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local feed = helpers.feed
  4. local clear = helpers.clear
  5. local command = helpers.command
  6. local insert = helpers.insert
  7. local write_file = helpers.write_file
  8. local source = helpers.source
  9. describe('Diff mode screen', function()
  10. local fname = 'Xtest-functional-diff-screen-1'
  11. local fname_2 = fname .. '.2'
  12. local screen
  13. local reread = function()
  14. feed(':e<cr><c-w>w:e<cr><c-w>w')
  15. end
  16. setup(function()
  17. clear()
  18. os.remove(fname)
  19. os.remove(fname_2)
  20. end)
  21. teardown(function()
  22. os.remove(fname)
  23. os.remove(fname_2)
  24. end)
  25. before_each(function()
  26. clear()
  27. feed(':e ' .. fname_2 .. '<cr>')
  28. feed(':vnew ' .. fname .. '<cr>')
  29. feed(':diffthis<cr>')
  30. feed('<c-w>w:diffthis<cr><c-w>w')
  31. screen = Screen.new(40, 16)
  32. screen:attach()
  33. screen:set_default_attr_ids({
  34. [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
  35. [2] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
  36. [3] = {reverse = true},
  37. [4] = {background = Screen.colors.LightBlue},
  38. [5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
  39. [6] = {bold = true, foreground = Screen.colors.Blue1},
  40. [7] = {bold = true, reverse = true},
  41. [8] = {bold = true, background = Screen.colors.Red},
  42. [9] = {background = Screen.colors.LightMagenta},
  43. })
  44. end)
  45. it('Add a line in beginning of file 2', function()
  46. write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
  47. write_file(fname_2, "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
  48. reread()
  49. feed(':set diffopt=filler<cr>')
  50. screen:expect([[
  51. {1: }{2:------------------}{3:│}{1: }{4:0 }|
  52. {1: }^1 {3:│}{1: }1 |
  53. {1: }2 {3:│}{1: }2 |
  54. {1: }3 {3:│}{1: }3 |
  55. {1: }4 {3:│}{1: }4 |
  56. {1: }5 {3:│}{1: }5 |
  57. {1: }6 {3:│}{1: }6 |
  58. {1:+ }{5:+-- 4 lines: 7···}{3:│}{1:+ }{5:+-- 4 lines: 7··}|
  59. {6:~ }{3:│}{6:~ }|
  60. {6:~ }{3:│}{6:~ }|
  61. {6:~ }{3:│}{6:~ }|
  62. {6:~ }{3:│}{6:~ }|
  63. {6:~ }{3:│}{6:~ }|
  64. {6:~ }{3:│}{6:~ }|
  65. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  66. :set diffopt=filler |
  67. ]])
  68. feed(':set diffopt+=internal<cr>')
  69. screen:expect([[
  70. {1: }{2:------------------}{3:│}{1: }{4:0 }|
  71. {1: }^1 {3:│}{1: }1 |
  72. {1: }2 {3:│}{1: }2 |
  73. {1: }3 {3:│}{1: }3 |
  74. {1: }4 {3:│}{1: }4 |
  75. {1: }5 {3:│}{1: }5 |
  76. {1: }6 {3:│}{1: }6 |
  77. {1:+ }{5:+-- 4 lines: 7···}{3:│}{1:+ }{5:+-- 4 lines: 7··}|
  78. {6:~ }{3:│}{6:~ }|
  79. {6:~ }{3:│}{6:~ }|
  80. {6:~ }{3:│}{6:~ }|
  81. {6:~ }{3:│}{6:~ }|
  82. {6:~ }{3:│}{6:~ }|
  83. {6:~ }{3:│}{6:~ }|
  84. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  85. :set diffopt+=internal |
  86. ]])
  87. end)
  88. it('Add a line in beginning of file 1', function()
  89. write_file(fname, "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
  90. write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
  91. reread()
  92. feed(":set diffopt=filler<cr>")
  93. screen:expect([[
  94. {1: }{4:^0 }{3:│}{1: }{2:-----------------}|
  95. {1: }1 {3:│}{1: }1 |
  96. {1: }2 {3:│}{1: }2 |
  97. {1: }3 {3:│}{1: }3 |
  98. {1: }4 {3:│}{1: }4 |
  99. {1: }5 {3:│}{1: }5 |
  100. {1: }6 {3:│}{1: }6 |
  101. {1:+ }{5:+-- 4 lines: 7···}{3:│}{1:+ }{5:+-- 4 lines: 7··}|
  102. {6:~ }{3:│}{6:~ }|
  103. {6:~ }{3:│}{6:~ }|
  104. {6:~ }{3:│}{6:~ }|
  105. {6:~ }{3:│}{6:~ }|
  106. {6:~ }{3:│}{6:~ }|
  107. {6:~ }{3:│}{6:~ }|
  108. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  109. :set diffopt=filler |
  110. ]])
  111. feed(":set diffopt+=internal<cr>")
  112. screen:expect([[
  113. {1: }{4:^0 }{3:│}{1: }{2:-----------------}|
  114. {1: }1 {3:│}{1: }1 |
  115. {1: }2 {3:│}{1: }2 |
  116. {1: }3 {3:│}{1: }3 |
  117. {1: }4 {3:│}{1: }4 |
  118. {1: }5 {3:│}{1: }5 |
  119. {1: }6 {3:│}{1: }6 |
  120. {1:+ }{5:+-- 4 lines: 7···}{3:│}{1:+ }{5:+-- 4 lines: 7··}|
  121. {6:~ }{3:│}{6:~ }|
  122. {6:~ }{3:│}{6:~ }|
  123. {6:~ }{3:│}{6:~ }|
  124. {6:~ }{3:│}{6:~ }|
  125. {6:~ }{3:│}{6:~ }|
  126. {6:~ }{3:│}{6:~ }|
  127. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  128. :set diffopt+=internal |
  129. ]])
  130. end)
  131. it('Add a line at the end of file 2', function()
  132. write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
  133. write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", false)
  134. reread()
  135. feed(":set diffopt=filler<cr>")
  136. screen:expect([[
  137. {1:+ }{5:^+-- 4 lines: 1···}{3:│}{1:+ }{5:+-- 4 lines: 1··}|
  138. {1: }5 {3:│}{1: }5 |
  139. {1: }6 {3:│}{1: }6 |
  140. {1: }7 {3:│}{1: }7 |
  141. {1: }8 {3:│}{1: }8 |
  142. {1: }9 {3:│}{1: }9 |
  143. {1: }10 {3:│}{1: }10 |
  144. {1: }{2:------------------}{3:│}{1: }{4:11 }|
  145. {6:~ }{3:│}{6:~ }|
  146. {6:~ }{3:│}{6:~ }|
  147. {6:~ }{3:│}{6:~ }|
  148. {6:~ }{3:│}{6:~ }|
  149. {6:~ }{3:│}{6:~ }|
  150. {6:~ }{3:│}{6:~ }|
  151. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  152. :set diffopt=filler |
  153. ]])
  154. feed(":set diffopt+=internal<cr>")
  155. screen:expect([[
  156. {1:+ }{5:^+-- 4 lines: 1···}{3:│}{1:+ }{5:+-- 4 lines: 1··}|
  157. {1: }5 {3:│}{1: }5 |
  158. {1: }6 {3:│}{1: }6 |
  159. {1: }7 {3:│}{1: }7 |
  160. {1: }8 {3:│}{1: }8 |
  161. {1: }9 {3:│}{1: }9 |
  162. {1: }10 {3:│}{1: }10 |
  163. {1: }{2:------------------}{3:│}{1: }{4:11 }|
  164. {6:~ }{3:│}{6:~ }|
  165. {6:~ }{3:│}{6:~ }|
  166. {6:~ }{3:│}{6:~ }|
  167. {6:~ }{3:│}{6:~ }|
  168. {6:~ }{3:│}{6:~ }|
  169. {6:~ }{3:│}{6:~ }|
  170. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  171. :set diffopt+=internal |
  172. ]])
  173. end)
  174. it('Add a line at the end of file 1', function()
  175. write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", false)
  176. write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
  177. reread()
  178. feed(":set diffopt=filler<cr>")
  179. screen:expect([[
  180. {1:+ }{5:^+-- 4 lines: 1···}{3:│}{1:+ }{5:+-- 4 lines: 1··}|
  181. {1: }5 {3:│}{1: }5 |
  182. {1: }6 {3:│}{1: }6 |
  183. {1: }7 {3:│}{1: }7 |
  184. {1: }8 {3:│}{1: }8 |
  185. {1: }9 {3:│}{1: }9 |
  186. {1: }10 {3:│}{1: }10 |
  187. {1: }{4:11 }{3:│}{1: }{2:-----------------}|
  188. {6:~ }{3:│}{6:~ }|
  189. {6:~ }{3:│}{6:~ }|
  190. {6:~ }{3:│}{6:~ }|
  191. {6:~ }{3:│}{6:~ }|
  192. {6:~ }{3:│}{6:~ }|
  193. {6:~ }{3:│}{6:~ }|
  194. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  195. :set diffopt=filler |
  196. ]])
  197. feed(":set diffopt+=internal<cr>")
  198. screen:expect([[
  199. {1:+ }{5:^+-- 4 lines: 1···}{3:│}{1:+ }{5:+-- 4 lines: 1··}|
  200. {1: }5 {3:│}{1: }5 |
  201. {1: }6 {3:│}{1: }6 |
  202. {1: }7 {3:│}{1: }7 |
  203. {1: }8 {3:│}{1: }8 |
  204. {1: }9 {3:│}{1: }9 |
  205. {1: }10 {3:│}{1: }10 |
  206. {1: }{4:11 }{3:│}{1: }{2:-----------------}|
  207. {6:~ }{3:│}{6:~ }|
  208. {6:~ }{3:│}{6:~ }|
  209. {6:~ }{3:│}{6:~ }|
  210. {6:~ }{3:│}{6:~ }|
  211. {6:~ }{3:│}{6:~ }|
  212. {6:~ }{3:│}{6:~ }|
  213. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  214. :set diffopt+=internal |
  215. ]])
  216. end)
  217. it('Add a line in the middle of file 2, remove on at the end of file 1', function()
  218. write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", false)
  219. write_file(fname_2, "1\n2\n3\n4\n4\n5\n6\n7\n8\n9\n10\n", false)
  220. reread()
  221. feed(':set diffopt=filler<cr>')
  222. screen:expect([[
  223. {1: }^1 {3:│}{1: }1 |
  224. {1: }2 {3:│}{1: }2 |
  225. {1: }3 {3:│}{1: }3 |
  226. {1: }4 {3:│}{1: }4 |
  227. {1: }{2:------------------}{3:│}{1: }{4:4 }|
  228. {1: }5 {3:│}{1: }5 |
  229. {1: }6 {3:│}{1: }6 |
  230. {1: }7 {3:│}{1: }7 |
  231. {1: }8 {3:│}{1: }8 |
  232. {1: }9 {3:│}{1: }9 |
  233. {1: }10 {3:│}{1: }10 |
  234. {1: }{4:11 }{3:│}{1: }{2:-----------------}|
  235. {6:~ }{3:│}{6:~ }|
  236. {6:~ }{3:│}{6:~ }|
  237. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  238. :set diffopt=filler |
  239. ]])
  240. feed(':set diffopt+=internal<cr>')
  241. screen:expect([[
  242. {1: }^1 {3:│}{1: }1 |
  243. {1: }2 {3:│}{1: }2 |
  244. {1: }3 {3:│}{1: }3 |
  245. {1: }4 {3:│}{1: }4 |
  246. {1: }{2:------------------}{3:│}{1: }{4:4 }|
  247. {1: }5 {3:│}{1: }5 |
  248. {1: }6 {3:│}{1: }6 |
  249. {1: }7 {3:│}{1: }7 |
  250. {1: }8 {3:│}{1: }8 |
  251. {1: }9 {3:│}{1: }9 |
  252. {1: }10 {3:│}{1: }10 |
  253. {1: }{4:11 }{3:│}{1: }{2:-----------------}|
  254. {6:~ }{3:│}{6:~ }|
  255. {6:~ }{3:│}{6:~ }|
  256. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  257. :set diffopt+=internal |
  258. ]])
  259. end)
  260. it('Add a line in the middle of file 1, remove on at the end of file 2', function()
  261. write_file(fname, "1\n2\n3\n4\n4\n5\n6\n7\n8\n9\n10\n", false)
  262. write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", false)
  263. reread()
  264. feed(':set diffopt=filler<cr>')
  265. screen:expect([[
  266. {1: }^1 {3:│}{1: }1 |
  267. {1: }2 {3:│}{1: }2 |
  268. {1: }3 {3:│}{1: }3 |
  269. {1: }4 {3:│}{1: }4 |
  270. {1: }{4:4 }{3:│}{1: }{2:-----------------}|
  271. {1: }5 {3:│}{1: }5 |
  272. {1: }6 {3:│}{1: }6 |
  273. {1: }7 {3:│}{1: }7 |
  274. {1: }8 {3:│}{1: }8 |
  275. {1: }9 {3:│}{1: }9 |
  276. {1: }10 {3:│}{1: }10 |
  277. {1: }{2:------------------}{3:│}{1: }{4:11 }|
  278. {6:~ }{3:│}{6:~ }|
  279. {6:~ }{3:│}{6:~ }|
  280. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  281. :set diffopt=filler |
  282. ]])
  283. feed(':set diffopt+=internal<cr>')
  284. screen:expect([[
  285. {1: }^1 {3:│}{1: }1 |
  286. {1: }2 {3:│}{1: }2 |
  287. {1: }3 {3:│}{1: }3 |
  288. {1: }4 {3:│}{1: }4 |
  289. {1: }{4:4 }{3:│}{1: }{2:-----------------}|
  290. {1: }5 {3:│}{1: }5 |
  291. {1: }6 {3:│}{1: }6 |
  292. {1: }7 {3:│}{1: }7 |
  293. {1: }8 {3:│}{1: }8 |
  294. {1: }9 {3:│}{1: }9 |
  295. {1: }10 {3:│}{1: }10 |
  296. {1: }{2:------------------}{3:│}{1: }{4:11 }|
  297. {6:~ }{3:│}{6:~ }|
  298. {6:~ }{3:│}{6:~ }|
  299. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  300. :set diffopt+=internal |
  301. ]])
  302. end)
  303. describe('normal/patience/histogram diff algorithm', function()
  304. setup(function()
  305. local f1 = [[#include <stdio.h>
  306. // Frobs foo heartily
  307. int frobnitz(int foo)
  308. {
  309. int i;
  310. for(i = 0; i < 10; i++)
  311. {
  312. printf("Your answer is: ");
  313. printf("%d\n", foo);
  314. }
  315. }
  316. int fact(int n)
  317. {
  318. if(n > 1)
  319. {
  320. return fact(n-1) * n;
  321. }
  322. return 1;
  323. }
  324. int main(int argc, char **argv)
  325. {
  326. frobnitz(fact(10));
  327. }]]
  328. write_file(fname, f1, false)
  329. local f2 = [[#include <stdio.h>
  330. int fib(int n)
  331. {
  332. if(n > 2)
  333. {
  334. return fib(n-1) + fib(n-2);
  335. }
  336. return 1;
  337. }
  338. // Frobs foo heartily
  339. int frobnitz(int foo)
  340. {
  341. int i;
  342. for(i = 0; i < 10; i++)
  343. {
  344. printf("%d\n", foo);
  345. }
  346. }
  347. int main(int argc, char **argv)
  348. {
  349. frobnitz(fib(10));
  350. }]]
  351. write_file(fname_2, f2, false)
  352. end)
  353. it('diffopt=+algorithm:myers', function()
  354. reread()
  355. feed(':set diffopt=internal,filler<cr>')
  356. screen:expect([[
  357. {1: }^#include <stdio.h>{3:│}{1: }#include <stdio.h|
  358. {1: } {3:│}{1: } |
  359. {1: }{8:// Frobs foo heart}{3:│}{1: }{8:int fib(int n)}{9: }|
  360. {1: }{4:int frobnitz(int f}{3:│}{1: }{2:-----------------}|
  361. {1: }{ {3:│}{1: }{ |
  362. {1: }{9: i}{8:nt i;}{9: }{3:│}{1: }{9: i}{8:f(n > 2)}{9: }|
  363. {1: }{4: for(i = 0; i <}{3:│}{1: }{2:-----------------}|
  364. {1: } { {3:│}{1: } { |
  365. {1: }{9: }{8:printf("Yo}{3:│}{1: }{9: }{8:return fi}|
  366. {1: }{4: printf("%d}{3:│}{1: }{2:-----------------}|
  367. {1: } } {3:│}{1: } } |
  368. {1: }{2:------------------}{3:│}{1: }{4: return 1; }|
  369. {1: }} {3:│}{1: }} |
  370. {1: } {3:│}{1: } |
  371. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  372. :set diffopt=internal,filler |
  373. ]])
  374. feed('G')
  375. screen:expect([[
  376. {1: }{2:------------------}{3:│}{1: }{4:int frobnitz(int }|
  377. {1: }{ {3:│}{1: }{ |
  378. {1: }{9: i}{8:f(n > 1)}{9: }{3:│}{1: }{9: i}{8:nt i;}{9: }|
  379. {1: }{2:------------------}{3:│}{1: }{4: for(i = 0; i }|
  380. {1: } { {3:│}{1: } { |
  381. {1: }{9: }{8:return fac}{3:│}{1: }{9: }{8:printf("%}|
  382. {1: } } {3:│}{1: } } |
  383. {1: }{4: return 1; }{3:│}{1: }{2:-----------------}|
  384. {1: }} {3:│}{1: }} |
  385. {1: } {3:│}{1: } |
  386. {1: }int main(int argc,{3:│}{1: }int main(int argc|
  387. {1: }{ {3:│}{1: }{ |
  388. {1: }{9: frobnitz(f}{8:act}{9:(}{3:│}{1: }{9: frobnitz(f}{8:ib}{9:(}|
  389. {1: }^} {3:│}{1: }} |
  390. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  391. :set diffopt=internal,filler |
  392. ]])
  393. end)
  394. it('diffopt+=algorithm:patience', function()
  395. reread()
  396. feed(':set diffopt=internal,filler,algorithm:patience<cr>')
  397. screen:expect([[
  398. {1: }^#include <stdio.h>{3:│}{1: }#include <stdio.h|
  399. {1: } {3:│}{1: } |
  400. {1: }{2:------------------}{3:│}{1: }{4:int fib(int n) }|
  401. {1: }{2:------------------}{3:│}{1: }{4:{ }|
  402. {1: }{2:------------------}{3:│}{1: }{4: if(n > 2) }|
  403. {1: }{2:------------------}{3:│}{1: }{4: { }|
  404. {1: }{2:------------------}{3:│}{1: }{4: return fi}|
  405. {1: }{2:------------------}{3:│}{1: }{4: } }|
  406. {1: }{2:------------------}{3:│}{1: }{4: return 1; }|
  407. {1: }{2:------------------}{3:│}{1: }{4:} }|
  408. {1: }{2:------------------}{3:│}{1: }{4: }|
  409. {1: }// Frobs foo heart{3:│}{1: }// Frobs foo hear|
  410. {1: }int frobnitz(int f{3:│}{1: }int frobnitz(int |
  411. {1: }{ {3:│}{1: }{ |
  412. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  413. |
  414. ]])
  415. feed('G')
  416. screen:expect([[
  417. {1: } {3:│}{1: } |
  418. {1: }{4:int fact(int n) }{3:│}{1: }{2:-----------------}|
  419. {1: }{4:{ }{3:│}{1: }{2:-----------------}|
  420. {1: }{4: if(n > 1) }{3:│}{1: }{2:-----------------}|
  421. {1: }{4: { }{3:│}{1: }{2:-----------------}|
  422. {1: }{4: return fac}{3:│}{1: }{2:-----------------}|
  423. {1: }{4: } }{3:│}{1: }{2:-----------------}|
  424. {1: }{4: return 1; }{3:│}{1: }{2:-----------------}|
  425. {1: }{4:} }{3:│}{1: }{2:-----------------}|
  426. {1: }{4: }{3:│}{1: }{2:-----------------}|
  427. {1: }int main(int argc,{3:│}{1: }int main(int argc|
  428. {1: }{ {3:│}{1: }{ |
  429. {1: }{9: frobnitz(f}{8:act}{9:(}{3:│}{1: }{9: frobnitz(f}{8:ib}{9:(}|
  430. {1: }^} {3:│}{1: }} |
  431. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  432. |
  433. ]])
  434. end)
  435. it('diffopt+=algorithm:histogram', function()
  436. reread()
  437. feed(':set diffopt=internal,filler,algorithm:histogram<cr>')
  438. screen:expect([[
  439. {1: }^#include <stdio.h>{3:│}{1: }#include <stdio.h|
  440. {1: } {3:│}{1: } |
  441. {1: }{2:------------------}{3:│}{1: }{4:int fib(int n) }|
  442. {1: }{2:------------------}{3:│}{1: }{4:{ }|
  443. {1: }{2:------------------}{3:│}{1: }{4: if(n > 2) }|
  444. {1: }{2:------------------}{3:│}{1: }{4: { }|
  445. {1: }{2:------------------}{3:│}{1: }{4: return fi}|
  446. {1: }{2:------------------}{3:│}{1: }{4: } }|
  447. {1: }{2:------------------}{3:│}{1: }{4: return 1; }|
  448. {1: }{2:------------------}{3:│}{1: }{4:} }|
  449. {1: }{2:------------------}{3:│}{1: }{4: }|
  450. {1: }// Frobs foo heart{3:│}{1: }// Frobs foo hear|
  451. {1: }int frobnitz(int f{3:│}{1: }int frobnitz(int |
  452. {1: }{ {3:│}{1: }{ |
  453. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  454. |
  455. ]])
  456. feed('G')
  457. screen:expect([[
  458. {1: } {3:│}{1: } |
  459. {1: }{4:int fact(int n) }{3:│}{1: }{2:-----------------}|
  460. {1: }{4:{ }{3:│}{1: }{2:-----------------}|
  461. {1: }{4: if(n > 1) }{3:│}{1: }{2:-----------------}|
  462. {1: }{4: { }{3:│}{1: }{2:-----------------}|
  463. {1: }{4: return fac}{3:│}{1: }{2:-----------------}|
  464. {1: }{4: } }{3:│}{1: }{2:-----------------}|
  465. {1: }{4: return 1; }{3:│}{1: }{2:-----------------}|
  466. {1: }{4:} }{3:│}{1: }{2:-----------------}|
  467. {1: }{4: }{3:│}{1: }{2:-----------------}|
  468. {1: }int main(int argc,{3:│}{1: }int main(int argc|
  469. {1: }{ {3:│}{1: }{ |
  470. {1: }{9: frobnitz(f}{8:act}{9:(}{3:│}{1: }{9: frobnitz(f}{8:ib}{9:(}|
  471. {1: }^} {3:│}{1: }} |
  472. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  473. |
  474. ]])
  475. end)
  476. end)
  477. describe('diffopt+=indent-heuristic', function()
  478. setup(function()
  479. local f1 = [[
  480. def finalize(values)
  481. values.each do |v|
  482. v.finalize
  483. end]]
  484. write_file(fname, f1, false)
  485. local f2 = [[
  486. def finalize(values)
  487. values.each do |v|
  488. v.prepare
  489. end
  490. values.each do |v|
  491. v.finalize
  492. end]]
  493. write_file(fname_2, f2, false)
  494. feed(':diffupdate!<cr>')
  495. end)
  496. it('internal', function()
  497. reread()
  498. feed(":set diffopt=internal,filler<cr>")
  499. screen:expect([[
  500. {1: }^def finalize(value{3:│}{1: }def finalize(valu|
  501. {1: } {3:│}{1: } |
  502. {1: } values.each do |{3:│}{1: } values.each do |
  503. {1: }{2:------------------}{3:│}{1: }{4: v.prepare }|
  504. {1: }{2:------------------}{3:│}{1: }{4: end }|
  505. {1: }{2:------------------}{3:│}{1: }{4: }|
  506. {1: }{2:------------------}{3:│}{1: }{4: values.each do }|
  507. {1: } v.finalize {3:│}{1: } v.finalize |
  508. {1: } end {3:│}{1: } end |
  509. {6:~ }{3:│}{6:~ }|
  510. {6:~ }{3:│}{6:~ }|
  511. {6:~ }{3:│}{6:~ }|
  512. {6:~ }{3:│}{6:~ }|
  513. {6:~ }{3:│}{6:~ }|
  514. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  515. :set diffopt=internal,filler |
  516. ]])
  517. end)
  518. it('indent-heuristic', function()
  519. reread()
  520. feed(':set diffopt=internal,filler,indent-heuristic<cr>')
  521. screen:expect([[
  522. {1: }^def finalize(value{3:│}{1: }def finalize(valu|
  523. {1: } {3:│}{1: } |
  524. {1: }{2:------------------}{3:│}{1: }{4: values.each do }|
  525. {1: }{2:------------------}{3:│}{1: }{4: v.prepare }|
  526. {1: }{2:------------------}{3:│}{1: }{4: end }|
  527. {1: }{2:------------------}{3:│}{1: }{4: }|
  528. {1: } values.each do |{3:│}{1: } values.each do |
  529. {1: } v.finalize {3:│}{1: } v.finalize |
  530. {1: } end {3:│}{1: } end |
  531. {6:~ }{3:│}{6:~ }|
  532. {6:~ }{3:│}{6:~ }|
  533. {6:~ }{3:│}{6:~ }|
  534. {6:~ }{3:│}{6:~ }|
  535. {6:~ }{3:│}{6:~ }|
  536. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  537. |
  538. ]])
  539. end)
  540. it('indent-heuristic random order', function()
  541. reread()
  542. feed(':set diffopt=internal,filler,indent-heuristic,algorithm:patience<cr>')
  543. feed(':<cr>')
  544. screen:expect([[
  545. {1: }^def finalize(value{3:│}{1: }def finalize(valu|
  546. {1: } {3:│}{1: } |
  547. {1: }{2:------------------}{3:│}{1: }{4: values.each do }|
  548. {1: }{2:------------------}{3:│}{1: }{4: v.prepare }|
  549. {1: }{2:------------------}{3:│}{1: }{4: end }|
  550. {1: }{2:------------------}{3:│}{1: }{4: }|
  551. {1: } values.each do |{3:│}{1: } values.each do |
  552. {1: } v.finalize {3:│}{1: } v.finalize |
  553. {1: } end {3:│}{1: } end |
  554. {6:~ }{3:│}{6:~ }|
  555. {6:~ }{3:│}{6:~ }|
  556. {6:~ }{3:│}{6:~ }|
  557. {6:~ }{3:│}{6:~ }|
  558. {6:~ }{3:│}{6:~ }|
  559. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  560. : |
  561. ]])
  562. end)
  563. end)
  564. it('Diff the same file', function()
  565. write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
  566. write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
  567. reread()
  568. feed(':set diffopt=filler<cr>')
  569. screen:expect([[
  570. {1:+ }{5:^+-- 10 lines: 1···}{3:│}{1:+ }{5:+-- 10 lines: 1··}|
  571. {6:~ }{3:│}{6:~ }|
  572. {6:~ }{3:│}{6:~ }|
  573. {6:~ }{3:│}{6:~ }|
  574. {6:~ }{3:│}{6:~ }|
  575. {6:~ }{3:│}{6:~ }|
  576. {6:~ }{3:│}{6:~ }|
  577. {6:~ }{3:│}{6:~ }|
  578. {6:~ }{3:│}{6:~ }|
  579. {6:~ }{3:│}{6:~ }|
  580. {6:~ }{3:│}{6:~ }|
  581. {6:~ }{3:│}{6:~ }|
  582. {6:~ }{3:│}{6:~ }|
  583. {6:~ }{3:│}{6:~ }|
  584. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  585. :set diffopt=filler |
  586. ]])
  587. feed(':set diffopt+=internal<cr>')
  588. screen:expect([[
  589. {1:+ }{5:^+-- 10 lines: 1···}{3:│}{1:+ }{5:+-- 10 lines: 1··}|
  590. {6:~ }{3:│}{6:~ }|
  591. {6:~ }{3:│}{6:~ }|
  592. {6:~ }{3:│}{6:~ }|
  593. {6:~ }{3:│}{6:~ }|
  594. {6:~ }{3:│}{6:~ }|
  595. {6:~ }{3:│}{6:~ }|
  596. {6:~ }{3:│}{6:~ }|
  597. {6:~ }{3:│}{6:~ }|
  598. {6:~ }{3:│}{6:~ }|
  599. {6:~ }{3:│}{6:~ }|
  600. {6:~ }{3:│}{6:~ }|
  601. {6:~ }{3:│}{6:~ }|
  602. {6:~ }{3:│}{6:~ }|
  603. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  604. :set diffopt+=internal |
  605. ]])
  606. end)
  607. it('Diff an empty file', function()
  608. write_file(fname, "", false)
  609. write_file(fname_2, "", false)
  610. reread()
  611. feed(':set diffopt=filler<cr>')
  612. screen:expect([[
  613. {1:- }^ {3:│}{1:- } |
  614. {6:~ }{3:│}{6:~ }|
  615. {6:~ }{3:│}{6:~ }|
  616. {6:~ }{3:│}{6:~ }|
  617. {6:~ }{3:│}{6:~ }|
  618. {6:~ }{3:│}{6:~ }|
  619. {6:~ }{3:│}{6:~ }|
  620. {6:~ }{3:│}{6:~ }|
  621. {6:~ }{3:│}{6:~ }|
  622. {6:~ }{3:│}{6:~ }|
  623. {6:~ }{3:│}{6:~ }|
  624. {6:~ }{3:│}{6:~ }|
  625. {6:~ }{3:│}{6:~ }|
  626. {6:~ }{3:│}{6:~ }|
  627. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  628. :set diffopt=filler |
  629. ]])
  630. feed(':set diffopt+=internal<cr>')
  631. screen:expect([[
  632. {1:- }^ {3:│}{1:- } |
  633. {6:~ }{3:│}{6:~ }|
  634. {6:~ }{3:│}{6:~ }|
  635. {6:~ }{3:│}{6:~ }|
  636. {6:~ }{3:│}{6:~ }|
  637. {6:~ }{3:│}{6:~ }|
  638. {6:~ }{3:│}{6:~ }|
  639. {6:~ }{3:│}{6:~ }|
  640. {6:~ }{3:│}{6:~ }|
  641. {6:~ }{3:│}{6:~ }|
  642. {6:~ }{3:│}{6:~ }|
  643. {6:~ }{3:│}{6:~ }|
  644. {6:~ }{3:│}{6:~ }|
  645. {6:~ }{3:│}{6:~ }|
  646. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  647. :set diffopt+=internal |
  648. ]])
  649. end)
  650. it('diffopt+=icase', function()
  651. write_file(fname, "a\nb\ncd\n", false)
  652. write_file(fname_2, "A\nb\ncDe\n", false)
  653. reread()
  654. feed(':set diffopt=filler,icase<cr>')
  655. screen:expect([[
  656. {1: }^a {3:│}{1: }A |
  657. {1: }b {3:│}{1: }b |
  658. {1: }{9:cd }{3:│}{1: }{9:cD}{8:e}{9: }|
  659. {6:~ }{3:│}{6:~ }|
  660. {6:~ }{3:│}{6:~ }|
  661. {6:~ }{3:│}{6:~ }|
  662. {6:~ }{3:│}{6:~ }|
  663. {6:~ }{3:│}{6:~ }|
  664. {6:~ }{3:│}{6:~ }|
  665. {6:~ }{3:│}{6:~ }|
  666. {6:~ }{3:│}{6:~ }|
  667. {6:~ }{3:│}{6:~ }|
  668. {6:~ }{3:│}{6:~ }|
  669. {6:~ }{3:│}{6:~ }|
  670. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  671. :set diffopt=filler,icase |
  672. ]])
  673. feed(':set diffopt+=internal<cr>')
  674. screen:expect([[
  675. {1: }^a {3:│}{1: }A |
  676. {1: }b {3:│}{1: }b |
  677. {1: }{9:cd }{3:│}{1: }{9:cD}{8:e}{9: }|
  678. {6:~ }{3:│}{6:~ }|
  679. {6:~ }{3:│}{6:~ }|
  680. {6:~ }{3:│}{6:~ }|
  681. {6:~ }{3:│}{6:~ }|
  682. {6:~ }{3:│}{6:~ }|
  683. {6:~ }{3:│}{6:~ }|
  684. {6:~ }{3:│}{6:~ }|
  685. {6:~ }{3:│}{6:~ }|
  686. {6:~ }{3:│}{6:~ }|
  687. {6:~ }{3:│}{6:~ }|
  688. {6:~ }{3:│}{6:~ }|
  689. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  690. :set diffopt+=internal |
  691. ]])
  692. end)
  693. describe('diffopt+=iwhite', function()
  694. setup(function()
  695. local f1 = 'int main()\n{\n printf("Hello, World!");\n return 0;\n}\n'
  696. write_file(fname, f1, false)
  697. local f2 = 'int main()\n{\n if (0)\n {\n printf("Hello, World!");\n return 0;\n }\n}\n'
  698. write_file(fname_2, f2, false)
  699. feed(':diffupdate!<cr>')
  700. end)
  701. it('external', function()
  702. reread()
  703. feed(':set diffopt=filler,iwhite<cr>')
  704. screen:expect([[
  705. {1: }^int main() {3:│}{1: }int main() |
  706. {1: }{ {3:│}{1: }{ |
  707. {1: }{2:------------------}{3:│}{1: }{4: if (0) }|
  708. {1: }{2:------------------}{3:│}{1: }{4: { }|
  709. {1: } printf("Hello, {3:│}{1: } printf("Hel|
  710. {1: } return 0; {3:│}{1: } return 0; |
  711. {1: }{2:------------------}{3:│}{1: }{4: } }|
  712. {1: }} {3:│}{1: }} |
  713. {6:~ }{3:│}{6:~ }|
  714. {6:~ }{3:│}{6:~ }|
  715. {6:~ }{3:│}{6:~ }|
  716. {6:~ }{3:│}{6:~ }|
  717. {6:~ }{3:│}{6:~ }|
  718. {6:~ }{3:│}{6:~ }|
  719. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  720. :set diffopt=filler,iwhite |
  721. ]])
  722. end)
  723. it('internal', function()
  724. reread()
  725. feed(':set diffopt=filler,iwhite,internal<cr>')
  726. screen:expect([[
  727. {1: }^int main() {3:│}{1: }int main() |
  728. {1: }{ {3:│}{1: }{ |
  729. {1: }{2:------------------}{3:│}{1: }{4: if (0) }|
  730. {1: }{2:------------------}{3:│}{1: }{4: { }|
  731. {1: } printf("Hello, {3:│}{1: } printf("Hel|
  732. {1: } return 0; {3:│}{1: } return 0; |
  733. {1: }{2:------------------}{3:│}{1: }{4: } }|
  734. {1: }} {3:│}{1: }} |
  735. {6:~ }{3:│}{6:~ }|
  736. {6:~ }{3:│}{6:~ }|
  737. {6:~ }{3:│}{6:~ }|
  738. {6:~ }{3:│}{6:~ }|
  739. {6:~ }{3:│}{6:~ }|
  740. {6:~ }{3:│}{6:~ }|
  741. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  742. :set diffopt=filler,iwhite,internal |
  743. ]])
  744. end)
  745. end)
  746. describe('diffopt+=iblank', function()
  747. setup(function()
  748. write_file(fname, 'a\n\n \ncd\nef\nxxx\n', false)
  749. write_file(fname_2, 'a\ncd\n\nef\nyyy\n', false)
  750. feed(':diffupdate!<cr>')
  751. end)
  752. it('generic', function()
  753. reread()
  754. feed(':set diffopt=internal,filler,iblank<cr>')
  755. screen:expect([[
  756. {1: }^a {3:│}{1: }a |
  757. {1: }{4: }{3:│}{1: }{2:-----------------}|
  758. {1: }{4: }{3:│}{1: }{2:-----------------}|
  759. {1: }cd {3:│}{1: }cd |
  760. {1: }ef {3:│}{1: } |
  761. {1: }{8:xxx}{9: }{3:│}{1: }ef |
  762. {6:~ }{3:│}{1: }{8:yyy}{9: }|
  763. {6:~ }{3:│}{6:~ }|
  764. {6:~ }{3:│}{6:~ }|
  765. {6:~ }{3:│}{6:~ }|
  766. {6:~ }{3:│}{6:~ }|
  767. {6:~ }{3:│}{6:~ }|
  768. {6:~ }{3:│}{6:~ }|
  769. {6:~ }{3:│}{6:~ }|
  770. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  771. :set diffopt=internal,filler,iblank |
  772. ]])
  773. end)
  774. it('diffopt+=iwhite', function()
  775. reread()
  776. feed(':set diffopt=internal,filler,iblank,iwhite<cr>')
  777. feed(':<cr>')
  778. screen:expect([[
  779. {1: }^a {3:│}{1: }a |
  780. {1: } {3:│}{1: }cd |
  781. {1: } {3:│}{1: } |
  782. {1: }cd {3:│}{1: }ef |
  783. {1: }ef {3:│}{1: }{8:yyy}{9: }|
  784. {1: }{8:xxx}{9: }{3:│}{6:~ }|
  785. {6:~ }{3:│}{6:~ }|
  786. {6:~ }{3:│}{6:~ }|
  787. {6:~ }{3:│}{6:~ }|
  788. {6:~ }{3:│}{6:~ }|
  789. {6:~ }{3:│}{6:~ }|
  790. {6:~ }{3:│}{6:~ }|
  791. {6:~ }{3:│}{6:~ }|
  792. {6:~ }{3:│}{6:~ }|
  793. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  794. : |
  795. ]])
  796. end)
  797. it('diffopt+=iwhiteall', function()
  798. reread()
  799. feed(':set diffopt=internal,filler,iblank,iwhiteall<cr>')
  800. feed(':<cr>')
  801. screen:expect([[
  802. {1: }^a {3:│}{1: }a |
  803. {1: } {3:│}{1: }cd |
  804. {1: } {3:│}{1: } |
  805. {1: }cd {3:│}{1: }ef |
  806. {1: }ef {3:│}{1: }{8:yyy}{9: }|
  807. {1: }{8:xxx}{9: }{3:│}{6:~ }|
  808. {6:~ }{3:│}{6:~ }|
  809. {6:~ }{3:│}{6:~ }|
  810. {6:~ }{3:│}{6:~ }|
  811. {6:~ }{3:│}{6:~ }|
  812. {6:~ }{3:│}{6:~ }|
  813. {6:~ }{3:│}{6:~ }|
  814. {6:~ }{3:│}{6:~ }|
  815. {6:~ }{3:│}{6:~ }|
  816. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  817. : |
  818. ]])
  819. end)
  820. it('diffopt+=iwhiteeol', function()
  821. reread()
  822. feed(':set diffopt=internal,filler,iblank,iwhiteeol<cr>')
  823. feed(':<cr>')
  824. screen:expect([[
  825. {1: }^a {3:│}{1: }a |
  826. {1: } {3:│}{1: }cd |
  827. {1: } {3:│}{1: } |
  828. {1: }cd {3:│}{1: }ef |
  829. {1: }ef {3:│}{1: }{8:yyy}{9: }|
  830. {1: }{8:xxx}{9: }{3:│}{6:~ }|
  831. {6:~ }{3:│}{6:~ }|
  832. {6:~ }{3:│}{6:~ }|
  833. {6:~ }{3:│}{6:~ }|
  834. {6:~ }{3:│}{6:~ }|
  835. {6:~ }{3:│}{6:~ }|
  836. {6:~ }{3:│}{6:~ }|
  837. {6:~ }{3:│}{6:~ }|
  838. {6:~ }{3:│}{6:~ }|
  839. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  840. : |
  841. ]])
  842. end)
  843. end)
  844. describe('diffopt+=iwhite{eol,all}', function()
  845. setup(function()
  846. write_file(fname, 'a \nx\ncd\nef\nxx xx\nfoo\nbar\n', false)
  847. write_file(fname_2, 'a\nx\nc d\n ef\nxx xx\nfoo\n\nbar\n', false)
  848. feed(':diffupdate!<cr>')
  849. end)
  850. it('diffopt+=iwhiteeol', function()
  851. reread()
  852. feed(':set diffopt=internal,filler,iwhiteeol<cr>')
  853. feed(':<cr>')
  854. screen:expect([[
  855. {1: }^a {3:│}{1: }a |
  856. {1: }x {3:│}{1: }x |
  857. {1: }{9:cd }{3:│}{1: }{9:c}{8: }{9:d }|
  858. {1: }{9:ef }{3:│}{1: }{8: }{9:ef }|
  859. {1: }{9:xx }{8: }{9:xx }{3:│}{1: }{9:xx xx }|
  860. {1: }foo {3:│}{1: }foo |
  861. {1: }{2:------------------}{3:│}{1: }{4: }|
  862. {1: }bar {3:│}{1: }bar |
  863. {6:~ }{3:│}{6:~ }|
  864. {6:~ }{3:│}{6:~ }|
  865. {6:~ }{3:│}{6:~ }|
  866. {6:~ }{3:│}{6:~ }|
  867. {6:~ }{3:│}{6:~ }|
  868. {6:~ }{3:│}{6:~ }|
  869. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  870. : |
  871. ]])
  872. end)
  873. it('diffopt+=iwhiteall', function()
  874. reread()
  875. feed(':set diffopt=internal,filler,iwhiteall<cr>')
  876. feed(':<cr>')
  877. screen:expect([[
  878. {1: }^a {3:│}{1: }a |
  879. {1: }x {3:│}{1: }x |
  880. {1: }cd {3:│}{1: }c d |
  881. {1: }ef {3:│}{1: } ef |
  882. {1: }xx xx {3:│}{1: }xx xx |
  883. {1: }foo {3:│}{1: }foo |
  884. {1: }{2:------------------}{3:│}{1: }{4: }|
  885. {1: }bar {3:│}{1: }bar |
  886. {6:~ }{3:│}{6:~ }|
  887. {6:~ }{3:│}{6:~ }|
  888. {6:~ }{3:│}{6:~ }|
  889. {6:~ }{3:│}{6:~ }|
  890. {6:~ }{3:│}{6:~ }|
  891. {6:~ }{3:│}{6:~ }|
  892. {7:<onal-diff-screen-1 }{3:<l-diff-screen-1.2 }|
  893. : |
  894. ]])
  895. end)
  896. end)
  897. end)
  898. it('win_update redraws lines properly', function()
  899. local screen
  900. clear()
  901. screen = Screen.new(50, 10)
  902. screen:attach()
  903. screen:set_default_attr_ids({
  904. [1] = {bold = true, foreground = Screen.colors.Blue1},
  905. [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
  906. [3] = {background = Screen.colors.Red, foreground = Screen.colors.Grey100, special = Screen.colors.Yellow},
  907. [4] = {bold = true, foreground = Screen.colors.SeaGreen4},
  908. [5] = {special = Screen.colors.Yellow},
  909. [6] = {special = Screen.colors.Yellow, bold = true, foreground = Screen.colors.SeaGreen4},
  910. [7] = {foreground = Screen.colors.Grey0, background = Screen.colors.Grey100},
  911. [8] = {foreground = Screen.colors.Gray90, background = Screen.colors.Grey100},
  912. [9] = {foreground = tonumber('0x00000c'), background = Screen.colors.Grey100},
  913. [10] = {background = Screen.colors.Grey100, bold = true, foreground = tonumber('0xe5e5ff')},
  914. [11] = {background = Screen.colors.Grey100, bold = true, foreground = tonumber('0x2b8452')},
  915. [12] = {bold = true, reverse = true},
  916. [13] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
  917. [14] = {reverse = true},
  918. [15] = {background = Screen.colors.LightBlue},
  919. [16] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
  920. [17] = {bold = true, background = Screen.colors.Red},
  921. [18] = {background = Screen.colors.LightMagenta},
  922. })
  923. insert([[
  924. 1
  925. 2
  926. 1a
  927. ]])
  928. command("vnew left")
  929. insert([[
  930. 2
  931. 2a
  932. 2b
  933. ]])
  934. command("windo diffthis")
  935. command("windo 1")
  936. screen:expect{grid=[[
  937. {13: }{16:-----------------------}{14:│}{13: }{15:^1 }|
  938. {13: }{16:-----------------------}{14:│}{13: }{15: }|
  939. {13: }{16:-----------------------}{14:│}{13: }{15: }|
  940. {13: }2 {14:│}{13: }2 |
  941. {13: }{17:2}{18:a }{14:│}{13: }{17:1}{18:a }|
  942. {13: }{15:2b }{14:│}{13: }{16:----------------------}|
  943. {13: } {14:│}{13: } |
  944. {1:~ }{14:│}{1:~ }|
  945. {14:left [+] }{12:[No Name] [+] }|
  946. |
  947. ]]}
  948. feed('<C-e>')
  949. feed('<C-e>')
  950. feed('<C-y>')
  951. feed('<C-y>')
  952. feed('<C-y>')
  953. screen:expect{grid=[[
  954. {13: }{16:-----------------------}{14:│}{13: }{15:1 }|
  955. {13: }{16:-----------------------}{14:│}{13: }{15: }|
  956. {13: }{16:-----------------------}{14:│}{13: }{15:^ }|
  957. {13: }2 {14:│}{13: }2 |
  958. {13: }{17:2}{18:a }{14:│}{13: }{17:1}{18:a }|
  959. {13: }{15:2b }{14:│}{13: }{16:----------------------}|
  960. {13: } {14:│}{13: } |
  961. {1:~ }{14:│}{1:~ }|
  962. {14:left [+] }{12:[No Name] [+] }|
  963. |
  964. ]]}
  965. end)
  966. it('diff updates line numbers below filler lines', function()
  967. clear()
  968. local screen = Screen.new(40, 14)
  969. screen:attach()
  970. screen:set_default_attr_ids({
  971. [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
  972. [2] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
  973. [3] = {reverse = true},
  974. [4] = {background = Screen.colors.LightBlue},
  975. [5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
  976. [6] = {bold = true, foreground = Screen.colors.Blue1},
  977. [7] = {bold = true, reverse = true},
  978. [8] = {bold = true, background = Screen.colors.Red},
  979. [9] = {background = Screen.colors.LightMagenta},
  980. [10] = {bold = true, foreground = Screen.colors.Brown},
  981. [11] = {foreground = Screen.colors.Brown},
  982. [12] = {foreground = Screen.colors.Brown, bold = true, background = Screen.colors.Red};
  983. [13] = {background = Screen.colors.Gray90};
  984. })
  985. source([[
  986. call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b'])
  987. vnew
  988. call setline(1, ['a', 'a', 'a', 'x', 'x', 'x', 'b', 'b', 'b', 'b', 'b'])
  989. windo diffthis
  990. setlocal number rnu foldcolumn=0
  991. ]])
  992. screen:expect([[
  993. {1: }a {3:│}{10:1 }^a |
  994. {1: }a {3:│}{11: 1 }a |
  995. {1: }a {3:│}{11: 2 }a |
  996. {1: }{8:x}{9: }{3:│}{11: 3 }{8:y}{9: }|
  997. {1: }{4:x }{3:│}{11: }{2:----------------}|
  998. {1: }{4:x }{3:│}{11: }{2:----------------}|
  999. {1: }b {3:│}{11: 4 }b |
  1000. {1: }b {3:│}{11: 5 }b |
  1001. {1: }b {3:│}{11: 6 }b |
  1002. {1: }b {3:│}{11: 7 }b |
  1003. {1: }b {3:│}{11: 8 }b |
  1004. {6:~ }{3:│}{6:~ }|
  1005. {3:[No Name] [+] }{7:[No Name] [+] }|
  1006. |
  1007. ]])
  1008. feed('j')
  1009. screen:expect([[
  1010. {1: }a {3:│}{11: 1 }a |
  1011. {1: }a {3:│}{10:2 }^a |
  1012. {1: }a {3:│}{11: 1 }a |
  1013. {1: }{8:x}{9: }{3:│}{11: 2 }{8:y}{9: }|
  1014. {1: }{4:x }{3:│}{11: }{2:----------------}|
  1015. {1: }{4:x }{3:│}{11: }{2:----------------}|
  1016. {1: }b {3:│}{11: 3 }b |
  1017. {1: }b {3:│}{11: 4 }b |
  1018. {1: }b {3:│}{11: 5 }b |
  1019. {1: }b {3:│}{11: 6 }b |
  1020. {1: }b {3:│}{11: 7 }b |
  1021. {6:~ }{3:│}{6:~ }|
  1022. {3:[No Name] [+] }{7:[No Name] [+] }|
  1023. |
  1024. ]])
  1025. feed('j')
  1026. screen:expect([[
  1027. {1: }a {3:│}{11: 2 }a |
  1028. {1: }a {3:│}{11: 1 }a |
  1029. {1: }a {3:│}{10:3 }^a |
  1030. {1: }{8:x}{9: }{3:│}{11: 1 }{8:y}{9: }|
  1031. {1: }{4:x }{3:│}{11: }{2:----------------}|
  1032. {1: }{4:x }{3:│}{11: }{2:----------------}|
  1033. {1: }b {3:│}{11: 2 }b |
  1034. {1: }b {3:│}{11: 3 }b |
  1035. {1: }b {3:│}{11: 4 }b |
  1036. {1: }b {3:│}{11: 5 }b |
  1037. {1: }b {3:│}{11: 6 }b |
  1038. {6:~ }{3:│}{6:~ }|
  1039. {3:[No Name] [+] }{7:[No Name] [+] }|
  1040. |
  1041. ]])
  1042. command("set signcolumn number tgc cursorline")
  1043. command("hi CursorLineNr guibg=red")
  1044. screen:expect{grid=[[
  1045. {1: }a {3:│}{11: 2 }a |
  1046. {1: }a {3:│}{11: 1 }a |
  1047. {1: }a {3:│}{12:3 }{13:^a }|
  1048. {1: }{8:x}{9: }{3:│}{11: 1 }{8:y}{9: }|
  1049. {1: }{4:x }{3:│}{11: }{2:----------------}|
  1050. {1: }{4:x }{3:│}{11: }{2:----------------}|
  1051. {1: }b {3:│}{11: 2 }b |
  1052. {1: }b {3:│}{11: 3 }b |
  1053. {1: }b {3:│}{11: 4 }b |
  1054. {1: }b {3:│}{11: 5 }b |
  1055. {1: }b {3:│}{11: 6 }b |
  1056. {6:~ }{3:│}{6:~ }|
  1057. {3:[No Name] [+] }{7:[No Name] [+] }|
  1058. signcolumn=auto |
  1059. ]]}
  1060. end)