syntax_conceal_spec.lua 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local clear, feed, command = helpers.clear, helpers.feed, helpers.command
  4. local eq = helpers.eq
  5. local insert = helpers.insert
  6. local poke_eventloop = helpers.poke_eventloop
  7. describe('Screen', function()
  8. local screen
  9. before_each(function()
  10. clear()
  11. screen = Screen.new(nil,10)
  12. screen:attach()
  13. screen:set_default_attr_ids( {
  14. [0] = {bold=true, foreground=Screen.colors.Blue},
  15. [1] = {foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray},
  16. [2] = {bold = true, reverse = true},
  17. [3] = {reverse = true},
  18. [4] = {bold = true},
  19. [5] = {background = Screen.colors.Yellow},
  20. [6] = {background = Screen.colors.LightGrey},
  21. } )
  22. end)
  23. describe("match and conceal", function()
  24. before_each(function()
  25. command("let &conceallevel=1")
  26. end)
  27. describe("multiple", function()
  28. before_each(function()
  29. insert([[
  30. &&
  31. &&
  32. &&
  33. &&
  34. &&
  35. &&
  36. ]])
  37. command("syn match dAmpersand '[&][&]' conceal cchar=∧")
  38. end)
  39. it("double characters.", function()
  40. screen:expect([[
  41. {1:∧} |
  42. {1:∧} |
  43. {1:∧} |
  44. {1:∧} |
  45. {1:∧} |
  46. {1:∧} |
  47. ^ |
  48. {0:~ }|
  49. {0:~ }|
  50. |
  51. ]])
  52. end)
  53. it('double characters and move the cursor one line up.', function()
  54. feed("k")
  55. screen:expect([[
  56. {1:∧} |
  57. {1:∧} |
  58. {1:∧} |
  59. {1:∧} |
  60. {1:∧} |
  61. ^&& |
  62. |
  63. {0:~ }|
  64. {0:~ }|
  65. |
  66. ]])
  67. end)
  68. it('double characters and move the cursor to the beginning of the file.', function()
  69. feed("gg")
  70. screen:expect([[
  71. ^&& |
  72. {1:∧} |
  73. {1:∧} |
  74. {1:∧} |
  75. {1:∧} |
  76. {1:∧} |
  77. |
  78. {0:~ }|
  79. {0:~ }|
  80. |
  81. ]])
  82. end)
  83. it('double characters and move the cursor to the second line in the file.', function()
  84. feed("ggj")
  85. screen:expect([[
  86. {1:∧} |
  87. ^&& |
  88. {1:∧} |
  89. {1:∧} |
  90. {1:∧} |
  91. {1:∧} |
  92. |
  93. {0:~ }|
  94. {0:~ }|
  95. |
  96. ]])
  97. end)
  98. it('double characters and then move the cursor to the beginning of the file and back to the end of the file.', function()
  99. feed("ggG")
  100. screen:expect([[
  101. {1:∧} |
  102. {1:∧} |
  103. {1:∧} |
  104. {1:∧} |
  105. {1:∧} |
  106. {1:∧} |
  107. ^ |
  108. {0:~ }|
  109. {0:~ }|
  110. |
  111. ]])
  112. end)
  113. end) -- multiple
  114. it("keyword instances in initially in the document.", function()
  115. feed("2ilambda<cr><ESC>")
  116. command("let &conceallevel=1")
  117. command("syn keyword kLambda lambda conceal cchar=λ")
  118. screen:expect([[
  119. {1:λ} |
  120. {1:λ} |
  121. ^ |
  122. {0:~ }|
  123. {0:~ }|
  124. {0:~ }|
  125. {0:~ }|
  126. {0:~ }|
  127. {0:~ }|
  128. |
  129. ]])
  130. end) -- Keyword
  131. describe("regions in the document", function()
  132. before_each(function()
  133. feed("2")
  134. insert("<r> a region of text </r>\n")
  135. command("let &conceallevel=1")
  136. end)
  137. it('initially and conceal it.', function()
  138. command("syn region rText start='<r>' end='</r>' conceal cchar=R")
  139. screen:expect([[
  140. {1:R} |
  141. {1:R} |
  142. ^ |
  143. {0:~ }|
  144. {0:~ }|
  145. {0:~ }|
  146. {0:~ }|
  147. {0:~ }|
  148. {0:~ }|
  149. |
  150. ]])
  151. end)
  152. it('initially and conceal its start tag and end tag.', function()
  153. -- concealends has a known bug (todo.txt) where the first match won't
  154. -- be replaced with cchar.
  155. command("syn region rText matchgroup=rMatch start='<r>' end='</r>' concealends cchar=-")
  156. screen:expect([[
  157. {1: } a region of text {1:-} |
  158. {1: } a region of text {1:-} |
  159. ^ |
  160. {0:~ }|
  161. {0:~ }|
  162. {0:~ }|
  163. {0:~ }|
  164. {0:~ }|
  165. {0:~ }|
  166. |
  167. ]])
  168. end)
  169. it('that are nested and conceal the nested region\'s start and end tags.', function()
  170. command("syn region rText contains=rText matchgroup=rMatch start='<r>' end='</r>' concealends cchar=-")
  171. insert("<r> A region with <r> a nested <r> nested region.</r> </r> </r>\n")
  172. screen:expect([[
  173. {1: } a region of text {1:-} |
  174. {1: } a region of text {1:-} |
  175. {1: } A region with {1: } a nested {1: } nested region.{1:-} |
  176. {1:-} {1:-} |
  177. ^ |
  178. {0:~ }|
  179. {0:~ }|
  180. {0:~ }|
  181. {0:~ }|
  182. |
  183. ]])
  184. end)
  185. end) -- regions in the document
  186. describe("a region of text", function()
  187. before_each(function()
  188. command("syntax conceal on")
  189. feed("2")
  190. insert("<r> a region of text </r>\n")
  191. command("syn region rText start='<r>' end='</r>' cchar=-")
  192. end)
  193. it("and turn on implicit concealing", function()
  194. screen:expect([[
  195. {1:-} |
  196. {1:-} |
  197. ^ |
  198. {0:~ }|
  199. {0:~ }|
  200. {0:~ }|
  201. {0:~ }|
  202. {0:~ }|
  203. {0:~ }|
  204. |
  205. ]])
  206. end)
  207. it("and then turn on, then off, and then back on implicit concealing.", function()
  208. command("syntax conceal off")
  209. feed("2")
  210. insert("<i> italian text </i>\n")
  211. command("syn region iText start='<i>' end='</i>' cchar=*")
  212. screen:expect([[
  213. {1:-} |
  214. {1:-} |
  215. <i> italian text </i> |
  216. <i> italian text </i> |
  217. ^ |
  218. {0:~ }|
  219. {0:~ }|
  220. {0:~ }|
  221. {0:~ }|
  222. |
  223. ]])
  224. command("syntax conceal on")
  225. command("syn region iText start='<i>' end='</i>' cchar=*")
  226. screen:expect([[
  227. {1:-} |
  228. {1:-} |
  229. {1:*} |
  230. {1:*} |
  231. ^ |
  232. {0:~ }|
  233. {0:~ }|
  234. {0:~ }|
  235. {0:~ }|
  236. |
  237. ]])
  238. end)
  239. end) -- a region of text (implicit concealing)
  240. it("cursor position is correct when entering Insert mode with cocu=ni #13916", function()
  241. insert([[foobarfoobarfoobar]])
  242. -- move to end of line
  243. feed("$")
  244. command("set concealcursor=ni")
  245. command("syn match Foo /foobar/ conceal cchar=&")
  246. screen:expect([[
  247. {1:&&&}^ |
  248. {0:~ }|
  249. {0:~ }|
  250. {0:~ }|
  251. {0:~ }|
  252. {0:~ }|
  253. {0:~ }|
  254. {0:~ }|
  255. {0:~ }|
  256. |
  257. ]])
  258. feed("i")
  259. -- cursor should stay in place, not jump to column 16
  260. screen:expect([[
  261. {1:&&&}^ |
  262. {0:~ }|
  263. {0:~ }|
  264. {0:~ }|
  265. {0:~ }|
  266. {0:~ }|
  267. {0:~ }|
  268. {0:~ }|
  269. {0:~ }|
  270. {4:-- INSERT --} |
  271. ]])
  272. end)
  273. end) -- match and conceal
  274. describe("let the conceal level be", function()
  275. before_each(function()
  276. insert("// No Conceal\n")
  277. insert('"Conceal without a cchar"\n')
  278. insert("+ With cchar\n\n")
  279. command("syn match noConceal '^//.*$'")
  280. command("syn match concealNoCchar '\".\\{-}\"$' conceal")
  281. command("syn match concealWCchar '^+.\\{-}$' conceal cchar=C")
  282. end)
  283. it("0. No concealing.", function()
  284. command("let &conceallevel=0")
  285. screen:expect([[
  286. // No Conceal |
  287. "Conceal without a cchar" |
  288. + With cchar |
  289. |
  290. ^ |
  291. {0:~ }|
  292. {0:~ }|
  293. {0:~ }|
  294. {0:~ }|
  295. |
  296. ]])
  297. end)
  298. it("1. Conceal using cchar or reference listchars.", function()
  299. command("let &conceallevel=1")
  300. screen:expect([[
  301. // No Conceal |
  302. {1: } |
  303. {1:C} |
  304. |
  305. ^ |
  306. {0:~ }|
  307. {0:~ }|
  308. {0:~ }|
  309. {0:~ }|
  310. |
  311. ]])
  312. end)
  313. it("2. Hidden unless cchar is set.", function()
  314. command("let &conceallevel=2")
  315. screen:expect([[
  316. // No Conceal |
  317. |
  318. {1:C} |
  319. |
  320. ^ |
  321. {0:~ }|
  322. {0:~ }|
  323. {0:~ }|
  324. {0:~ }|
  325. |
  326. ]])
  327. end)
  328. it("3. Hide all concealed text.", function()
  329. command("let &conceallevel=3")
  330. screen:expect([[
  331. // No Conceal |
  332. |
  333. |
  334. |
  335. ^ |
  336. {0:~ }|
  337. {0:~ }|
  338. {0:~ }|
  339. {0:~ }|
  340. |
  341. ]])
  342. end)
  343. end) -- conceallevel
  344. describe("cursor movement", function()
  345. before_each(function()
  346. command("syn keyword concealy barf conceal cchar=b")
  347. command("set cole=2")
  348. feed('5Ofoo barf bar barf eggs<esc>')
  349. screen:expect([[
  350. foo {1:b} bar {1:b} eggs |
  351. foo {1:b} bar {1:b} eggs |
  352. foo {1:b} bar {1:b} eggs |
  353. foo {1:b} bar {1:b} eggs |
  354. foo barf bar barf egg^s |
  355. |
  356. {0:~ }|
  357. {0:~ }|
  358. {0:~ }|
  359. |
  360. ]])
  361. end)
  362. it('between windows', function()
  363. feed('k')
  364. command("split")
  365. screen:expect([[
  366. foo {1:b} bar {1:b} eggs |
  367. foo barf bar barf egg^s |
  368. foo {1:b} bar {1:b} eggs |
  369. |
  370. {2:[No Name] [+] }|
  371. foo {1:b} bar {1:b} eggs |
  372. foo {1:b} bar {1:b} eggs |
  373. foo {1:b} bar {1:b} eggs |
  374. {3:[No Name] [+] }|
  375. |
  376. ]])
  377. feed('<c-w>w')
  378. screen:expect([[
  379. foo {1:b} bar {1:b} eggs |
  380. foo {1:b} bar {1:b} eggs |
  381. foo {1:b} bar {1:b} eggs |
  382. |
  383. {3:[No Name] [+] }|
  384. foo {1:b} bar {1:b} eggs |
  385. foo barf bar barf egg^s |
  386. foo {1:b} bar {1:b} eggs |
  387. {2:[No Name] [+] }|
  388. |
  389. ]])
  390. end)
  391. it('in insert mode', function()
  392. feed('i')
  393. screen:expect([[
  394. foo {1:b} bar {1:b} eggs |
  395. foo {1:b} bar {1:b} eggs |
  396. foo {1:b} bar {1:b} eggs |
  397. foo {1:b} bar {1:b} eggs |
  398. foo barf bar barf egg^s |
  399. |
  400. {0:~ }|
  401. {0:~ }|
  402. {0:~ }|
  403. {4:-- INSERT --} |
  404. ]])
  405. feed('<up>')
  406. screen:expect([[
  407. foo {1:b} bar {1:b} eggs |
  408. foo {1:b} bar {1:b} eggs |
  409. foo {1:b} bar {1:b} eggs |
  410. foo barf bar barf egg^s |
  411. foo {1:b} bar {1:b} eggs |
  412. |
  413. {0:~ }|
  414. {0:~ }|
  415. {0:~ }|
  416. {4:-- INSERT --} |
  417. ]])
  418. end)
  419. it('between modes cocu=iv', function()
  420. command('set cocu=iv')
  421. feed('gg')
  422. screen:expect([[
  423. ^foo barf bar barf eggs |
  424. foo {1:b} bar {1:b} eggs |
  425. foo {1:b} bar {1:b} eggs |
  426. foo {1:b} bar {1:b} eggs |
  427. foo {1:b} bar {1:b} eggs |
  428. |
  429. {0:~ }|
  430. {0:~ }|
  431. {0:~ }|
  432. |
  433. ]])
  434. feed('i')
  435. screen:expect([[
  436. ^foo {1:b} bar {1:b} eggs |
  437. foo {1:b} bar {1:b} eggs |
  438. foo {1:b} bar {1:b} eggs |
  439. foo {1:b} bar {1:b} eggs |
  440. foo {1:b} bar {1:b} eggs |
  441. |
  442. {0:~ }|
  443. {0:~ }|
  444. {0:~ }|
  445. {4:-- INSERT --} |
  446. ]])
  447. feed('<esc>')
  448. screen:expect([[
  449. ^foo barf bar barf eggs |
  450. foo {1:b} bar {1:b} eggs |
  451. foo {1:b} bar {1:b} eggs |
  452. foo {1:b} bar {1:b} eggs |
  453. foo {1:b} bar {1:b} eggs |
  454. |
  455. {0:~ }|
  456. {0:~ }|
  457. {0:~ }|
  458. |
  459. ]])
  460. feed('v')
  461. screen:expect([[
  462. ^foo {1:b} bar {1:b} eggs |
  463. foo {1:b} bar {1:b} eggs |
  464. foo {1:b} bar {1:b} eggs |
  465. foo {1:b} bar {1:b} eggs |
  466. foo {1:b} bar {1:b} eggs |
  467. |
  468. {0:~ }|
  469. {0:~ }|
  470. {0:~ }|
  471. {4:-- VISUAL --} |
  472. ]])
  473. feed('<esc>')
  474. screen:expect([[
  475. ^foo barf bar barf eggs |
  476. foo {1:b} bar {1:b} eggs |
  477. foo {1:b} bar {1:b} eggs |
  478. foo {1:b} bar {1:b} eggs |
  479. foo {1:b} bar {1:b} eggs |
  480. |
  481. {0:~ }|
  482. {0:~ }|
  483. {0:~ }|
  484. |
  485. ]])
  486. end)
  487. it('between modes cocu=n', function()
  488. command('set cocu=n')
  489. feed('gg')
  490. screen:expect([[
  491. ^foo {1:b} bar {1:b} eggs |
  492. foo {1:b} bar {1:b} eggs |
  493. foo {1:b} bar {1:b} eggs |
  494. foo {1:b} bar {1:b} eggs |
  495. foo {1:b} bar {1:b} eggs |
  496. |
  497. {0:~ }|
  498. {0:~ }|
  499. {0:~ }|
  500. |
  501. ]])
  502. feed('i')
  503. screen:expect([[
  504. ^foo barf bar barf eggs |
  505. foo {1:b} bar {1:b} eggs |
  506. foo {1:b} bar {1:b} eggs |
  507. foo {1:b} bar {1:b} eggs |
  508. foo {1:b} bar {1:b} eggs |
  509. |
  510. {0:~ }|
  511. {0:~ }|
  512. {0:~ }|
  513. {4:-- INSERT --} |
  514. ]])
  515. feed('<esc>')
  516. screen:expect([[
  517. ^foo {1:b} bar {1:b} eggs |
  518. foo {1:b} bar {1:b} eggs |
  519. foo {1:b} bar {1:b} eggs |
  520. foo {1:b} bar {1:b} eggs |
  521. foo {1:b} bar {1:b} eggs |
  522. |
  523. {0:~ }|
  524. {0:~ }|
  525. {0:~ }|
  526. |
  527. ]])
  528. feed('v')
  529. screen:expect([[
  530. ^foo barf bar barf eggs |
  531. foo {1:b} bar {1:b} eggs |
  532. foo {1:b} bar {1:b} eggs |
  533. foo {1:b} bar {1:b} eggs |
  534. foo {1:b} bar {1:b} eggs |
  535. |
  536. {0:~ }|
  537. {0:~ }|
  538. {0:~ }|
  539. {4:-- VISUAL --} |
  540. ]])
  541. feed('<esc>')
  542. screen:expect([[
  543. ^foo {1:b} bar {1:b} eggs |
  544. foo {1:b} bar {1:b} eggs |
  545. foo {1:b} bar {1:b} eggs |
  546. foo {1:b} bar {1:b} eggs |
  547. foo {1:b} bar {1:b} eggs |
  548. |
  549. {0:~ }|
  550. {0:~ }|
  551. {0:~ }|
  552. |
  553. ]])
  554. end)
  555. it('and open line', function()
  556. feed('o')
  557. screen:expect([[
  558. foo {1:b} bar {1:b} eggs |
  559. foo {1:b} bar {1:b} eggs |
  560. foo {1:b} bar {1:b} eggs |
  561. foo {1:b} bar {1:b} eggs |
  562. foo {1:b} bar {1:b} eggs |
  563. ^ |
  564. |
  565. {0:~ }|
  566. {0:~ }|
  567. {4:-- INSERT --} |
  568. ]])
  569. end)
  570. it('and open line cocu=i', function()
  571. command('set cocu=i')
  572. feed('o')
  573. screen:expect([[
  574. foo {1:b} bar {1:b} eggs |
  575. foo {1:b} bar {1:b} eggs |
  576. foo {1:b} bar {1:b} eggs |
  577. foo {1:b} bar {1:b} eggs |
  578. foo {1:b} bar {1:b} eggs |
  579. ^ |
  580. |
  581. {0:~ }|
  582. {0:~ }|
  583. {4:-- INSERT --} |
  584. ]])
  585. end)
  586. describe('with incsearch', function()
  587. before_each(function()
  588. command('set incsearch hlsearch')
  589. feed('2GA x<esc>3GA xy<esc>gg')
  590. screen:expect([[
  591. ^foo barf bar barf eggs |
  592. foo {1:b} bar {1:b} eggs x |
  593. foo {1:b} bar {1:b} eggs xy |
  594. foo {1:b} bar {1:b} eggs |
  595. foo {1:b} bar {1:b} eggs |
  596. |
  597. {0:~ }|
  598. {0:~ }|
  599. {0:~ }|
  600. |
  601. ]])
  602. end)
  603. it('cocu=', function()
  604. feed('/')
  605. screen:expect([[
  606. foo barf bar barf eggs |
  607. foo {1:b} bar {1:b} eggs x |
  608. foo {1:b} bar {1:b} eggs xy |
  609. foo {1:b} bar {1:b} eggs |
  610. foo {1:b} bar {1:b} eggs |
  611. |
  612. {0:~ }|
  613. {0:~ }|
  614. {0:~ }|
  615. /^ |
  616. ]])
  617. feed('x')
  618. screen:expect([[
  619. foo {1:b} bar {1:b} eggs |
  620. foo barf bar barf eggs {3:x} |
  621. foo {1:b} bar {1:b} eggs {5:x}y |
  622. foo {1:b} bar {1:b} eggs |
  623. foo {1:b} bar {1:b} eggs |
  624. |
  625. {0:~ }|
  626. {0:~ }|
  627. {0:~ }|
  628. /x^ |
  629. ]])
  630. feed('y')
  631. screen:expect([[
  632. foo {1:b} bar {1:b} eggs |
  633. foo {1:b} bar {1:b} eggs x |
  634. foo barf bar barf eggs {3:xy} |
  635. foo {1:b} bar {1:b} eggs |
  636. foo {1:b} bar {1:b} eggs |
  637. |
  638. {0:~ }|
  639. {0:~ }|
  640. {0:~ }|
  641. /xy^ |
  642. ]])
  643. feed('<c-w>')
  644. screen:expect([[
  645. foo barf bar barf eggs |
  646. foo {1:b} bar {1:b} eggs x |
  647. foo {1:b} bar {1:b} eggs xy |
  648. foo {1:b} bar {1:b} eggs |
  649. foo {1:b} bar {1:b} eggs |
  650. |
  651. {0:~ }|
  652. {0:~ }|
  653. {0:~ }|
  654. /^ |
  655. ]])
  656. end)
  657. it('cocu=c', function()
  658. command('set cocu=c')
  659. feed('/')
  660. -- NB: we don't do this redraw. Probably best to still skip it,
  661. -- to avoid annoying distraction from the cmdline
  662. screen:expect([[
  663. foo barf bar barf eggs |
  664. foo {1:b} bar {1:b} eggs x |
  665. foo {1:b} bar {1:b} eggs xy |
  666. foo {1:b} bar {1:b} eggs |
  667. foo {1:b} bar {1:b} eggs |
  668. |
  669. {0:~ }|
  670. {0:~ }|
  671. {0:~ }|
  672. /^ |
  673. ]])
  674. feed('x')
  675. screen:expect([[
  676. foo {1:b} bar {1:b} eggs |
  677. foo {1:b} bar {1:b} eggs {3:x} |
  678. foo {1:b} bar {1:b} eggs {5:x}y |
  679. foo {1:b} bar {1:b} eggs |
  680. foo {1:b} bar {1:b} eggs |
  681. |
  682. {0:~ }|
  683. {0:~ }|
  684. {0:~ }|
  685. /x^ |
  686. ]])
  687. feed('y')
  688. screen:expect([[
  689. foo {1:b} bar {1:b} eggs |
  690. foo {1:b} bar {1:b} eggs x |
  691. foo {1:b} bar {1:b} eggs {3:xy} |
  692. foo {1:b} bar {1:b} eggs |
  693. foo {1:b} bar {1:b} eggs |
  694. |
  695. {0:~ }|
  696. {0:~ }|
  697. {0:~ }|
  698. /xy^ |
  699. ]])
  700. feed('<c-w>')
  701. screen:expect([[
  702. foo {1:b} bar {1:b} eggs |
  703. foo {1:b} bar {1:b} eggs x |
  704. foo {1:b} bar {1:b} eggs xy |
  705. foo {1:b} bar {1:b} eggs |
  706. foo {1:b} bar {1:b} eggs |
  707. |
  708. {0:~ }|
  709. {0:~ }|
  710. {0:~ }|
  711. /^ |
  712. ]])
  713. feed('<esc>')
  714. screen:expect([[
  715. ^foo barf bar barf eggs |
  716. foo {1:b} bar {1:b} eggs x |
  717. foo {1:b} bar {1:b} eggs xy |
  718. foo {1:b} bar {1:b} eggs |
  719. foo {1:b} bar {1:b} eggs |
  720. |
  721. {0:~ }|
  722. {0:~ }|
  723. {0:~ }|
  724. |
  725. ]])
  726. end)
  727. it('cocu=n', function()
  728. command('set cocu=n')
  729. screen:expect([[
  730. ^foo {1:b} bar {1:b} eggs |
  731. foo {1:b} bar {1:b} eggs x |
  732. foo {1:b} bar {1:b} eggs xy |
  733. foo {1:b} bar {1:b} eggs |
  734. foo {1:b} bar {1:b} eggs |
  735. |
  736. {0:~ }|
  737. {0:~ }|
  738. {0:~ }|
  739. |
  740. ]])
  741. feed('/')
  742. -- NB: we don't do this redraw. Probably best to still skip it,
  743. -- to avoid annoying distraction from the cmdline
  744. screen:expect([[
  745. foo {1:b} bar {1:b} eggs |
  746. foo {1:b} bar {1:b} eggs x |
  747. foo {1:b} bar {1:b} eggs xy |
  748. foo {1:b} bar {1:b} eggs |
  749. foo {1:b} bar {1:b} eggs |
  750. |
  751. {0:~ }|
  752. {0:~ }|
  753. {0:~ }|
  754. /^ |
  755. ]])
  756. feed('x')
  757. screen:expect([[
  758. foo {1:b} bar {1:b} eggs |
  759. foo barf bar barf eggs {3:x} |
  760. foo {1:b} bar {1:b} eggs {5:x}y |
  761. foo {1:b} bar {1:b} eggs |
  762. foo {1:b} bar {1:b} eggs |
  763. |
  764. {0:~ }|
  765. {0:~ }|
  766. {0:~ }|
  767. /x^ |
  768. ]])
  769. feed('<c-w>')
  770. screen:expect([[
  771. foo barf bar barf eggs |
  772. foo {1:b} bar {1:b} eggs x |
  773. foo {1:b} bar {1:b} eggs xy |
  774. foo {1:b} bar {1:b} eggs |
  775. foo {1:b} bar {1:b} eggs |
  776. |
  777. {0:~ }|
  778. {0:~ }|
  779. {0:~ }|
  780. /^ |
  781. ]])
  782. feed('<esc>')
  783. screen:expect([[
  784. ^foo {1:b} bar {1:b} eggs |
  785. foo {1:b} bar {1:b} eggs x |
  786. foo {1:b} bar {1:b} eggs xy |
  787. foo {1:b} bar {1:b} eggs |
  788. foo {1:b} bar {1:b} eggs |
  789. |
  790. {0:~ }|
  791. {0:~ }|
  792. {0:~ }|
  793. |
  794. ]])
  795. end)
  796. end)
  797. it('redraws properly with concealcursor in visual mode', function()
  798. command('set concealcursor=v conceallevel=2')
  799. feed('10Ofoo barf bar barf eggs<esc>')
  800. feed(':3<cr>o a<Esc>ggV')
  801. screen:expect{grid=[[
  802. ^f{6:oo }{1:b}{6: bar }{1:b}{6: eggs} |
  803. foo {1:b} bar {1:b} eggs |
  804. foo {1:b} bar {1:b} eggs |
  805. a |
  806. foo {1:b} bar {1:b} eggs |
  807. foo {1:b} bar {1:b} eggs |
  808. foo {1:b} bar {1:b} eggs |
  809. foo {1:b} bar {1:b} eggs |
  810. foo {1:b} bar {1:b} eggs |
  811. {4:-- VISUAL LINE --} |
  812. ]]}
  813. feed(string.rep('j', 15))
  814. screen:expect{grid=[[
  815. {6:foo }{1:b}{6: bar }{1:b}{6: eggs} |
  816. {6:foo }{1:b}{6: bar }{1:b}{6: eggs} |
  817. {6:foo }{1:b}{6: bar }{1:b}{6: eggs} |
  818. {6:foo }{1:b}{6: bar }{1:b}{6: eggs} |
  819. {6:foo }{1:b}{6: bar }{1:b}{6: eggs} |
  820. {6:foo }{1:b}{6: bar }{1:b}{6: eggs} |
  821. {6:foo }{1:b}{6: bar }{1:b}{6: eggs} |
  822. {6:foo }{1:b}{6: bar }{1:b}{6: eggs} |
  823. ^f{6:oo }{1:b}{6: bar }{1:b}{6: eggs} |
  824. {4:-- VISUAL LINE --} |
  825. ]]}
  826. feed(string.rep('k', 15))
  827. screen:expect{grid=[[
  828. ^f{6:oo }{1:b}{6: bar }{1:b}{6: eggs} |
  829. foo {1:b} bar {1:b} eggs |
  830. foo {1:b} bar {1:b} eggs |
  831. a |
  832. foo {1:b} bar {1:b} eggs |
  833. foo {1:b} bar {1:b} eggs |
  834. foo {1:b} bar {1:b} eggs |
  835. foo {1:b} bar {1:b} eggs |
  836. foo {1:b} bar {1:b} eggs |
  837. {4:-- VISUAL LINE --} |
  838. ]]}
  839. end)
  840. end)
  841. it('redraws not too much with conceallevel=1', function()
  842. command('set conceallevel=1')
  843. command('set redrawdebug+=nodelta')
  844. insert([[
  845. aaa
  846. bbb
  847. ccc
  848. ]])
  849. screen:expect{grid=[[
  850. aaa |
  851. bbb |
  852. ccc |
  853. ^ |
  854. {0:~ }|
  855. {0:~ }|
  856. {0:~ }|
  857. {0:~ }|
  858. {0:~ }|
  859. |
  860. ]]}
  861. -- XXX: hack to get notifications, and check only a single line is
  862. -- updated. Could use next_msg() also.
  863. local orig_handle_grid_line = screen._handle_grid_line
  864. local grid_lines = {}
  865. function screen._handle_grid_line(self, grid, row, col, items)
  866. table.insert(grid_lines, {row, col, items})
  867. orig_handle_grid_line(self, grid, row, col, items)
  868. end
  869. feed('k')
  870. screen:expect{grid=[[
  871. aaa |
  872. bbb |
  873. ^ccc |
  874. |
  875. {0:~ }|
  876. {0:~ }|
  877. {0:~ }|
  878. {0:~ }|
  879. {0:~ }|
  880. |
  881. ]]}
  882. eq({{2, 0, {{'c', 0, 3}}}}, grid_lines)
  883. end)
  884. it('K_EVENT should not cause extra redraws with concealcursor #13196', function()
  885. command('set conceallevel=1')
  886. command('set concealcursor=nv')
  887. command('set redrawdebug+=nodelta')
  888. insert([[
  889. aaa
  890. bbb
  891. ccc
  892. ]])
  893. screen:expect{grid=[[
  894. aaa |
  895. bbb |
  896. ccc |
  897. ^ |
  898. {0:~ }|
  899. {0:~ }|
  900. {0:~ }|
  901. {0:~ }|
  902. {0:~ }|
  903. |
  904. ]]}
  905. -- XXX: hack to get notifications, and check only a single line is
  906. -- updated. Could use next_msg() also.
  907. local orig_handle_grid_line = screen._handle_grid_line
  908. local grid_lines = {}
  909. function screen._handle_grid_line(self, grid, row, col, items)
  910. table.insert(grid_lines, {row, col, items})
  911. orig_handle_grid_line(self, grid, row, col, items)
  912. end
  913. feed('k')
  914. screen:expect{grid=[[
  915. aaa |
  916. bbb |
  917. ^ccc |
  918. |
  919. {0:~ }|
  920. {0:~ }|
  921. {0:~ }|
  922. {0:~ }|
  923. {0:~ }|
  924. |
  925. ]]}
  926. eq({{2, 0, {{'c', 0, 3}}}}, grid_lines)
  927. poke_eventloop() -- causes K_EVENT key
  928. screen:expect_unchanged()
  929. eq({{2, 0, {{'c', 0, 3}}}}, grid_lines)
  930. end)
  931. -- Copy of Test_cursor_column_in_concealed_line_after_window_scroll in
  932. -- test/functional/ui/syntax_conceal_spec.lua.
  933. describe('concealed line after window scroll', function()
  934. after_each(function()
  935. command(':qall!')
  936. os.remove('Xcolesearch')
  937. end)
  938. it('has the correct cursor column', function()
  939. insert([[
  940. 3split
  941. let m = matchadd('Conceal', '=')
  942. setl conceallevel=2 concealcursor=nc
  943. normal gg
  944. "==expr==
  945. ]])
  946. command('write Xcolesearch')
  947. feed(":so %<CR>")
  948. -- Jump to something that is beyond the bottom of the window,
  949. -- so there's a scroll down.
  950. feed("/expr<CR>")
  951. -- Are the concealed parts of the current line really hidden?
  952. -- Is the window's cursor column properly updated for hidden
  953. -- parts of the current line?
  954. screen:expect{grid=[[
  955. setl conceallevel2 concealcursornc |
  956. normal gg |
  957. "{5:^expr} |
  958. {2:Xcolesearch }|
  959. normal gg |
  960. "=={5:expr}== |
  961. |
  962. {0:~ }|
  963. {3:Xcolesearch }|
  964. /expr |
  965. ]]}
  966. end)
  967. end)
  968. end)