mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.1.1155: termcodes tests can be improved
Problem: Termcodes tests can be improved. Solution: Add helper functions to simplify tests. Dragging statusline for xterm and sgr. (Dominique Pelle, closes #4237)
This commit is contained in:
@@ -5,39 +5,61 @@ if has('gui_running') || !has('unix')
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Helper function to emit a terminal escape code.
|
||||||
|
func TerminalEscapeCode(code_xterm, code_sgr, row, col, m)
|
||||||
|
if &ttymouse ==# 'xterm'
|
||||||
|
" need to use byte encoding here.
|
||||||
|
let str = list2str([a:code_xterm, a:col + 0x20, a:row + 0x20])
|
||||||
|
if has('iconv')
|
||||||
|
let bytes = iconv(str, 'utf-8', 'latin1')
|
||||||
|
else
|
||||||
|
" Hopefully the numbers are not too big.
|
||||||
|
let bytes = str
|
||||||
|
endif
|
||||||
|
call feedkeys("\<Esc>[M" .. bytes, 'Lx!')
|
||||||
|
elseif &ttymouse ==# 'sgr'
|
||||||
|
call feedkeys(printf("\<Esc>[<%d;%d;%d%s", a:code_sgr, a:col, a:row, a:m), 'Lx!')
|
||||||
|
endif
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func MouseLeftClick(row, col)
|
||||||
|
call TerminalEscapeCode(0x20, 0, a:row, a:col, 'M')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func MouseLeftRelease(row, col)
|
||||||
|
call TerminalEscapeCode(0x23, 3, a:row, a:col, 'm')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func MouseLeftDrag(row, col)
|
||||||
|
call TerminalEscapeCode(0x43, 0x20, a:row, a:col, 'M')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func MouseWheelUp(row, col)
|
||||||
|
call TerminalEscapeCode(0x40, 0x40, a:row, a:col, 'M')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func MouseWheelDown(row, col)
|
||||||
|
call TerminalEscapeCode(0x41, 0x41, a:row, a:col, 'M')
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_xterm_mouse_click()
|
func Test_xterm_mouse_click()
|
||||||
new
|
new
|
||||||
let save_mouse = &mouse
|
let save_mouse = &mouse
|
||||||
let save_term = &term
|
let save_term = &term
|
||||||
let save_ttymouse = &ttymouse
|
let save_ttymouse = &ttymouse
|
||||||
set mouse=a
|
set mouse=a term=xterm
|
||||||
set term=xterm
|
|
||||||
call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer'])
|
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!')
|
|
||||||
|
|
||||||
|
for ttymouse_val in ['xterm', 'sgr']
|
||||||
|
exe 'set ttymouse=' . ttymouse_val
|
||||||
|
go
|
||||||
|
call assert_equal([0, 1, 1, 0], getpos('.'))
|
||||||
|
let row = 2
|
||||||
|
let col = 6
|
||||||
|
call MouseLeftClick(row, col)
|
||||||
|
call MouseLeftRelease(row, col)
|
||||||
call assert_equal([0, 2, 6, 0], getpos('.'))
|
call assert_equal([0, 2, 6, 0], getpos('.'))
|
||||||
|
endfor
|
||||||
" 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 &mouse = save_mouse
|
||||||
let &term = save_term
|
let &term = save_term
|
||||||
@@ -50,61 +72,31 @@ func Test_xterm_mouse_wheel()
|
|||||||
let save_mouse = &mouse
|
let save_mouse = &mouse
|
||||||
let save_term = &term
|
let save_term = &term
|
||||||
let save_ttymouse = &ttymouse
|
let save_ttymouse = &ttymouse
|
||||||
set mouse=a
|
set mouse=a term=xterm
|
||||||
set term=xterm
|
|
||||||
call setline(1, range(1, 100))
|
call setline(1, range(1, 100))
|
||||||
|
|
||||||
" Test Xterm mouse wheel.
|
for ttymouse_val in ['xterm', 'sgr']
|
||||||
set ttymouse=xterm
|
exe 'set ttymouse=' . ttymouse_val
|
||||||
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
|
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(1, line('w0'))
|
||||||
call assert_equal([0, 1, 1, 0], getpos('.'))
|
call assert_equal([0, 1, 1, 0], getpos('.'))
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
|
|
||||||
|
call MouseWheelDown(1, 1)
|
||||||
call assert_equal(4, line('w0'))
|
call assert_equal(4, line('w0'))
|
||||||
call assert_equal([0, 4, 1, 0], getpos('.'))
|
call assert_equal([0, 4, 1, 0], getpos('.'))
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
|
|
||||||
|
call MouseWheelDown(1, 1)
|
||||||
call assert_equal(7, line('w0'))
|
call assert_equal(7, line('w0'))
|
||||||
call assert_equal([0, 7, 1, 0], getpos('.'))
|
call assert_equal([0, 7, 1, 0], getpos('.'))
|
||||||
|
|
||||||
let button = 0x40 " wheel up.
|
call MouseWheelUp(1, 1)
|
||||||
|
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
|
|
||||||
call assert_equal(4, line('w0'))
|
call assert_equal(4, line('w0'))
|
||||||
call assert_equal([0, 7, 1, 0], getpos('.'))
|
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 MouseWheelUp(1, 1)
|
||||||
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(1, line('w0'))
|
||||||
call assert_equal([0, 7, 1, 0], getpos('.'))
|
call assert_equal([0, 7, 1, 0], getpos('.'))
|
||||||
|
endfor
|
||||||
|
|
||||||
let &mouse = save_mouse
|
let &mouse = save_mouse
|
||||||
let &term = save_term
|
let &term = save_term
|
||||||
@@ -116,29 +108,25 @@ func Test_xterm_mouse_drag_window_separator()
|
|||||||
let save_mouse = &mouse
|
let save_mouse = &mouse
|
||||||
let save_term = &term
|
let save_term = &term
|
||||||
let save_ttymouse = &ttymouse
|
let save_ttymouse = &ttymouse
|
||||||
set mouse=a
|
set mouse=a term=xterm
|
||||||
set term=xterm
|
|
||||||
set ttymouse=sgr
|
for ttymouse_val in ['xterm', 'sgr']
|
||||||
|
exe 'set ttymouse=' . ttymouse_val
|
||||||
|
|
||||||
" Split horizontally and test dragging the horizontal window separator.
|
" Split horizontally and test dragging the horizontal window separator.
|
||||||
split
|
split
|
||||||
let rowseparator = winheight(0) + 1
|
let rowseparator = winheight(0) + 1
|
||||||
|
|
||||||
let button = 0 " left down.
|
|
||||||
let row = rowseparator
|
let row = rowseparator
|
||||||
let col = 1
|
let col = 1
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
|
call MouseLeftClick(row, col)
|
||||||
|
|
||||||
let drag = 32
|
|
||||||
let row -= 1
|
let row -= 1
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!')
|
call MouseLeftDrag(row, col)
|
||||||
call assert_equal(rowseparator - 1, winheight(0) + 1)
|
call assert_equal(rowseparator - 1, winheight(0) + 1)
|
||||||
let row += 1
|
let row += 1
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!')
|
call MouseLeftDrag(row, col)
|
||||||
call assert_equal(rowseparator, winheight(0) + 1)
|
call assert_equal(rowseparator, winheight(0) + 1)
|
||||||
|
call MouseLeftRelease(row, col)
|
||||||
let release = 3
|
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dm", release, col, row), 'Lx!')
|
|
||||||
call assert_equal(rowseparator, winheight(0) + 1)
|
call assert_equal(rowseparator, winheight(0) + 1)
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
@@ -147,24 +135,53 @@ func Test_xterm_mouse_drag_window_separator()
|
|||||||
vsplit
|
vsplit
|
||||||
let colseparator = winwidth(0) + 1
|
let colseparator = winwidth(0) + 1
|
||||||
|
|
||||||
let button = 0
|
|
||||||
let row = 1
|
let row = 1
|
||||||
let col = colseparator
|
let col = colseparator
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", button, col, row), 'Lx!')
|
call MouseLeftClick(row, col)
|
||||||
|
|
||||||
let drag = 32
|
|
||||||
let col -= 1
|
let col -= 1
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!')
|
call MouseLeftDrag(row, col)
|
||||||
call assert_equal(colseparator - 1, winwidth(0) + 1)
|
call assert_equal(colseparator - 1, winwidth(0) + 1)
|
||||||
let col += 1
|
let col += 1
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dM", drag, col, row), 'Lx!')
|
call MouseLeftDrag(row, col)
|
||||||
call assert_equal(colseparator, winwidth(0) + 1)
|
call assert_equal(colseparator, winwidth(0) + 1)
|
||||||
|
call MouseLeftRelease(row, col)
|
||||||
let release = 3
|
|
||||||
call feedkeys(printf("\<Esc>[<%d;%d;%dm", release, col, row), 'Lx!')
|
|
||||||
call assert_equal(colseparator, winwidth(0) + 1)
|
call assert_equal(colseparator, winwidth(0) + 1)
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
|
endfor
|
||||||
|
|
||||||
|
let &mouse = save_mouse
|
||||||
|
let &term = save_term
|
||||||
|
let &ttymouse = save_ttymouse
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_xterm_mouse_drag_statusline()
|
||||||
|
let save_mouse = &mouse
|
||||||
|
let save_term = &term
|
||||||
|
let save_ttymouse = &ttymouse
|
||||||
|
set mouse=a term=xterm
|
||||||
|
|
||||||
|
for ttymouse_val in ['xterm', 'sgr']
|
||||||
|
exe 'set ttymouse=' . ttymouse_val
|
||||||
|
|
||||||
|
call assert_equal(1, &cmdheight)
|
||||||
|
let rowstatusline = winheight(0) + 1
|
||||||
|
let row = rowstatusline
|
||||||
|
let col = 1
|
||||||
|
call MouseLeftClick(row, col)
|
||||||
|
let row -= 1
|
||||||
|
call MouseLeftDrag(row, col)
|
||||||
|
call assert_equal(2, &cmdheight)
|
||||||
|
call assert_equal(rowstatusline - 1, winheight(0) + 1)
|
||||||
|
let row += 1
|
||||||
|
call MouseLeftDrag(row, col)
|
||||||
|
call assert_equal(1, &cmdheight)
|
||||||
|
call assert_equal(rowstatusline, winheight(0) + 1)
|
||||||
|
call MouseLeftRelease(row, col)
|
||||||
|
call assert_equal(1, &cmdheight)
|
||||||
|
call assert_equal(rowstatusline, winheight(0) + 1)
|
||||||
|
endfor
|
||||||
|
|
||||||
let &mouse = save_mouse
|
let &mouse = save_mouse
|
||||||
let &term = save_term
|
let &term = save_term
|
||||||
let &ttymouse = save_ttymouse
|
let &ttymouse = save_ttymouse
|
||||||
|
@@ -771,6 +771,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1155,
|
||||||
/**/
|
/**/
|
||||||
1154,
|
1154,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user