robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local eq =t . eq 7local pcall_err =t . pcall_err 8local clear =n . clear 9local fn =n . fn 10local command =n . command 11 12before_each ( clear ) 13 14describe ( 'setmatches()' , function () 15it ( 'correctly handles case when both group and pattern entries are numbers' , function () 16command ( 'hi def link 1 PreProc' ) 17eq ( 0 , fn . setmatches ( { { group =1 , pattern =2 , id =3 , priority =4 } } )) 18eq ( { 19{ 20group ='1' , 21pattern ='2' , 22id =3 , 23priority =4 , 24} , 25} , fn . getmatches ()) 26eq ( 0 , fn . setmatches ( { { group =1 , pattern =2 , id =3 , priority =4 , conceal =5 } } )) 27eq ( { 28{ 29group ='1' , 30pattern ='2' , 31id =3 , 32priority =4 , 33conceal ='5' , 34} , 35} , fn . getmatches ()) 36eq ( 370 , 38fn . setmatches ( { 39{ group =1 , pos1 ={ 2 } , pos2 ={ 6 } , id =3 , priority =4 , conceal =5 } , 40} ) 41) 42eq ( { 43{ 44group ='1' , 45pos1 ={ 2 } , 46pos2 ={ 6 } , 47id =3 , 48priority =4 , 49conceal ='5' , 50} , 51} , fn . getmatches ()) 52end ) 53 54it ( 'does not fail if highlight group is not defined' , function () 55eq ( 0 , fn . setmatches { { group =1 , pattern =2 , id =3 , priority =4 } } ) 56eq ( { { group ='1' , pattern ='2' , id =3 , priority =4 } } , fn . getmatches ()) 57eq ( 580 , 59fn . setmatches { 60{ group =1 , pos1 ={ 2 } , pos2 ={ 6 } , id =3 , priority =4 , conceal =5 } , 61} 62) 63eq ( 64{ { group ='1' , pos1 ={ 2 } , pos2 ={ 6 } , id =3 , priority =4 , conceal ='5' } } , 65fn . getmatches () 66) 67end ) 68end ) 69 70describe ( 'matchadd()' , function () 71it ( 'correctly works when first two arguments and conceal are numbers at once' , function () 72command ( 'hi def link 1 PreProc' ) 73eq ( 4 , fn . matchadd ( 1 , 2 , 3 , 4 , { conceal =5 } )) 74eq ( { 75{ 76group ='1' , 77pattern ='2' , 78priority =3 , 79id =4 , 80conceal ='5' , 81} , 82} , fn . getmatches ()) 83end ) 84end ) 85 86describe ( 'matchaddpos()' , function () 87it ( 'errors out on invalid input' , function () 88command ( 'hi clear PreProc' ) 89eq ( 90'Vim(let):E5030: Empty list at position 0' , 91pcall_err ( command , 'let val = matchaddpos("PreProc", [[]])' ) 92) 93eq ( 94'Vim(let):E5030: Empty list at position 1' , 95pcall_err ( command , 'let val = matchaddpos("PreProc", [1, v:_null_list])' ) 96) 97eq ( 98'Vim(let):E5031: List or number required at position 1' , 99pcall_err ( command , 'let val = matchaddpos("PreProc", [1, v:_null_dict])' ) 100) 101end ) 102it ( 'works with 0 lnum' , function () 103command ( 'hi clear PreProc' ) 104eq ( 4 , fn . matchaddpos ( 'PreProc' , { 1 } , 3 , 4 )) 105eq ( { 106{ 107group ='PreProc' , 108pos1 ={ 1 } , 109priority =3 , 110id =4 , 111} , 112} , fn . getmatches ()) 113fn . matchdelete ( 4 ) 114eq ( 4 , fn . matchaddpos ( 'PreProc' , { { 0 } , 1 } , 3 , 4 )) 115eq ( { 116{ 117group ='PreProc' , 118pos1 ={ 1 } , 119priority =3 , 120id =4 , 121} , 122} , fn . getmatches ()) 123fn . matchdelete ( 4 ) 124eq ( 4 , fn . matchaddpos ( 'PreProc' , { 0 , 1 } , 3 , 4 )) 125eq ( { 126{ 127group ='PreProc' , 128pos1 ={ 1 } , 129priority =3 , 130id =4 , 131} , 132} , fn . getmatches ()) 133end ) 134it ( 'works with negative numbers' , function () 135command ( 'hi clear PreProc' ) 136eq ( 4 , fn . matchaddpos ( 'PreProc' , { - 10 , 1 } , 3 , 4 )) 137eq ( { 138{ 139group ='PreProc' , 140pos1 ={ 1 } , 141priority =3 , 142id =4 , 143} , 144} , fn . getmatches ()) 145fn . matchdelete ( 4 ) 146eq ( 4 , fn . matchaddpos ( 'PreProc' , { { - 10 } , 1 } , 3 , 4 )) 147eq ( { 148{ 149group ='PreProc' , 150pos1 ={ 1 } , 151priority =3 , 152id =4 , 153} , 154} , fn . getmatches ()) 155fn . matchdelete ( 4 ) 156eq ( 4 , fn . matchaddpos ( 'PreProc' , { { 2 , - 1 } , 1 } , 3 , 4 )) 157eq ( { 158{ 159group ='PreProc' , 160pos1 ={ 1 } , 161priority =3 , 162id =4 , 163} , 164} , fn . getmatches ()) 165fn . matchdelete ( 4 ) 166eq ( 4 , fn . matchaddpos ( 'PreProc' , { { 2 , 0 , - 1 } , 1 } , 3 , 4 )) 167eq ( { 168{ 169group ='PreProc' , 170pos1 ={ 1 } , 171priority =3 , 172id =4 , 173} , 174} , fn . getmatches ()) 175end ) 176it ( 'works with zero length' , function () 177local screen =Screen . new ( 40 , 5 ) 178fn . setline ( 1 , 'abcdef' ) 179command ( 'hi PreProc guifg=Red' ) 180eq ( 4 , fn . matchaddpos ( 'PreProc' , { { 1 , 2 , 0 } } , 3 , 4 )) 181eq ( { 182{ 183group ='PreProc' , 184pos1 ={ 1 , 2 , 0 } , 185priority =3 , 186id =4 , 187} , 188} , fn . getmatches ()) 189screen : expect ( 190[[ 191^a{1:b}cdef | 192{2:~ }|*3 193| 194]] , 195{ 196[ 1 ] ={ foreground =Screen . colors . Red } , 197[ 2 ] ={ bold =true , foreground =Screen . colors . Blue1 } , 198} 199) 200end ) 201end )