mode_spec.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 = helpers.command
  5. local retry = helpers.retry
  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. local matchtime = 0
  57. command("set showmatch")
  58. retry(nil, nil, function()
  59. matchtime = matchtime + 1
  60. local screen_timeout = 1000 * matchtime -- fail faster for retry.
  61. command("set matchtime=" .. matchtime) -- tenths of seconds
  62. feed('a(stuff')
  63. screen:expect{grid=[[
  64. word(stuff^ |
  65. {0:~ }|
  66. {0:~ }|
  67. {2:-- INSERT --} |
  68. ]], mode="insert", timeout=screen_timeout}
  69. feed(')')
  70. screen:expect{grid=[[
  71. word^(stuff) |
  72. {0:~ }|
  73. {0:~ }|
  74. {2:-- INSERT --} |
  75. ]], mode="showmatch", timeout=screen_timeout}
  76. screen:expect{grid=[[
  77. word(stuff)^ |
  78. {0:~ }|
  79. {0:~ }|
  80. {2:-- INSERT --} |
  81. ]], mode="insert", timeout=screen_timeout}
  82. end)
  83. end)
  84. it('works in replace mode', function()
  85. feed('R')
  86. screen:expect{grid=[[
  87. ^ |
  88. {0:~ }|
  89. {0:~ }|
  90. {2:-- REPLACE --} |
  91. ]], mode="replace"}
  92. feed('word<esc>')
  93. screen:expect{grid=[[
  94. wor^d |
  95. {0:~ }|
  96. {0:~ }|
  97. |
  98. ]], mode="normal"}
  99. end)
  100. it('works in cmdline mode', function()
  101. feed(':')
  102. screen:expect{grid=[[
  103. |
  104. {0:~ }|
  105. {0:~ }|
  106. :^ |
  107. ]], mode="cmdline_normal"}
  108. feed('x<left>')
  109. screen:expect{grid=[[
  110. |
  111. {0:~ }|
  112. {0:~ }|
  113. :^x |
  114. ]], mode="cmdline_insert"}
  115. feed('<insert>')
  116. screen:expect{grid=[[
  117. |
  118. {0:~ }|
  119. {0:~ }|
  120. :^x |
  121. ]], mode="cmdline_replace"}
  122. feed('<right>')
  123. screen:expect{grid=[[
  124. |
  125. {0:~ }|
  126. {0:~ }|
  127. :x^ |
  128. ]], mode="cmdline_normal"}
  129. feed('<esc>')
  130. screen:expect{grid=[[
  131. ^ |
  132. {0:~ }|
  133. {0:~ }|
  134. |
  135. ]], mode="normal"}
  136. end)
  137. it('works in visual mode', function()
  138. insert("text")
  139. feed('v')
  140. screen:expect{grid=[[
  141. tex^t |
  142. {0:~ }|
  143. {0:~ }|
  144. {2:-- VISUAL --} |
  145. ]], mode="visual"}
  146. feed('<esc>')
  147. screen:expect{grid=[[
  148. tex^t |
  149. {0:~ }|
  150. {0:~ }|
  151. |
  152. ]], mode="normal"}
  153. command('set selection=exclusive')
  154. feed('v')
  155. screen:expect{grid=[[
  156. tex^t |
  157. {0:~ }|
  158. {0:~ }|
  159. {2:-- VISUAL --} |
  160. ]], mode="visual_select"}
  161. feed('<esc>')
  162. screen:expect{grid=[[
  163. tex^t |
  164. {0:~ }|
  165. {0:~ }|
  166. |
  167. ]], mode="normal"}
  168. end)
  169. end)