syntax_conceal_spec.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 insert = helpers.insert
  5. describe('Screen', function()
  6. local screen
  7. before_each(function()
  8. clear()
  9. screen = Screen.new(nil,10)
  10. screen:attach()
  11. screen:set_default_attr_ids( {
  12. [0] = {bold=true, foreground=Screen.colors.Blue},
  13. [1] = {foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray}
  14. } )
  15. end)
  16. after_each(function()
  17. screen:detach()
  18. end)
  19. describe("match and conceal", function()
  20. before_each(function()
  21. command("let &conceallevel=1")
  22. end)
  23. describe("multiple", function()
  24. before_each(function()
  25. insert([[
  26. &&
  27. &&
  28. &&
  29. &&
  30. &&
  31. &&
  32. ]])
  33. command("syn match dAmpersand '[&][&]' conceal cchar=∧")
  34. end)
  35. it("double characters.", function()
  36. screen:expect([[
  37. {1:∧} |
  38. {1:∧} |
  39. {1:∧} |
  40. {1:∧} |
  41. {1:∧} |
  42. {1:∧} |
  43. ^ |
  44. {0:~ }|
  45. {0:~ }|
  46. |
  47. ]])
  48. end)
  49. it('double characters and move the cursor one line up.', function()
  50. feed("k")
  51. screen:expect([[
  52. {1:∧} |
  53. {1:∧} |
  54. {1:∧} |
  55. {1:∧} |
  56. {1:∧} |
  57. ^&& |
  58. |
  59. {0:~ }|
  60. {0:~ }|
  61. |
  62. ]])
  63. end)
  64. it('double characters and move the cursor to the beginning of the file.', function()
  65. feed("gg")
  66. screen:expect([[
  67. ^&& |
  68. {1:∧} |
  69. {1:∧} |
  70. {1:∧} |
  71. {1:∧} |
  72. {1:∧} |
  73. |
  74. {0:~ }|
  75. {0:~ }|
  76. |
  77. ]])
  78. end)
  79. it('double characters and move the cursor to the second line in the file.', function()
  80. feed("ggj")
  81. screen:expect([[
  82. {1:∧} |
  83. ^&& |
  84. {1:∧} |
  85. {1:∧} |
  86. {1:∧} |
  87. {1:∧} |
  88. |
  89. {0:~ }|
  90. {0:~ }|
  91. |
  92. ]])
  93. end)
  94. it('double characters and then move the cursor to the beginning of the file and back to the end of the file.', function()
  95. feed("ggG")
  96. screen:expect([[
  97. {1:∧} |
  98. {1:∧} |
  99. {1:∧} |
  100. {1:∧} |
  101. {1:∧} |
  102. {1:∧} |
  103. ^ |
  104. {0:~ }|
  105. {0:~ }|
  106. |
  107. ]])
  108. end)
  109. end) -- multiple
  110. it("keyword instances in initially in the document.", function()
  111. feed("2ilambda<cr><ESC>")
  112. command("let &conceallevel=1")
  113. command("syn keyword kLambda lambda conceal cchar=λ")
  114. screen:expect([[
  115. {1:λ} |
  116. {1:λ} |
  117. ^ |
  118. {0:~ }|
  119. {0:~ }|
  120. {0:~ }|
  121. {0:~ }|
  122. {0:~ }|
  123. {0:~ }|
  124. |
  125. ]])
  126. end) -- Keyword
  127. describe("regions in the document", function()
  128. before_each(function()
  129. feed("2")
  130. insert("<r> a region of text </r>\n")
  131. command("let &conceallevel=1")
  132. end)
  133. it('initially and conceal it.', function()
  134. command("syn region rText start='<r>' end='</r>' conceal cchar=R")
  135. screen:expect([[
  136. {1:R} |
  137. {1:R} |
  138. ^ |
  139. {0:~ }|
  140. {0:~ }|
  141. {0:~ }|
  142. {0:~ }|
  143. {0:~ }|
  144. {0:~ }|
  145. |
  146. ]])
  147. end)
  148. it('initially and conceal its start tag and end tag.', function()
  149. -- concealends has a known bug (todo.txt) where the first match won't
  150. -- be replaced with cchar.
  151. command("syn region rText matchgroup=rMatch start='<r>' end='</r>' concealends cchar=-")
  152. screen:expect([[
  153. {1: } a region of text {1:-} |
  154. {1: } a region of text {1:-} |
  155. ^ |
  156. {0:~ }|
  157. {0:~ }|
  158. {0:~ }|
  159. {0:~ }|
  160. {0:~ }|
  161. {0:~ }|
  162. |
  163. ]])
  164. end)
  165. it('that are nested and conceal the nested region\'s start and end tags.', function()
  166. command("syn region rText contains=rText matchgroup=rMatch start='<r>' end='</r>' concealends cchar=-")
  167. insert("<r> A region with <r> a nested <r> nested region.</r> </r> </r>\n")
  168. screen:expect([[
  169. {1: } a region of text {1:-} |
  170. {1: } a region of text {1:-} |
  171. {1: } A region with {1: } a nested {1: } nested region.{1:-} |
  172. {1:-} {1:-} |
  173. ^ |
  174. {0:~ }|
  175. {0:~ }|
  176. {0:~ }|
  177. {0:~ }|
  178. |
  179. ]])
  180. end)
  181. end) -- regions in the document
  182. describe("a region of text", function()
  183. before_each(function()
  184. command("syntax conceal on")
  185. feed("2")
  186. insert("<r> a region of text </r>\n")
  187. command("syn region rText start='<r>' end='</r>' cchar=-")
  188. end)
  189. it("and turn on implicit concealing", function()
  190. screen:expect([[
  191. {1:-} |
  192. {1:-} |
  193. ^ |
  194. {0:~ }|
  195. {0:~ }|
  196. {0:~ }|
  197. {0:~ }|
  198. {0:~ }|
  199. {0:~ }|
  200. |
  201. ]])
  202. end)
  203. it("and then turn on, then off, and then back on implicit concealing.", function()
  204. command("syntax conceal off")
  205. feed("2")
  206. insert("<i> italian text </i>\n")
  207. command("syn region iText start='<i>' end='</i>' cchar=*")
  208. screen:expect([[
  209. {1:-} |
  210. {1:-} |
  211. <i> italian text </i> |
  212. <i> italian text </i> |
  213. ^ |
  214. {0:~ }|
  215. {0:~ }|
  216. {0:~ }|
  217. {0:~ }|
  218. |
  219. ]])
  220. command("syntax conceal on")
  221. command("syn region iText start='<i>' end='</i>' cchar=*")
  222. screen:expect([[
  223. {1:-} |
  224. {1:-} |
  225. {1:*} |
  226. {1:*} |
  227. ^ |
  228. {0:~ }|
  229. {0:~ }|
  230. {0:~ }|
  231. {0:~ }|
  232. |
  233. ]])
  234. end)
  235. end) -- a region of text (implicit concealing)
  236. end) -- match and conceal
  237. describe("let the conceal level be", function()
  238. before_each(function()
  239. insert("// No Conceal\n")
  240. insert('"Conceal without a cchar"\n')
  241. insert("+ With cchar\n\n")
  242. command("syn match noConceal '^//.*$'")
  243. command("syn match concealNoCchar '\".\\{-}\"$' conceal")
  244. command("syn match concealWCchar '^+.\\{-}$' conceal cchar=C")
  245. end)
  246. it("0. No concealing.", function()
  247. command("let &conceallevel=0")
  248. screen:expect([[
  249. // No Conceal |
  250. "Conceal without a cchar" |
  251. + With cchar |
  252. |
  253. ^ |
  254. {0:~ }|
  255. {0:~ }|
  256. {0:~ }|
  257. {0:~ }|
  258. |
  259. ]])
  260. end)
  261. it("1. Conceal using cchar or reference listchars.", function()
  262. command("let &conceallevel=1")
  263. screen:expect([[
  264. // No Conceal |
  265. {1: } |
  266. {1:C} |
  267. |
  268. ^ |
  269. {0:~ }|
  270. {0:~ }|
  271. {0:~ }|
  272. {0:~ }|
  273. |
  274. ]])
  275. end)
  276. it("2. Hidden unless cchar is set.", function()
  277. command("let &conceallevel=2")
  278. screen:expect([[
  279. // No Conceal |
  280. |
  281. {1:C} |
  282. |
  283. ^ |
  284. {0:~ }|
  285. {0:~ }|
  286. {0:~ }|
  287. {0:~ }|
  288. |
  289. ]])
  290. end)
  291. it("3. Hide all concealed text.", function()
  292. command("let &conceallevel=3")
  293. screen:expect([[
  294. // No Conceal |
  295. |
  296. |
  297. |
  298. ^ |
  299. {0:~ }|
  300. {0:~ }|
  301. {0:~ }|
  302. {0:~ }|
  303. |
  304. ]])
  305. end)
  306. end) -- conceallevel
  307. end)