forked from nvimdev/guard.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsp_spec.lua
More file actions
68 lines (59 loc) · 1.56 KB
/
lsp_spec.lua
File metadata and controls
68 lines (59 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---@diagnostic disable: undefined-field, undefined-global
require('plugin.guard')
local api = vim.api
local same = assert.are.same
local ft = require('guard.filetype')
local gapi = require('guard.api')
describe('format module', function()
local bufnr
local ill_c = {
'int main( void ) {return 0;}',
}
before_each(function()
for k, _ in pairs(ft) do
ft[k] = nil
end
vim.g.guard_config = {
lsp_as_default_formatter = true,
}
vim.lsp.config('clangd', {
cmd = { 'clangd' },
filetypes = { 'c' },
capabilities = {
textDocument = {
formatting = {
dynamicRegistration = true,
},
},
},
})
vim.lsp.enable('clangd')
bufnr = api.nvim_create_buf(true, false)
vim.bo[bufnr].filetype = 'c'
api.nvim_set_current_buf(bufnr)
vim.cmd('silent! write! /tmp/lsp_spec_test.c')
end)
after_each(function()
vim.lsp.enable('clangd', false)
end)
local function getlines()
return api.nvim_buf_get_lines(bufnr, 0, -1, false)
end
local function setlines(lines)
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
end
it('lsp default formatter works', function()
setlines(ill_c)
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
same(args.buf, bufnr)
same(args.file, '/tmp/lsp_spec_test.c')
same(args.match, '/tmp/lsp_spec_test.c')
gapi.fmt(bufnr)
vim.wait(500)
same({ 'int main(void) { return 0; }' }, getlines())
end,
})
vim.wait(1500)
end)
end)