robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Test filename modifiers. 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5 6local describe , it , before_each =t . describe , t . it , t . before_each 7local clear , source =n . clear , n . source 8local call , eq , api =n . call , t . eq , n . api 9 10local function expected_empty () 11eq ( {} , api . nvim_get_vvar ( 'errors' )) 12end 13 14describe ( 'filename modifiers' , function () 15before_each ( function () 16clear () 17 18source ( [=[ 19func Test_fnamemodify() 20if has('win32') 21set shellslash 22else 23set shell=sh 24endif 25let tmpdir = resolve($TMPDIR) 26call assert_true(isdirectory(tmpdir)) 27execute 'cd '. tmpdir 28let $HOME=fnamemodify('.', ':p:h:h:h') 29call assert_equal('/', fnamemodify('.', ':p')[-1:]) 30call assert_equal(tmpdir[strchars(tmpdir) - 1], fnamemodify('.', ':p:h')[-1:]) 31call assert_equal('t', fnamemodify('test.out', ':p')[-1:]) 32call assert_equal('test.out', fnamemodify('test.out', ':.')) 33call assert_equal('../testdir/a', fnamemodify('../testdir/a', ':.')) 34call assert_equal(fnamemodify(tmpdir, ':~').'/test.out', fnamemodify('test.out', ':~')) 35call assert_equal(fnamemodify(tmpdir, ':~').'/../testdir/a', fnamemodify('../testdir/a', ':~')) 36call assert_equal('a', fnamemodify('../testdir/a', ':t')) 37call assert_equal('', fnamemodify('.', ':p:t')) 38call assert_equal('test.out', fnamemodify('test.out', ':p:t')) 39call assert_equal('out', fnamemodify('test.out', ':p:e')) 40call assert_equal('out', fnamemodify('test.out', ':p:t:e')) 41call assert_equal('abc.fb2.tar', fnamemodify('abc.fb2.tar.gz', ':r')) 42call assert_equal('abc.fb2', fnamemodify('abc.fb2.tar.gz', ':r:r')) 43call assert_equal('abc', fnamemodify('abc.fb2.tar.gz', ':r:r:r')) 44call assert_equal(tmpdir .'/abc.fb2', substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(nvim/testdir/.*\)', '\1', '')) 45call assert_equal('gz', fnamemodify('abc.fb2.tar.gz', ':e')) 46call assert_equal('tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e')) 47call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e')) 48call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e:e')) 49call assert_equal('tar', fnamemodify('abc.fb2.tar.gz', ':e:e:r')) 50call assert_equal('''abc def''', fnamemodify('abc def', ':S')) 51call assert_equal('''abc" "def''', fnamemodify('abc" "def', ':S')) 52call assert_equal('''abc"%"def''', fnamemodify('abc"%"def', ':S')) 53call assert_equal('''abc''\'''' ''\''''def''', fnamemodify('abc'' ''def', ':S')) 54call assert_equal('''abc''\''''%''\''''def''', fnamemodify('abc''%''def', ':S')) 55new foo.txt 56call assert_equal(expand('%:r:S'), shellescape(expand('%:r'))) 57call assert_equal('foo,''foo'',foo.txt', join([expand('%:r'), expand('%:r:S'), expand('%')], ',')) 58quit 59 60call assert_equal("'abc\ndef'", fnamemodify("abc\ndef", ':S')) 61if executable('tcsh') 62set shell=tcsh 63call assert_equal("'abc\\\ndef'", fnamemodify("abc\ndef", ':S')) 64endif 65endfunc 66]=] ) 67end ) 68 69it ( 'is working' , function () 70call ( 'Test_fnamemodify' ) 71expected_empty () 72end ) 73end )