mode_spec.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
  4. local command, eval = helpers.command, helpers.eval
  5. local eq = helpers.eq
  6. describe('ui mode_change event', function()
  7. local screen
  8. before_each(function()
  9. clear()
  10. screen = Screen.new(25, 4)
  11. screen:attach({rgb= true})
  12. screen:set_default_attr_ids( {
  13. [0] = {bold=true, foreground=255},
  14. [1] = {bold=true, reverse=true},
  15. [2] = {bold=true},
  16. [3] = {reverse=true},
  17. })
  18. end)
  19. it('works in normal mode', function()
  20. screen:expect{grid=[[
  21. ^ |
  22. {0:~ }|
  23. {0:~ }|
  24. |
  25. ]], mode="normal"}
  26. feed('d')
  27. screen:expect{grid=[[
  28. ^ |
  29. {0:~ }|
  30. {0:~ }|
  31. |
  32. ]], mode="operator"}
  33. feed('<esc>')
  34. screen:expect{grid=[[
  35. ^ |
  36. {0:~ }|
  37. {0:~ }|
  38. |
  39. ]], mode="normal"}
  40. end)
  41. it('works in insert mode', function()
  42. feed('i')
  43. screen:expect{grid=[[
  44. ^ |
  45. {0:~ }|
  46. {0:~ }|
  47. {2:-- INSERT --} |
  48. ]], mode="insert"}
  49. feed('word<esc>')
  50. screen:expect{grid=[[
  51. wor^d |
  52. {0:~ }|
  53. {0:~ }|
  54. |
  55. ]], mode="normal"}
  56. command("set showmatch")
  57. eq(eval('&matchtime'), 5) -- tenths of seconds
  58. feed('a(stuff')
  59. screen:expect{grid=[[
  60. word(stuff^ |
  61. {0:~ }|
  62. {0:~ }|
  63. {2:-- INSERT --} |
  64. ]], mode="insert"}
  65. feed(')')
  66. screen:expect{grid=[[
  67. word^(stuff) |
  68. {0:~ }|
  69. {0:~ }|
  70. {2:-- INSERT --} |
  71. ]], mode="showmatch"}
  72. screen:sleep(400)
  73. screen:expect{grid=[[
  74. word(stuff)^ |
  75. {0:~ }|
  76. {0:~ }|
  77. {2:-- INSERT --} |
  78. ]], mode="insert"}
  79. end)
  80. it('works in replace mode', function()
  81. feed('R')
  82. screen:expect{grid=[[
  83. ^ |
  84. {0:~ }|
  85. {0:~ }|
  86. {2:-- REPLACE --} |
  87. ]], mode="replace"}
  88. feed('word<esc>')
  89. screen:expect{grid=[[
  90. wor^d |
  91. {0:~ }|
  92. {0:~ }|
  93. |
  94. ]], mode="normal"}
  95. end)
  96. it('works in cmdline mode', function()
  97. feed(':')
  98. screen:expect{grid=[[
  99. |
  100. {0:~ }|
  101. {0:~ }|
  102. :^ |
  103. ]], mode="cmdline_normal"}
  104. feed('x<left>')
  105. screen:expect{grid=[[
  106. |
  107. {0:~ }|
  108. {0:~ }|
  109. :^x |
  110. ]], mode="cmdline_insert"}
  111. feed('<insert>')
  112. screen:expect{grid=[[
  113. |
  114. {0:~ }|
  115. {0:~ }|
  116. :^x |
  117. ]], mode="cmdline_replace"}
  118. feed('<right>')
  119. screen:expect{grid=[[
  120. |
  121. {0:~ }|
  122. {0:~ }|
  123. :x^ |
  124. ]], mode="cmdline_normal"}
  125. feed('<esc>')
  126. screen:expect{grid=[[
  127. ^ |
  128. {0:~ }|
  129. {0:~ }|
  130. |
  131. ]], mode="normal"}
  132. end)
  133. it('works in visual mode', function()
  134. insert("text")
  135. feed('v')
  136. screen:expect{grid=[[
  137. tex^t |
  138. {0:~ }|
  139. {0:~ }|
  140. {2:-- VISUAL --} |
  141. ]], mode="visual"}
  142. feed('<esc>')
  143. screen:expect{grid=[[
  144. tex^t |
  145. {0:~ }|
  146. {0:~ }|
  147. |
  148. ]], mode="normal"}
  149. command('set selection=exclusive')
  150. feed('v')
  151. screen:expect{grid=[[
  152. tex^t |
  153. {0:~ }|
  154. {0:~ }|
  155. {2:-- VISUAL --} |
  156. ]], mode="visual_select"}
  157. feed('<esc>')
  158. screen:expect{grid=[[
  159. tex^t |
  160. {0:~ }|
  161. {0:~ }|
  162. |
  163. ]], mode="normal"}
  164. end)
  165. end)