robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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