aboutsummaryrefslogtreecommitdiff
path: root/test/functional/core/path_spec.lua
blob: 44e69fff7b63d2c2e395d8b1b3f11f4b1f88572e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local get_pathsep = helpers.get_pathsep
local command = helpers.command

describe("'%:p' expanding", function()
  local pathsep
  local targetdir
  local expected_path

  local function get_full_path()
    return eval('expand("%:p")')
  end

  local function join_path(...)
    return table.concat({...}, pathsep)
  end

  before_each(function()
    clear()
    pathsep = get_pathsep()
    targetdir = join_path('test', 'functional', 'fixtures')
    clear(join_path(targetdir, 'tty-test.c'))
    expected_path = get_full_path()
  end)

  it('given a relative path with current directory in the middle #7117', function()
    clear(join_path(targetdir, '.', 'tty-test.c'))
    eq(expected_path, get_full_path())
  end)

  it('given a relative path with current directory #7117', function()
    clear(join_path('.', targetdir, 'tty-test.c'))
    eq(expected_path, get_full_path())
  end)

  it('given a relative path with current directory to a file when changing directory #7117', function()
    clear(join_path('.', targetdir, 'tty-test.c'))
    command('cd test')
    eq(expected_path, get_full_path())
  end)

  it('given a relative path with directory up the tree to a file #7117', function()
    clear(join_path(targetdir, '..', 'fixtures', 'tty-test.c'))
    eq(expected_path, get_full_path())
  end)

  it('given a different starting directory and a relative path with directory up the tree #7117', function()
    command('cd test')
    command('e ' .. join_path('..', targetdir, 'tty-test.c'))
    eq(expected_path, get_full_path())
  end)

  it('given a different starting directory and a relative path with current directory and up the tree #7117', function()
    command('cd test')
    command('e ' .. join_path('.', '..', targetdir, 'tty-test.c'))
    eq(expected_path, get_full_path())
  end)
end)