view src/testdir/test_termcodes.vim @ 16275:ed5172ae1c32 v8.1.1142

patch 8.1.1142: no test for dragging the window separators with the mouse commit https://github.com/vim/vim/commit/3fb01a53c685d8d7e7bd83c33500de80aed0d7c8 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 9 21:52:02 2019 +0200 patch 8.1.1142: no test for dragging the window separators with the mouse Problem: No test for dragging the window separators with the mouse. Solution: Add a test. (Dominique Pelle, closes https://github.com/vim/vim/issues/4226)
author Bram Moolenaar <Bram@vim.org>
date Tue, 09 Apr 2019 22:00:05 +0200
parents 7feb5b90be5f
children f3d579f009d1
line wrap: on
line source

" Tests for decoding escape sequences sent by the terminal.

" This only works for Unix in a terminal
if has('gui_running') || !has('unix')
  finish
endif

func Test_xterm_mouse_click()
  new
  let save_mouse = &mouse
  let save_term = &term
  let save_ttymouse = &ttymouse
  set mouse=a
  set term=xterm
  call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer'])
  redraw

  " Xterm mouse click
  set ttymouse=xterm
  let button = 0x20  " left down
  let row = 2 + 32
  let col = 6 + 32
  call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!')

  let button = 0x23  " release
  call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!')

  call assert_equal([0, 2, 6, 0], getpos('.'))

  " SGR mouse click
  set ttymouse=sgr
  let button = 0  " left down
  let row = 3
  let col = 9
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')

  let button = 3  " release
  call feedkeys(printf("\<Esc>[<%d;%d;%dm", button, col, row), 'Lx!')

  call assert_equal([0, 3, 9, 0], getpos('.'))

  let &mouse = save_mouse
  let &term = save_term
  let &ttymouse = save_ttymouse
  bwipe!
endfunc

func Test_xterm_mouse_wheel()
  new
  let save_mouse = &mouse
  let save_term = &term
  let save_ttymouse = &ttymouse
  set mouse=a
  set term=xterm
  call setline(1, range(1, 100))

  " Test Xterm mouse wheel.
  set ttymouse=xterm
  let button = 0x41 " wheel down.
  let row = 1 + 32  " cursor position for mouse wheel is not relevant.
  let col = 1 + 32

  call assert_equal(1, line('w0'))
  call assert_equal([0, 1, 1, 0], getpos('.'))
  call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!')
  call assert_equal(4, line('w0'))
  call assert_equal([0, 4, 1, 0], getpos('.'))
  call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!')
  call assert_equal(7, line('w0'))
  call assert_equal([0, 7, 1, 0], getpos('.'))

  let button = 0x40  " wheel up.

  call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!')
  call assert_equal(4, line('w0'))
  call assert_equal([0, 7, 1, 0], getpos('.'))
  call feedkeys("\<Esc>[M" .. list2str([button, col, row]), 'Lx!')
  call assert_equal(1, line('w0'))
  call assert_equal([0, 7, 1, 0], getpos('.'))

  " Test SGR mouse wheel.
  set ttymouse=sgr
  go
  let button = 0x41 " wheel down.
  let row = 1       " cursor position for mouse wheel is not relevant.
  let col = 1

  call assert_equal(1, line('w0'))
  call assert_equal([0, 1, 1, 0], getpos('.'))
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
  call assert_equal(4, line('w0'))
  call assert_equal([0, 4, 1, 0], getpos('.'))
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
  call assert_equal(7, line('w0'))
  call assert_equal([0, 7, 1, 0], getpos('.'))

  let button = 0x40  " wheel up.

  call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
  call assert_equal(4, line('w0'))
  call assert_equal([0, 7, 1, 0], getpos('.'))
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
  call assert_equal(1, line('w0'))
  call assert_equal([0, 7, 1, 0], getpos('.'))
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
  call assert_equal(1, line('w0'))
  call assert_equal([0, 7, 1, 0], getpos('.'))

  let &mouse = save_mouse
  let &term = save_term
  let &ttymouse = save_ttymouse
  bwipe!
endfunc

func Test_xterm_mouse_drag_window_separator()
  let save_mouse = &mouse
  let save_term = &term
  let save_ttymouse = &ttymouse
  set mouse=a
  set term=xterm
  set ttymouse=sgr

  " Split horizontally and test dragging the horizontal window separator.
  split
  let rowseparator = winheight(0) + 1

  let button = 0  " left down.
  let row = rowseparator
  let col = 1
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')

  let drag = 32
  let row -= 1
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!')
  call assert_equal(rowseparator - 1, winheight(0) + 1)
  let row += 1
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!')
  call assert_equal(rowseparator, winheight(0) + 1)

  let release = 3
  call feedkeys(printf("\<Esc>[<%d;%d;%dm", release, col, row), 'Lx!')
  call assert_equal(rowseparator, winheight(0) + 1)

  bwipe!

  " Split vertically and test dragging the vertical window separator.
  vsplit
  let colseparator = winwidth(0) + 1

  let button = 0
  let row = 1
  let col = colseparator
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')

  let drag = 32
  let col -= 1
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!')
  call assert_equal(colseparator - 1, winwidth(0) + 1)
  let col += 1
  call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!')
  call assert_equal(colseparator, winwidth(0) + 1)

  let release = 3
  call feedkeys(printf("\<Esc>[<%d;%d;%dm", release, col, row), 'Lx!')
  call assert_equal(colseparator, winwidth(0) + 1)

  bwipe!
  let &mouse = save_mouse
  let &term = save_term
  let &ttymouse = save_ttymouse
endfunc