robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e533ec5160
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each =t . describe , t . it , t . before_each 5local command =n . command 6local clear =n . clear 7local eval =n . eval 8local eq =t . eq 9local pcall_err =t . pcall_err 10local feed =n . feed 11 12local scroll =function ( direction ) 13return n . request ( 'nvim_input_mouse' , 'wheel' , direction , '' , 0 , 2 , 2 ) 14end 15 16local screenrow =function () 17return n . call ( 'screenrow' ) 18end 19 20local screencol =function () 21return n . call ( 'screencol' ) 22end 23 24describe ( "'mousescroll'" , function () 25local function should_fail ( val , msg ) 26eq ( msg , pcall_err ( command , 'set mousescroll=' .. val )) 27end 28 29local function should_succeed ( val ) 30command ( 'set mousescroll=' .. val ) 31end 32 33before_each ( function () 34clear () 35command ( 'set nowrap lines=20 columns=20 virtualedit=all' ) 36feed ( '100o<Esc>50G10|' ) 37end ) 38 39it ( 'handles invalid values' , function () 40-- empty string (no direction set) 41should_fail ( '' , 'Vim(set):E474: Invalid argument: mousescroll=' ) 42-- unknown direction 43should_fail ( 'foo:123' , "Vim(set):E474: Unknown item 'foo': mousescroll=foo:123" ) 44-- integer overflow 45should_fail ( 46'ver:99999999999999999999' , 47"Vim(set):E474: 'ver' number is out of range: mousescroll=ver:99999999999999999999" 48) 49-- expected digit 50should_fail ( 'ver:bar' , "Vim(set):E474: 'ver' requires a number: mousescroll=ver:bar" ) 51-- negative count 52should_fail ( 'ver:-1' , "Vim(set):E474: 'ver' requires a number: mousescroll=ver:-1" ) 53end ) 54 55it ( 'handles valid values' , function () 56should_succeed ( 'hor:1,ver:1' ) -- both directions set 57should_succeed ( 'hor:1' ) -- only horizontal 58should_succeed ( 'ver:1' ) -- only vertical 59should_succeed ( 'hor:0,ver:0' ) -- zero 60should_succeed ( 'hor:2147483647' ) -- large count 61should_succeed ( 'hor:1,hor:2' ) -- duplicate direction: last wins 62end ) 63 64it ( 'default set correctly' , function () 65eq ( 'ver:3,hor:6' , eval ( '&mousescroll' )) 66 67eq ( 10 , screenrow ()) 68scroll ( 'up' ) 69eq ( 13 , screenrow ()) 70scroll ( 'down' ) 71eq ( 10 , screenrow ()) 72 73eq ( 10 , screencol ()) 74scroll ( 'right' ) 75eq ( 4 , screencol ()) 76scroll ( 'left' ) 77eq ( 10 , screencol ()) 78end ) 79 80it ( 'vertical scrolling falls back to default value' , function () 81command ( 'set mousescroll=hor:1' ) 82eq ( 10 , screenrow ()) 83scroll ( 'up' ) 84eq ( 13 , screenrow ()) 85end ) 86 87it ( 'horizontal scrolling falls back to default value' , function () 88command ( 'set mousescroll=ver:1' ) 89eq ( 10 , screencol ()) 90scroll ( 'right' ) 91eq ( 4 , screencol ()) 92end ) 93 94it ( 'count of zero disables mouse scrolling' , function () 95command ( 'set mousescroll=hor:0,ver:0' ) 96 97eq ( 10 , screenrow ()) 98scroll ( 'up' ) 99eq ( 10 , screenrow ()) 100scroll ( 'down' ) 101eq ( 10 , screenrow ()) 102 103eq ( 10 , screencol ()) 104scroll ( 'right' ) 105eq ( 10 , screencol ()) 106scroll ( 'left' ) 107eq ( 10 , screencol ()) 108 109-- vertical scrolling is still disabled with non-zero 'scrolloff' value 110command ( 'set scrolloff=1' ) 111 112eq ( 10 , screenrow ()) 113scroll ( 'up' ) 114eq ( 10 , screenrow ()) 115scroll ( 'down' ) 116eq ( 10 , screenrow ()) 117 118-- also in insert mode 119feed ( 'i' ) 120 121eq ( 10 , screenrow ()) 122scroll ( 'up' ) 123eq ( 10 , screenrow ()) 124scroll ( 'down' ) 125eq ( 10 , screenrow ()) 126end ) 127 128local test_vertical_scrolling =function () 129eq ( 10 , screenrow ()) 130 131command ( 'set mousescroll=ver:1' ) 132scroll ( 'up' ) 133eq ( 11 , screenrow ()) 134 135command ( 'set mousescroll=ver:2' ) 136scroll ( 'down' ) 137eq ( 9 , screenrow ()) 138 139command ( 'set mousescroll=ver:5' ) 140scroll ( 'up' ) 141eq ( 14 , screenrow ()) 142end 143 144it ( 'controls vertical scrolling in normal mode' , function () 145test_vertical_scrolling () 146end ) 147 148it ( 'controls vertical scrolling in insert mode' , function () 149feed ( 'i' ) 150test_vertical_scrolling () 151end ) 152 153local test_horizontal_scrolling =function () 154eq ( 10 , screencol ()) 155 156command ( 'set mousescroll=hor:1' ) 157scroll ( 'right' ) 158eq ( 9 , screencol ()) 159 160command ( 'set mousescroll=hor:3' ) 161scroll ( 'right' ) 162eq ( 6 , screencol ()) 163 164command ( 'set mousescroll=hor:2' ) 165scroll ( 'left' ) 166eq ( 8 , screencol ()) 167end 168 169it ( 'controls horizontal scrolling in normal mode' , function () 170test_horizontal_scrolling () 171end ) 172 173it ( 'controls horizontal scrolling in insert mode' , function () 174feed ( 'i' ) 175test_horizontal_scrolling () 176end ) 177end )