robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each , pending =t . describe , t . it , t . before_each , t . pending 5local clear , feed , eq =n . clear , n . feed , t . eq 6local expect , command , eval =n . expect , n . command , n . eval 7local insert , call =n . insert , n . call 8local exec_capture , dedent =n . exec_capture , t . dedent 9 10-- First test it's implemented using the :lmap and :lnoremap commands, then 11-- check those mappings behave as expected. 12describe ( "'keymap' / :lmap" , function () 13before_each ( function () 14clear () 15insert ( 'lllaaa' ) 16command ( 'set iminsert=1' ) 17command ( 'set imsearch=1' ) 18command ( 'lmap l a' ) 19feed ( 'gg0' ) 20end ) 21 22describe ( "'keymap' as :lmap" , function () 23-- Shows that 'keymap' sets language mappings that allows remapping. 24-- This equivalence allows us to only test :lmap commands and assert they 25-- behave the same as 'keymap' settings. 26-- It does rely on the absence of special code that implements 'keymap' 27-- and :lmap differently but shows mappings from the 'keymap' after 28-- typing :lmap. 29-- At the moment this is the case. 30it ( "'keymap' mappings are shown with :lmap" , function () 31command ( 'lmapclear' ) 32command ( 'lmapclear <buffer>' ) 33command ( 'set keymap=dvorak' ) 34command ( 'set nomore' ) 35local bindings =exec_capture ( 'lmap' ) 36eq ( 37dedent ( [[ 38 39l " @_ 40l ' @- 41l + @} 42l , @w 43l - @[ 44l . @v 45l / @z 46l : @S 47l ; @s 48l < @W 49l = @] 50l > @V 51l ? @Z 52l A @A 53l B @X 54l C @J 55l D @E 56l E @> 57l F @U 58l G @I 59l H @D 60l I @C 61l J @H 62l K @T 63l L @N 64l M @M 65l N @B 66l O @R 67l P @L 68l Q @" 69l R @P 70l S @O 71l T @Y 72l U @G 73l V @K 74l W @< 75l X @Q 76l Y @F 77l Z @: 78l [ @/ 79l \ @\ 80l ] @= 81l _ @{ 82l a @a 83l b @x 84l c @j 85l d @e 86l e @. 87l f @u 88l g @i 89l h @d 90l i @c 91l j @h 92l k @t 93l l @n 94l m @m 95l n @b 96l o @r 97l p @l 98l q @' 99l r @p 100l s @o 101l t @y 102l u @g 103l v @k 104l w @, 105l x @q 106l y @f 107l z @; 108l { @? 109l | @| 110l } @+]] ), 111bindings 112) 113end ) 114end ) 115describe ( "'iminsert' option" , function () 116it ( 'Uses :lmap in insert mode when ON' , function () 117feed ( 'il<esc>' ) 118expect ( 'alllaaa' ) 119end ) 120it ( 'Ignores :lmap in insert mode when OFF' , function () 121command ( 'set iminsert=0' ) 122feed ( 'il<esc>' ) 123expect ( 'llllaaa' ) 124end ) 125it ( 'Can be toggled with <C-^> in insert mode' , function () 126feed ( 'i<C-^>l<C-^>l<esc>' ) 127expect ( 'lalllaaa' ) 128eq ( 1 , eval ( '&iminsert' )) 129feed ( 'i<C-^><esc>' ) 130eq ( 0 , eval ( '&iminsert' )) 131end ) 132end ) 133describe ( "'imsearch' option" , function () 134it ( 'Uses :lmap at search prompt when ON' , function () 135feed ( '/lll<cr>3x' ) 136expect ( 'lll' ) 137end ) 138it ( 'Ignores :lmap at search prompt when OFF' , function () 139command ( 'set imsearch=0' ) 140feed ( 'gg/lll<cr>3x' ) 141expect ( 'aaa' ) 142end ) 143it ( 'Can be toggled with C-^' , function () 144eq ( 1 , eval ( '&imsearch' )) 145feed ( '/<C-^>lll<cr>3x' ) 146expect ( 'aaa' ) 147eq ( 0 , eval ( '&imsearch' )) 148feed ( 'u0/<C-^>lll<cr>3x' ) 149expect ( 'lll' ) 150eq ( 1 , eval ( '&imsearch' )) 151end ) 152it ( "can follow 'iminsert'" , function () 153command ( 'set imsearch=-1' ) 154feed ( '/lll<cr>3x' ) 155expect ( 'lll' ) 156eq ( - 1 , eval ( '&imsearch' )) 157eq ( 1 , eval ( '&iminsert' )) 158feed ( 'u/<C-^>lll<cr>3x' ) 159expect ( 'aaa' ) 160eq ( - 1 , eval ( '&imsearch' )) 161eq ( 0 , eval ( '&iminsert' )) 162end ) 163end ) 164it ( ':lmap not applied to macros' , function () 165command ( "call setreg('a', 'il')" ) 166feed ( '@a' ) 167expect ( 'llllaaa' ) 168eq ( 'il' , call ( 'getreg' , 'a' )) 169end ) 170it ( ':lmap applied to macro recording' , function () 171feed ( 'qail<esc>q@a' ) 172expect ( 'aalllaaa' ) 173eq ( 'ia' , call ( 'getreg' , 'a' )) 174end ) 175it ( ':lmap not applied to mappings' , function () 176command ( 'imap t l' ) 177feed ( 'it<esc>' ) 178expect ( 'llllaaa' ) 179end ) 180it ( 'mappings applied to keys created with :lmap' , function () 181command ( 'imap a x' ) 182feed ( 'il<esc>' ) 183expect ( 'xlllaaa' ) 184end ) 185it ( 'mappings not applied to keys gotten with :lnoremap' , function () 186command ( 'lmapclear' ) 187command ( 'lnoremap l a' ) 188command ( 'imap a x' ) 189feed ( 'il<esc>' ) 190expect ( 'alllaaa' ) 191end ) 192-- This is a problem introduced when introducing :lmap and macro 193-- compatibility. There are no plans to fix this as the complexity involved 194-- seems too great. 195pending ( 'mappings not applied to macro replay of :lnoremap' , function () 196command ( 'lmapclear' ) 197command ( 'lnoremap l a' ) 198command ( 'imap a x' ) 199feed ( 'qail<esc>q' ) 200expect ( 'alllaaa' ) 201feed ( '@a' ) 202expect ( 'aalllaaa' ) 203end ) 204it ( 'is applied when using f/F t/T' , function () 205feed ( 'flx' ) 206expect ( 'lllaa' ) 207feed ( '0ia<esc>4lFlx' ) 208expect ( 'lllaa' ) 209feed ( 'tllx' ) 210expect ( 'llla' ) 211feed ( '0ia<esc>4lTlhx' ) 212expect ( 'llla' ) 213end ) 214it ( 'takes priority over :imap mappings' , function () 215command ( 'imap l x' ) 216feed ( 'il<esc>' ) 217expect ( 'alllaaa' ) 218command ( 'lmapclear' ) 219command ( 'lmap l a' ) 220feed ( 'il' ) 221expect ( 'aalllaaa' ) 222end ) 223it ( 'does not cause recursive mappings' , function () 224command ( 'lmap a l' ) 225feed ( 'qaila<esc>q' ) 226expect ( 'allllaaa' ) 227feed ( 'u@a' ) 228expect ( 'allllaaa' ) 229end ) 230it ( 'can handle multicharacter mappings' , function () 231command ( "lmap 'a x" ) 232command ( "lmap '' '" ) 233feed ( "qai'a''a<esc>q" ) 234expect ( "x'alllaaa" ) 235feed ( 'u@a' ) 236expect ( "x'alllaaa" ) 237end ) 238end )