Skip to content

Commit a5b1f73

Browse files
author
fanyunqian
committed
test: around relative paths
1 parent ced3831 commit a5b1f73

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/plenary/helpers.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,34 @@ local function create_file_instance(lines, filename)
3535
return file
3636
end
3737

38+
---@return table
39+
local function create_agenda_files(filenames, contents)
40+
-- NOTE: content is only 1 line for 1 file
41+
local temp_fname = vim.fn.tempname()
42+
local temp_dir = vim.fn.fnamemodify(temp_fname, ':p:h')
43+
local files = {}
44+
for i, filename in ipairs(filenames) do
45+
local fname = temp_dir .. '/' .. filename
46+
fname = vim.fn.fnamemodify(fname, ':p')
47+
if fname then
48+
local dir = vim.fn.fnamemodify(fname, ':p:h')
49+
vim.fn.mkdir(dir, 'p')
50+
vim.fn.writefile({ contents[i] }, fname)
51+
files[filename] = fname
52+
end
53+
end
54+
local cfg = vim.tbl_extend('force', {
55+
org_agenda_files = { temp_dir .. '/**/*' },
56+
}, {})
57+
local org = orgmode.setup(cfg)
58+
org:init()
59+
return files
60+
end
61+
3862
return {
63+
load_file = load_file,
3964
create_file = create_file,
4065
create_file_instance = create_file_instance,
4166
create_agenda_file = create_agenda_file,
67+
create_agenda_files = create_agenda_files,
4268
}

tests/plenary/org/autocompletion_spec.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,31 @@ describe('Autocompletion', function()
339339
{ menu = '[Org]', word = 'Title without anchor' },
340340
}, result)
341341
end)
342+
343+
it('should work on relative paths', function()
344+
local files = helpers.create_agenda_files({
345+
'a.org',
346+
'b/c.org',
347+
}, {
348+
'[[./ ',
349+
'[[../ ',
350+
})
351+
helpers.load_file(files['a.org'])
352+
vim.fn.cursor({ 1, 5 })
353+
354+
assert.are.same({
355+
{ menu = '[Org]', word = './a.org' },
356+
{ menu = '[Org]', word = './b/c.org' },
357+
}, org.completion:omnifunc(0, './'))
358+
359+
helpers.load_file(files['b/c.org'])
360+
vim.fn.cursor({ 1, 6 })
361+
362+
assert.are.same({
363+
{ menu = '[Org]', word = '../a.org' },
364+
{ menu = '[Org]', word = '../b/c.org' },
365+
}, org.completion:omnifunc(0, '../'))
366+
end)
342367
end)
343368
end)
344369
end)

0 commit comments

Comments
 (0)