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 =t . describe , t . it , t . before_each 5local exec_lua =n . exec_lua 6local eq =t . eq 7local eval =n . eval 8local clear =n . clear 9 10describe ( 'vim.inspect_pos' , function () 11before_each ( function () 12clear () 13end ) 14 15it ( 'it returns items' , function () 16local buf , ns1 , ns2 =exec_lua ( function () 17local buf =vim . api . nvim_create_buf ( true , false ) 18_G . buf1 =vim . api . nvim_create_buf ( true , false ) 19local ns1 =vim . api . nvim_create_namespace ( 'ns1' ) 20local ns2 =vim . api . nvim_create_namespace ( '' ) 21vim . api . nvim_set_current_buf ( buf ) 22vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , { 'local a = 123' } ) 23vim . api . nvim_buf_set_lines ( _G . buf1 , 0 , - 1 , false , { '--commentline' } ) 24vim . bo [ buf ]. filetype ='lua' 25vim . bo [ _G . buf1 ]. filetype ='lua' 26vim . api . nvim_buf_set_extmark ( buf , ns1 , 0 , 10 , { hl_group ='Normal' } ) 27vim . api . nvim_buf_set_extmark ( buf , ns1 , 0 , 10 , { hl_group ='Normal' , end_col =10 } ) 28vim . api . nvim_buf_set_extmark ( buf , ns2 , 0 , 10 , { hl_group ='Normal' , end_col =11 } ) 29vim . cmd ( 'syntax on' ) 30return buf , ns1 , ns2 31end ) 32 33eq ( '' , eval ( 'v:errmsg' )) 34-- Only visible highlights with `filter.extmarks == true` 35eq ( { 36buffer =buf , 37col =10 , 38row =0 , 39extmarks ={ 40{ 41col =10 , 42end_col =11 , 43end_row =0 , 44id =1 , 45ns ='' , 46ns_id =ns2 , 47opts ={ 48end_row =0 , 49end_col =11 , 50hl_eol =false , 51hl_group ='Normal' , 52hl_group_link ='Normal' , 53ns_id =ns2 , 54priority =4096 , 55right_gravity =true , 56end_right_gravity =false , 57} , 58row =0 , 59} , 60} , 61treesitter ={} , 62semantic_tokens ={} , 63syntax ={ { hl_group ='luaNumber' , hl_group_link ='Constant' } } , 64} , exec_lua ( 'return vim.inspect_pos(0, 0, 10)' )) 65-- All extmarks with `filters.extmarks == 'all'` 66eq ( { 67buffer =buf , 68col =10 , 69row =0 , 70extmarks ={ 71{ 72col =10 , 73end_col =10 , 74end_row =0 , 75id =1 , 76ns ='ns1' , 77ns_id =ns1 , 78opts ={ 79hl_eol =false , 80hl_group ='Normal' , 81hl_group_link ='Normal' , 82ns_id =ns1 , 83priority =4096 , 84right_gravity =true , 85} , 86row =0 , 87} , 88{ 89col =10 , 90end_col =11 , 91end_row =0 , 92id =1 , 93ns ='' , 94ns_id =ns2 , 95opts ={ 96end_row =0 , 97end_col =11 , 98hl_eol =false , 99hl_group ='Normal' , 100hl_group_link ='Normal' , 101ns_id =ns2 , 102priority =4096 , 103right_gravity =true , 104end_right_gravity =false , 105} , 106row =0 , 107} , 108{ 109col =10 , 110end_col =10 , 111end_row =0 , 112id =2 , 113ns ='ns1' , 114ns_id =ns1 , 115opts ={ 116end_row =0 , 117end_col =10 , 118hl_eol =false , 119hl_group ='Normal' , 120hl_group_link ='Normal' , 121ns_id =ns1 , 122priority =4096 , 123right_gravity =true , 124end_right_gravity =false , 125} , 126row =0 , 127} , 128} , 129treesitter ={} , 130semantic_tokens ={} , 131syntax ={ { hl_group ='luaNumber' , hl_group_link ='Constant' } } , 132} , exec_lua ( 'return vim.inspect_pos(0, 0, 10, { extmarks = "all" })' )) 133-- Syntax from other buffer. 134eq ( { 135{ hl_group ='luaComment' , hl_group_link ='Comment' } , 136} , exec_lua ( 'return vim.inspect_pos(_G.buf1, 0, 10).syntax' )) 137end ) 138end ) 139 140describe ( 'vim.show_pos' , function () 141before_each ( function () 142clear () 143end ) 144 145it ( 'it does not error' , function () 146exec_lua ( function () 147local buf =vim . api . nvim_create_buf ( true , false ) 148vim . api . nvim_set_current_buf ( buf ) 149vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , { 'local a = 123' } ) 150vim . bo [ buf ]. filetype ='lua' 151vim . cmd ( 'syntax on' ) 152return { buf , vim . show_pos ( 0 , 0 , 10 ) } 153end ) 154eq ( '' , eval ( 'v:errmsg' )) 155end ) 156end )