Skip to content
Open
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
2 changes: 1 addition & 1 deletion lua/urlview/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
function M.netrw(raw_url)
local url = vim.fn.shellescape(raw_url)
local ok, err = pcall(vim.cmd, string.format("call netrw#BrowseX(%s, netrw#CheckIfRemote(%s))", url, url))
if not ok and vim.startswith(err, "Vim(call):E117: Unknown function") then
if not ok and string.find(err, "Vim(call):E117: Unknown function", 1, true) then
-- lazily use system action if netrw is disabled
M.system(raw_url)
end
Expand Down
26 changes: 26 additions & 0 deletions tests/urlview/netrw_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local urlview = require("urlview")
local actions = require("urlview.actions")
local stub = require("luassert.stub")
local netrw_action = require("urlview.actions").netrw

describe("M.netrw fallback when netrw is disabled", function()
before_each(function()
-- disable netrw
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd("enew")
vim.api.nvim_buf_set_lines(0, 0, -1, false, {
"Here is a link: https://example.com",
})
urlview.setup({})
end)

it("calls the system fallback", function()
stub(actions, "system")

netrw_action("https://example.com")

assert.stub(actions.system).was.called_with("https://example.com")
end)
end)