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 command =n . command 6local eq =t . eq 7local exec_capture =n . exec_capture 8local exec_lua =n . exec_lua 9local feed =n . feed 10local fn =n . fn 11local matches =t . matches 12 13describe ( ':marks' , function () 14before_each ( function () 15n . clear {} 16fn . setline ( 1 , { 'one' , 'two' , 'three' } ) 17feed ( 'ma' ) 18exec_lua ( function () 19local ns =vim . api . nvim_create_namespace ( 'my.plugin' ) 20vim . api . nvim_buf_set_extmark ( 0 , ns , 1 , 0 , {} ) 21vim . api . nvim_buf_set_extmark ( 0 , ns , 2 , 1 , {} ) 22vim . api . nvim_create_namespace ( 'empty.ns' ) -- no extmarks: not completed, not mentioned 23end ) 24end ) 25 26it ( 'completes names, lists extmarks' , function () 27-- Completion offers the set marks and the buffer's extmark namespaces. 28eq ( { '"' , "'" , '.' , 'a' , 'my.plugin' } , fn . getcompletion ( 'marks ' , 'cmdline' )) 29-- :marks (no args) only mentions the namespaces instead of listing their extmarks. 30local out =exec_capture ( 'marks' ) 31matches ( 'mark line col file/text' , out ) 32matches ( 'Extmark namespaces %(use ":marks {ns}"%): my%.plugin' , out ) 33eq ( nil , out : find ( 'empty%.ns' )) 34-- ":marks {ns}" lists that namespace's extmarks. 35out =exec_capture ( 'marks my.plugin' ) 36matches ( 'id%s+line%s+col text' , out ) 37matches ( '1%s+2%s+0 two' , out ) 38matches ( '2%s+3%s+1 three' , out ) 39-- Not a namespace: the usual mark-names filter. 40matches ( 'mark line col file/text' , exec_capture ( 'marks aB' )) 41end ) 42 43it ( ':filter on file/text column; E283; "No marks set"' , function () 44fn . setpos ( "'b" , { 0 , 2 , 1 , 0 } ) 45local out =exec_capture ( 'filter /two/ marks' ) 46matches ( ' b%s+2%s+0 two' , out ) 47eq ( nil , out : find ( ' a ' , 1 , true )) -- mark a is on "one": filtered out 48matches ( 'E283: No marks matching "z"' , t . pcall_err ( command , 'marks z' )) 49-- Bare :marks with every row filtered out. 50matches ( 'No marks set' , exec_capture ( 'filter /xxx-nomatch/ marks' )) 51end ) 52 53it ( "prompt buffer: ':' mark in getmarklist() and :marks" , function () 54command ( 'enew | set buftype=prompt' ) 55feed ( 'ifoo<Esc>' ) 56local found =false 57for _ , m in ipairs ( fn . getmarklist ( fn . bufnr ( '' ))) do 58found =found or m . mark == "':" 59end 60eq ( true , found ) 61matches ( ' :%s+%d+%s+%d+ ' , exec_capture ( 'marks' )) 62end ) 63end )