Skip to content

Little improvements to #749 #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading