mousescroll_spec.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local command = helpers.command
  3. local clear = helpers.clear
  4. local eval = helpers.eval
  5. local eq = helpers.eq
  6. local exc_exec = helpers.exc_exec
  7. local feed = helpers.feed
  8. local scroll = function(direction)
  9. return helpers.request('nvim_input_mouse', 'wheel', direction, '', 0, 2, 2)
  10. end
  11. local screenrow = function()
  12. return helpers.call('screenrow')
  13. end
  14. local screencol = function()
  15. return helpers.call('screencol')
  16. end
  17. describe("'mousescroll'", function()
  18. local invalid_arg = 'Vim(set):E474: Invalid argument: mousescroll='
  19. local digit_expected = 'Vim(set):E548: digit expected: mousescroll='
  20. local function should_fail(val, errorstr)
  21. eq(errorstr..val, exc_exec('set mousescroll='..val))
  22. end
  23. local function should_succeed(val)
  24. eq(0, exc_exec('set mousescroll='..val))
  25. end
  26. before_each(function()
  27. clear()
  28. command('set nowrap lines=20 columns=20 virtualedit=all')
  29. feed('100o<Esc>50G10|')
  30. end)
  31. it('handles invalid values', function()
  32. should_fail('', invalid_arg) -- empty string
  33. should_fail('foo:123', invalid_arg) -- unknown direction
  34. should_fail('hor:1,hor:2', invalid_arg) -- duplicate direction
  35. should_fail('ver:99999999999999999999', invalid_arg) -- integer overflow
  36. should_fail('ver:bar', digit_expected) -- expected digit
  37. should_fail('ver:-1', digit_expected) -- negative count
  38. end)
  39. it('handles valid values', function()
  40. should_succeed('hor:1,ver:1') -- both directions set
  41. should_succeed('hor:1') -- only horizontal
  42. should_succeed('ver:1') -- only vertical
  43. should_succeed('hor:0,ver:0') -- zero
  44. should_succeed('hor:2147483647') -- large count
  45. end)
  46. it('default set correctly', function()
  47. eq('ver:3,hor:6', eval('&mousescroll'))
  48. eq(10, screenrow())
  49. scroll('up')
  50. eq(13, screenrow())
  51. scroll('down')
  52. eq(10, screenrow())
  53. eq(10, screencol())
  54. scroll('right')
  55. eq(4, screencol())
  56. scroll('left')
  57. eq(10, screencol())
  58. end)
  59. it('vertical scrolling falls back to default value', function()
  60. command('set mousescroll=hor:1')
  61. eq(10, screenrow())
  62. scroll('up')
  63. eq(13, screenrow())
  64. end)
  65. it('horizontal scrolling falls back to default value', function()
  66. command('set mousescroll=ver:1')
  67. eq(10, screencol())
  68. scroll('right')
  69. eq(4, screencol())
  70. end)
  71. it('count of zero disables mouse scrolling', function()
  72. command('set mousescroll=hor:0,ver:0')
  73. eq(10, screenrow())
  74. scroll('up')
  75. eq(10, screenrow())
  76. scroll('down')
  77. eq(10, screenrow())
  78. eq(10, screencol())
  79. scroll('right')
  80. eq(10, screencol())
  81. scroll('left')
  82. eq(10, screencol())
  83. -- vertical scrolling is still disabled with non-zero 'scrolloff' value
  84. command('set scrolloff=1')
  85. eq(10, screenrow())
  86. scroll('up')
  87. eq(10, screenrow())
  88. scroll('down')
  89. eq(10, screenrow())
  90. -- also in insert mode
  91. feed('i')
  92. eq(10, screenrow())
  93. scroll('up')
  94. eq(10, screenrow())
  95. scroll('down')
  96. eq(10, screenrow())
  97. end)
  98. local test_vertical_scrolling = function()
  99. eq(10, screenrow())
  100. command('set mousescroll=ver:1')
  101. scroll('up')
  102. eq(11, screenrow())
  103. command('set mousescroll=ver:2')
  104. scroll('down')
  105. eq(9, screenrow())
  106. command('set mousescroll=ver:5')
  107. scroll('up')
  108. eq(14, screenrow())
  109. end
  110. it('controls vertical scrolling in normal mode', function()
  111. test_vertical_scrolling()
  112. end)
  113. it('controls vertical scrolling in insert mode', function()
  114. feed('i')
  115. test_vertical_scrolling()
  116. end)
  117. local test_horizontal_scrolling = function()
  118. eq(10, screencol())
  119. command('set mousescroll=hor:1')
  120. scroll('right')
  121. eq(9, screencol())
  122. command('set mousescroll=hor:3')
  123. scroll('right')
  124. eq(6, screencol())
  125. command('set mousescroll=hor:2')
  126. scroll('left')
  127. eq(8, screencol())
  128. end
  129. it('controls horizontal scrolling in normal mode', function()
  130. test_horizontal_scrolling()
  131. end)
  132. it('controls horizontal scrolling in insert mode', function()
  133. feed('i')
  134. test_horizontal_scrolling()
  135. end)
  136. end)