Skip to content

Commit

Permalink
Little improvements to #749 (#771)
Browse files Browse the repository at this point in the history
* fix: add realpath annotation

* refactor: test helper

---------

Co-authored-by: Sebastian Flügge <seflue@users.noreply.github.com>
  • Loading branch information
seflue and seflue authored Jul 4, 2024
1 parent 47c3d92 commit 95fb795
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
1 change: 1 addition & 0 deletions lua/orgmode/org/hyperlinks/url.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local fs = require('orgmode.utils.fs')
---@field protocol string
---@field path string
---@field path_type OrgUrlPathType
---@field realpath string
---@field target { type: OrgUrlTargetType, value: string | number | nil }
local Url = {}
Url.__index = Url
Expand Down
14 changes: 8 additions & 6 deletions tests/plenary/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,31 @@ local function create_file_instance(lines, filename)
return file
end

---@param fixtures {filename: string, content: string[] }[]
---@param config table?
---@return table
local function create_agenda_files(filenames, contents)
local function create_agenda_files(fixtures, config)
-- NOTE: content is only 1 line for 1 file
local temp_fname = vim.fn.tempname()
local temp_dir = vim.fn.fnamemodify(temp_fname, ':p:h')
-- clear temp dir
vim.fn.delete(temp_dir .. '/*', 'rf')
local files = {}
local agenda_files = {}
for i, filename in ipairs(filenames) do
local fname = temp_dir .. '/' .. filename
for _, fixture in pairs(fixtures) do
local fname = temp_dir .. '/' .. fixture.filename
fname = vim.fn.fnamemodify(fname, ':p')
if fname then
local dir = vim.fn.fnamemodify(fname, ':p:h')
vim.fn.mkdir(dir, 'p')
vim.fn.writefile({ contents[i] }, fname)
files[filename] = fname
vim.fn.writefile(fixture.content, fname)
files[fixture.filename] = fname
table.insert(agenda_files, fname)
end
end
local cfg = vim.tbl_extend('force', {
org_agenda_files = agenda_files,
}, {})
}, config or {})
local org = orgmode.setup(cfg)
org:init()
return files
Expand Down
31 changes: 19 additions & 12 deletions tests/plenary/org/autocompletion_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,16 @@ describe('Autocompletion', function()
}, result)
end)

it('should work on relative paths', function()
it('should work on relative paths targeting parent directory', function()
local files = helpers.create_agenda_files({
'a.org',
'b/c.org',
}, {
'[[./ ',
'[[../ ',
{
filename = 'a.org',
content = { '' },
},
{
filename = 'b/c.org',
content = { '[[../' },
},
})
helpers.load_file(files['b/c.org'])
vim.fn.cursor({ 1, 6 })
Expand All @@ -356,13 +359,17 @@ describe('Autocompletion', function()
{ menu = '[Org]', word = '../b/c.org' },
}, org.completion:omnifunc(0, '../'))
end)
it('should work on relative paths', function()

it('should work on relative paths targeting current directory', function()
local files = helpers.create_agenda_files({
'a.org',
'b/c.org',
}, {
'[[./ ',
'[[../ ',
{
filename = 'a.org',
content = { '[[./' },
},
{
filename = 'b/c.org',
content = { '' },
},
})
helpers.load_file(files['a.org'])
vim.fn.cursor({ 1, 5 })
Expand Down

0 comments on commit 95fb795

Please sign in to comment.