robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
8a0eb8f10b
master
1local t =require ( 'test.unit.testutil' ) 2local describe =t . describe 3local itp =t . gen_itp ( t . it ) 4 5local to_cstr =t . to_cstr 6local eq =t . eq 7 8local search =t . cimport ( './src/nvim/search.h' ) 9local globals =t . cimport ( './src/nvim/globals.h' ) 10local ffi =t . ffi 11 12itp ( 'pat_has_uppercase' , function () 13-- works on empty string 14eq ( false , search . pat_has_uppercase ( to_cstr ( '' ))) 15 16-- works with utf uppercase 17eq ( false , search . pat_has_uppercase ( to_cstr ( 'ä' ))) 18eq ( true , search . pat_has_uppercase ( to_cstr ( 'Ä' ))) 19eq ( true , search . pat_has_uppercase ( to_cstr ( 'äaÅ' ))) 20 21-- works when pat ends with backslash 22eq ( false , search . pat_has_uppercase ( to_cstr ( '\\' ))) 23eq ( false , search . pat_has_uppercase ( to_cstr ( 'ab$\\' ))) 24 25-- skips escaped characters 26eq ( false , search . pat_has_uppercase ( to_cstr ( '\\Ab' ))) 27eq ( true , search . pat_has_uppercase ( to_cstr ( '\\AU' ))) 28 29-- skips _X escaped characters 30eq ( false , search . pat_has_uppercase ( to_cstr ( '\\_Ab' ))) 31eq ( true , search . pat_has_uppercase ( to_cstr ( '\\_AU' ))) 32 33-- skips %X escaped characters 34eq ( false , search . pat_has_uppercase ( to_cstr ( 'aa\\%Ab' ))) 35eq ( true , search . pat_has_uppercase ( to_cstr ( 'aab\\%AU' ))) 36end ) 37 38describe ( 'search_regcomp' , function () 39local search_regcomp =function ( pat , patlen , pat_save , pat_use , options ) 40local regmatch =ffi . new ( 'regmmatch_T' ) 41local fail = 42search . search_regcomp ( to_cstr ( pat ), patlen , nil , pat_save , pat_use , options , true , regmatch ) 43return fail , regmatch 44end 45 46local get_search_pat =function () 47return t . internalize ( search . get_search_pat ()) 48end 49 50itp ( 'accepts regexp pattern with invalid utf' , function () 51--crafted to call reverse_text with invalid utf 52globals . curwin . w_onebuf_opt . wo_rl =1 53globals . curwin . w_onebuf_opt . wo_rlc =to_cstr ( 's' ) 54globals . cmdmod . cmod_flags =globals . CMOD_KEEPPATTERNS 55local fail =search_regcomp ( 'a\192' , 2 , 0 , 0 , 0 ) 56eq ( 1 , fail ) 57eq ( '\192a' , get_search_pat ()) 58end ) 59end )