mirror of
https://github.com/neovim/neovim.git
synced 2025-12-12 09:32:39 +00:00
Problem: When running ":edit <url>", filetype detection is not triggered. Solution: Run the autocmds in the filetypedetect group after loading the content. Problem: After fetching remote content from a URL and adding it to the buffer, the buffer is marked as modified. This is inconsistent with the original netrw behavior, and it causes problems with `:e` to refresh or `:q` as it prompts for saving the file even if the user hasn't touched the content at all. Solution: Mark the buffer as unmodified right after adding the remote content to the buffer.
92 lines
2.8 KiB
Lua
92 lines
2.8 KiB
Lua
local n = require('test.functional.testnvim')()
|
|
local t = require('test.testutil')
|
|
local skip_integ = os.getenv('NVIM_TEST_INTEG') ~= '1'
|
|
|
|
local exec_lua = n.exec_lua
|
|
|
|
local function assert_404_error(err)
|
|
assert(
|
|
err:lower():find('404') or err:find('22'),
|
|
'Expected HTTP 404 or exit code 22, got: ' .. tostring(err)
|
|
)
|
|
end
|
|
|
|
describe('vim.net.request', function()
|
|
before_each(function()
|
|
n:clear()
|
|
end)
|
|
|
|
it('fetches a URL into memory (async success)', function()
|
|
t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test')
|
|
local content = exec_lua([[
|
|
local done = false
|
|
local result
|
|
local M = require('vim.net')
|
|
|
|
M.request("https://httpbingo.org/anything", { retry = 3 }, function(err, body)
|
|
assert(not err, err)
|
|
result = body.body
|
|
done = true
|
|
end)
|
|
|
|
vim.wait(2000, function() return done end)
|
|
return result
|
|
]])
|
|
|
|
assert(
|
|
content and content:find('"url"%s*:%s*"https://httpbingo.org/anything"'),
|
|
'Expected response body to contain the correct URL'
|
|
)
|
|
end)
|
|
|
|
it('detects filetype for remote content', function()
|
|
t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test')
|
|
|
|
local ft = exec_lua([[
|
|
vim.cmd('runtime! plugin/nvim/net.lua')
|
|
vim.cmd('runtime! filetype.lua')
|
|
-- github raw dump of a small lua file in the neovim repo
|
|
vim.cmd('edit https://raw.githubusercontent.com/neovim/neovim/master/runtime/syntax/tutor.lua')
|
|
vim.wait(2000, function() return vim.bo.filetype ~= '' end)
|
|
return vim.bo.filetype
|
|
]])
|
|
|
|
assert(ft == 'lua', 'Expected filetype to be "lua", got: ' .. tostring(ft))
|
|
end)
|
|
|
|
it('removes the modified flag from the buffer for remote content', function()
|
|
t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test')
|
|
|
|
local buffer_modified = exec_lua([[
|
|
vim.cmd('runtime! plugin/nvim/net.lua')
|
|
vim.cmd('runtime! filetype.lua')
|
|
vim.cmd('edit https://raw.githubusercontent.com/neovim/neovim/master/runtime/syntax/tutor.lua')
|
|
-- wait for buffer to have content
|
|
vim.wait(2000, function() return vim.fn.wordcount().bytes > 0 end)
|
|
vim.wait(2000, function() return vim.bo.modified == false end)
|
|
return vim.bo.modified
|
|
]])
|
|
|
|
assert(not buffer_modified, 'Expected buffer to be unmodified for remote content')
|
|
end)
|
|
|
|
it('calls on_response with error on 404 (async failure)', function()
|
|
t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test')
|
|
local err = exec_lua([[
|
|
local done = false
|
|
local result
|
|
local M = require('vim.net')
|
|
|
|
M.request("https://httpbingo.org/status/404", {}, function(e, _)
|
|
result = e
|
|
done = true
|
|
end)
|
|
|
|
vim.wait(2000, function() return done end)
|
|
return result
|
|
]])
|
|
|
|
assert_404_error(err)
|
|
end)
|
|
end)
|