popupmenu_spec.lua 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local clear, feed = helpers.clear, helpers.feed
  4. local source = helpers.source
  5. describe('ui/ext_popupmenu', function()
  6. local screen
  7. before_each(function()
  8. clear()
  9. screen = Screen.new(60, 8)
  10. screen:attach({rgb=true, ext_popupmenu=true})
  11. screen:set_default_attr_ids({
  12. [1] = {bold=true, foreground=Screen.colors.Blue},
  13. [2] = {bold = true},
  14. [3] = {reverse = true},
  15. [4] = {bold = true, reverse = true},
  16. [5] = {bold = true, foreground = Screen.colors.SeaGreen}
  17. })
  18. end)
  19. it('works', function()
  20. source([[
  21. function! TestComplete() abort
  22. call complete(1, ['foo', 'bar', 'spam'])
  23. return ''
  24. endfunction
  25. ]])
  26. local expected = {
  27. {'foo', '', '', ''},
  28. {'bar', '', '', ''},
  29. {'spam', '', '', ''},
  30. }
  31. feed('o<C-r>=TestComplete()<CR>')
  32. screen:expect{grid=[[
  33. |
  34. foo^ |
  35. {1:~ }|
  36. {1:~ }|
  37. {1:~ }|
  38. {1:~ }|
  39. {1:~ }|
  40. {2:-- INSERT --} |
  41. ]], popupmenu={
  42. items=expected,
  43. pos=0,
  44. anchor={1,0},
  45. }}
  46. feed('<c-p>')
  47. screen:expect{grid=[[
  48. |
  49. ^ |
  50. {1:~ }|
  51. {1:~ }|
  52. {1:~ }|
  53. {1:~ }|
  54. {1:~ }|
  55. {2:-- INSERT --} |
  56. ]], popupmenu={
  57. items=expected,
  58. pos=-1,
  59. anchor={1,0},
  60. }}
  61. -- down moves the selection in the menu, but does not insert anything
  62. feed('<down><down>')
  63. screen:expect{grid=[[
  64. |
  65. ^ |
  66. {1:~ }|
  67. {1:~ }|
  68. {1:~ }|
  69. {1:~ }|
  70. {1:~ }|
  71. {2:-- INSERT --} |
  72. ]], popupmenu={
  73. items=expected,
  74. pos=1,
  75. anchor={1,0},
  76. }}
  77. feed('<cr>')
  78. screen:expect{grid=[[
  79. |
  80. bar^ |
  81. {1:~ }|
  82. {1:~ }|
  83. {1:~ }|
  84. {1:~ }|
  85. {1:~ }|
  86. {2:-- INSERT --} |
  87. ]]}
  88. end)
  89. end)
  90. describe('popup placement', function()
  91. local screen
  92. before_each(function()
  93. clear()
  94. screen = Screen.new(32, 20)
  95. screen:attach()
  96. screen:set_default_attr_ids({
  97. -- popup selected item / scrollbar track
  98. ['s'] = {background = Screen.colors.WebGray},
  99. -- popup non-selected item
  100. ['n'] = {background = Screen.colors.LightMagenta},
  101. -- popup scrollbar knob
  102. ['c'] = {background = Screen.colors.Grey0},
  103. [1] = {bold = true, foreground = Screen.colors.Blue},
  104. [2] = {bold = true},
  105. [3] = {reverse = true},
  106. [4] = {bold = true, reverse = true},
  107. [5] = {bold = true, foreground = Screen.colors.SeaGreen}
  108. })
  109. end)
  110. it('works with preview-window above', function()
  111. feed(':ped<CR><c-w>4+')
  112. feed('iaa bb cc dd ee ff gg hh ii jj<cr>')
  113. feed('<c-x><c-n>')
  114. screen:expect([[
  115. aa bb cc dd ee ff gg hh ii jj |
  116. aa |
  117. {1:~ }|
  118. {1:~ }|
  119. {1:~ }|
  120. {1:~ }|
  121. {1:~ }|
  122. {1:~ }|
  123. {3:[No Name] [Preview][+] }|
  124. aa bb cc dd ee ff gg hh ii jj |
  125. aa^ |
  126. {s:aa }{c: }{1: }|
  127. {n:bb }{c: }{1: }|
  128. {n:cc }{c: }{1: }|
  129. {n:dd }{c: }{1: }|
  130. {n:ee }{c: }{1: }|
  131. {n:ff }{c: }{1: }|
  132. {n:gg }{s: }{1: }|
  133. {n:hh }{s: }{4: }|
  134. {2:-- }{5:match 1 of 10} |
  135. ]])
  136. end)
  137. it('works with preview-window below', function()
  138. feed(':ped<CR><c-w>4+<c-w>r')
  139. feed('iaa bb cc dd ee ff gg hh ii jj<cr>')
  140. feed('<c-x><c-n>')
  141. screen:expect([[
  142. aa bb cc dd ee ff gg hh ii jj |
  143. aa^ |
  144. {s:aa }{c: }{1: }|
  145. {n:bb }{c: }{1: }|
  146. {n:cc }{c: }{1: }|
  147. {n:dd }{c: }{1: }|
  148. {n:ee }{c: }{1: }|
  149. {n:ff }{c: }{1: }|
  150. {n:gg }{s: }{1: }|
  151. {n:hh }{s: }{4: }|
  152. aa bb cc dd ee ff gg hh ii jj |
  153. aa |
  154. {1:~ }|
  155. {1:~ }|
  156. {1:~ }|
  157. {1:~ }|
  158. {1:~ }|
  159. {1:~ }|
  160. {3:[No Name] [Preview][+] }|
  161. {2:-- }{5:match 1 of 10} |
  162. ]])
  163. end)
  164. it('works with preview-window above and tall and inverted', function()
  165. feed(':ped<CR><c-w>8+')
  166. feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
  167. feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
  168. feed('kk<cr>ll<cr>mm<cr>nn<cr>oo<cr>')
  169. feed('<c-x><c-n>')
  170. screen:expect([[
  171. aa |
  172. bb |
  173. cc |
  174. dd |
  175. {s:aa }{c: }{3:ew][+] }|
  176. {n:bb }{c: } |
  177. {n:cc }{c: } |
  178. {n:dd }{c: } |
  179. {n:ee }{c: } |
  180. {n:ff }{c: } |
  181. {n:gg }{c: } |
  182. {n:hh }{c: } |
  183. {n:ii }{c: } |
  184. {n:jj }{c: } |
  185. {n:kk }{c: } |
  186. {n:ll }{s: } |
  187. {n:mm }{s: } |
  188. aa^ |
  189. {4:[No Name] [+] }|
  190. {2:-- }{5:match 1 of 15} |
  191. ]])
  192. end)
  193. it('works with preview-window above and short and inverted', function()
  194. feed(':ped<CR><c-w>4+')
  195. feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
  196. feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
  197. feed('<c-x><c-n>')
  198. screen:expect([[
  199. aa |
  200. bb |
  201. cc |
  202. dd |
  203. ee |
  204. ff |
  205. gg |
  206. {s:aa } |
  207. {n:bb }{3:iew][+] }|
  208. {n:cc } |
  209. {n:dd } |
  210. {n:ee } |
  211. {n:ff } |
  212. {n:gg } |
  213. {n:hh } |
  214. {n:ii } |
  215. {n:jj } |
  216. aa^ |
  217. {4:[No Name] [+] }|
  218. {2:-- }{5:match 1 of 10} |
  219. ]])
  220. end)
  221. it('works with preview-window below and inverted', function()
  222. feed(':ped<CR><c-w>4+<c-w>r')
  223. feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
  224. feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
  225. feed('<c-x><c-n>')
  226. screen:expect([[
  227. {s:aa }{c: } |
  228. {n:bb }{c: } |
  229. {n:cc }{c: } |
  230. {n:dd }{c: } |
  231. {n:ee }{c: } |
  232. {n:ff }{c: } |
  233. {n:gg }{s: } |
  234. {n:hh }{s: } |
  235. aa^ |
  236. {4:[No Name] [+] }|
  237. aa |
  238. bb |
  239. cc |
  240. dd |
  241. ee |
  242. ff |
  243. gg |
  244. hh |
  245. {3:[No Name] [Preview][+] }|
  246. {2:-- }{5:match 1 of 10} |
  247. ]])
  248. end)
  249. end)