Skip to content

Commit 95fb795

Browse files
authored
Little improvements to #749 (#771)
* fix: add realpath annotation * refactor: test helper --------- Co-authored-by: Sebastian Flügge <[email protected]>
1 parent 47c3d92 commit 95fb795

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

lua/orgmode/org/hyperlinks/url.lua

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local fs = require('orgmode.utils.fs')
77
---@field protocol string
88
---@field path string
99
---@field path_type OrgUrlPathType
10+
---@field realpath string
1011
---@field target { type: OrgUrlTargetType, value: string | number | nil }
1112
local Url = {}
1213
Url.__index = Url

tests/plenary/helpers.lua

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,31 @@ local function create_file_instance(lines, filename)
3535
return file
3636
end
3737

38+
---@param fixtures {filename: string, content: string[] }[]
39+
---@param config table?
3840
---@return table
39-
local function create_agenda_files(filenames, contents)
41+
local function create_agenda_files(fixtures, config)
4042
-- NOTE: content is only 1 line for 1 file
4143
local temp_fname = vim.fn.tempname()
4244
local temp_dir = vim.fn.fnamemodify(temp_fname, ':p:h')
4345
-- clear temp dir
4446
vim.fn.delete(temp_dir .. '/*', 'rf')
4547
local files = {}
4648
local agenda_files = {}
47-
for i, filename in ipairs(filenames) do
48-
local fname = temp_dir .. '/' .. filename
49+
for _, fixture in pairs(fixtures) do
50+
local fname = temp_dir .. '/' .. fixture.filename
4951
fname = vim.fn.fnamemodify(fname, ':p')
5052
if fname then
5153
local dir = vim.fn.fnamemodify(fname, ':p:h')
5254
vim.fn.mkdir(dir, 'p')
53-
vim.fn.writefile({ contents[i] }, fname)
54-
files[filename] = fname
55+
vim.fn.writefile(fixture.content, fname)
56+
files[fixture.filename] = fname
5557
table.insert(agenda_files, fname)
5658
end
5759
end
5860
local cfg = vim.tbl_extend('force', {
5961
org_agenda_files = agenda_files,
60-
}, {})
62+
}, config or {})
6163
local org = orgmode.setup(cfg)
6264
org:init()
6365
return files

tests/plenary/org/autocompletion_spec.lua

+19-12
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,16 @@ describe('Autocompletion', function()
340340
}, result)
341341
end)
342342

343-
it('should work on relative paths', function()
343+
it('should work on relative paths targeting parent directory', function()
344344
local files = helpers.create_agenda_files({
345-
'a.org',
346-
'b/c.org',
347-
}, {
348-
'[[./ ',
349-
'[[../ ',
345+
{
346+
filename = 'a.org',
347+
content = { '' },
348+
},
349+
{
350+
filename = 'b/c.org',
351+
content = { '[[../' },
352+
},
350353
})
351354
helpers.load_file(files['b/c.org'])
352355
vim.fn.cursor({ 1, 6 })
@@ -356,13 +359,17 @@ describe('Autocompletion', function()
356359
{ menu = '[Org]', word = '../b/c.org' },
357360
}, org.completion:omnifunc(0, '../'))
358361
end)
359-
it('should work on relative paths', function()
362+
363+
it('should work on relative paths targeting current directory', function()
360364
local files = helpers.create_agenda_files({
361-
'a.org',
362-
'b/c.org',
363-
}, {
364-
'[[./ ',
365-
'[[../ ',
365+
{
366+
filename = 'a.org',
367+
content = { '[[./' },
368+
},
369+
{
370+
filename = 'b/c.org',
371+
content = { '' },
372+
},
366373
})
367374
helpers.load_file(files['a.org'])
368375
vim.fn.cursor({ 1, 5 })

0 commit comments

Comments
 (0)