robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.unit.testutil' ) 2local describe =t . describe 3local itp =t . gen_itp ( t . it ) 4 5local ffi =t . ffi 6local eq =t . eq 7local neq =t . neq 8 9local keycodes =t . cimport ( './src/nvim/keycodes.h' ) 10local NULL =t . NULL 11 12describe ( 'keycodes.c' , function () 13describe ( 'find_special_key()' , function () 14local srcp =ffi . new ( 'const unsigned char *[1]' ) 15local modp =ffi . new ( 'int[1]' ) 16 17itp ( 'no keycode' , function () 18srcp [ 0 ] ='abc' 19eq ( 0 , keycodes . find_special_key ( srcp , 3 , modp , 0 , NULL )) 20end ) 21 22itp ( 'keycode with multiple modifiers' , function () 23srcp [ 0 ] ='<C-M-S-A>' 24neq ( 0 , keycodes . find_special_key ( srcp , 9 , modp , 0 , NULL )) 25neq ( 0 , modp [ 0 ]) 26end ) 27 28itp ( 'case-insensitive' , function () 29-- Compare other capitalizations to this. 30srcp [ 0 ] ='<C-A>' 31local all_caps_key =keycodes . find_special_key ( srcp , 5 , modp , 0 , NULL ) 32local all_caps_mod =modp [ 0 ] 33 34srcp [ 0 ] ='<C-a>' 35eq ( all_caps_key , keycodes . find_special_key ( srcp , 5 , modp , 0 , NULL )) 36eq ( all_caps_mod , modp [ 0 ]) 37 38srcp [ 0 ] ='<c-A>' 39eq ( all_caps_key , keycodes . find_special_key ( srcp , 5 , modp , 0 , NULL )) 40eq ( all_caps_mod , modp [ 0 ]) 41 42srcp [ 0 ] ='<c-a>' 43eq ( all_caps_key , keycodes . find_special_key ( srcp , 5 , modp , 0 , NULL )) 44eq ( all_caps_mod , modp [ 0 ]) 45end ) 46 47itp ( 'double-quote in keycode #7411' , function () 48-- Unescaped with in_string=false 49srcp [ 0 ] ='<C-">' 50eq ( string . byte ( '"' ), keycodes . find_special_key ( srcp , 5 , modp , 0 , NULL )) 51 52-- Unescaped with in_string=true 53eq ( 0 , keycodes . find_special_key ( srcp , 5 , modp , keycodes . FSK_IN_STRING , NULL )) 54 55-- Escaped with in_string=false 56srcp [ 0 ] ='<C-\\">' 57-- Should fail because the key is invalid 58-- (more than 1 non-modifier character). 59eq ( 0 , keycodes . find_special_key ( srcp , 6 , modp , 0 , NULL )) 60 61-- Escaped with in_string=true 62eq ( string . byte ( '"' ), keycodes . find_special_key ( srcp , 6 , modp , keycodes . FSK_IN_STRING , NULL )) 63end ) 64end ) 65end )