aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/treesitter/query_spec.lua78
-rw-r--r--test/functional/ui/messages_spec.lua27
-rw-r--r--test/old/testdir/test_filetype.vim2
-rw-r--r--test/old/testdir/test_perl.vim1
-rw-r--r--test/old/testdir/test_winfixbuf.vim24
5 files changed, 115 insertions, 17 deletions
diff --git a/test/functional/treesitter/query_spec.lua b/test/functional/treesitter/query_spec.lua
index fb3eaa1518..170f448f97 100644
--- a/test/functional/treesitter/query_spec.lua
+++ b/test/functional/treesitter/query_spec.lua
@@ -696,4 +696,82 @@ void ui_refresh(void)
'((identifier) @id \n(#eq? @id\n@ok.capture\n))'
)
end)
+
+ describe('Query:iter_captures', function()
+ it('includes metadata for all captured nodes #23664', function()
+ insert([[
+ const char *sql = "SELECT * FROM Students WHERE name = 'Robert'); DROP TABLE Students;--";
+ ]])
+
+ local query = [[
+ (declaration
+ type: (_)
+ declarator: (init_declarator
+ declarator: (pointer_declarator
+ declarator: (identifier)) @_id
+ value: (string_literal
+ (string_content) @injection.content))
+ (#set! injection.language "sql")
+ (#contains? @_id "sql"))
+ ]]
+
+ local result = exec_lua(
+ [=[
+ local query = vim.treesitter.query.parse("c", ...)
+ local parser = vim.treesitter.get_parser(0, "c")
+ local root = parser:parse()[1]:root()
+ local t = {}
+ for id, node, metadata in query:iter_captures(root, 0) do
+ t[query.captures[id]] = metadata
+ end
+ return t
+ ]=],
+ query
+ )
+
+ eq({
+ ['_id'] = { ['injection.language'] = 'sql' },
+ ['injection.content'] = { ['injection.language'] = 'sql' },
+ }, result)
+ end)
+
+ it('only evaluates predicates once per match', function()
+ insert([[
+ void foo(int x, int y);
+ ]])
+ local query = [[
+ (declaration
+ type: (_)
+ declarator: (function_declarator
+ declarator: (identifier) @function.name
+ parameters: (parameter_list
+ (parameter_declaration
+ type: (_)
+ declarator: (identifier) @argument)))
+ (#eq? @function.name "foo"))
+ ]]
+
+ local result = exec_lua(
+ [[
+ local query = vim.treesitter.query.parse("c", ...)
+ local match_preds = query.match_preds
+ local called = 0
+ function query:match_preds(...)
+ called = called + 1
+ return match_preds(self, ...)
+ end
+ local parser = vim.treesitter.get_parser(0, "c")
+ local root = parser:parse()[1]:root()
+ local captures = {}
+ for id, node in query:iter_captures(root, 0) do
+ captures[#captures + 1] = id
+ end
+ return { called, captures }
+ ]],
+ query
+ )
+
+ eq({ 2, { 1, 1, 2, 2 } }, result)
+ end)
+ end)
end)
diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua
index d8f8c8c50a..fb02af46b5 100644
--- a/test/functional/ui/messages_spec.lua
+++ b/test/functional/ui/messages_spec.lua
@@ -1604,13 +1604,14 @@ describe('ui/ext_messages', function()
[5] = { foreground = Screen.colors.Blue1 },
[6] = { reverse = true },
[7] = { bold = true, reverse = true },
+ [8] = { background = Screen.colors.Plum1 },
})
end)
it('supports intro screen', function()
-- intro message is not externalized. But check that it still works.
-- Note parts of it depends on version or is indeterministic. We ignore those parts.
- screen:expect([[
+ local introscreen = [[
^ |
{1:~ }|*4
{MATCH:.*}|
@@ -1628,14 +1629,27 @@ describe('ui/ext_messages', function()
{1:~ }Help poor children in Uganda!{1: }|
{1:~ }type :help iccf{5:<Enter>} for information {1: }|
{1:~ }|*5
- ]])
+ ]]
+ screen:expect(introscreen)
-- <c-l> (same as :mode) does _not_ clear intro message
feed('<c-l>i')
+ screen:expect { grid = introscreen, showmode = { { '-- INSERT --', 3 } } }
+
+ -- opening a float also does not
+ local win = api.nvim_open_win(api.nvim_create_buf(false, false), true, {
+ relative = 'editor',
+ height = 1,
+ width = 5,
+ row = 1,
+ col = 5,
+ })
+ feed('float<esc><c-l>')
screen:expect {
grid = [[
- ^ |
- {1:~ }|*4
+ |
+ {1:~ }{8:floa^t}{1: }|
+ {1:~ }|*3
{MATCH:.*}|
{1:~ }|
{1:~ }Nvim is open source and freely distributable{1: }|
@@ -1652,11 +1666,12 @@ describe('ui/ext_messages', function()
{1:~ }type :help iccf{5:<Enter>} for information {1: }|
{1:~ }|*5
]],
- showmode = { { '-- INSERT --', 3 } },
}
+ api.nvim_win_close(win, true)
+ screen:expect { grid = introscreen }
-- but editing text does..
- feed('x')
+ feed('ix')
screen:expect {
grid = [[
x^ |
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
index fc859cf3eb..c5e0d6808f 100644
--- a/test/old/testdir/test_filetype.vim
+++ b/test/old/testdir/test_filetype.vim
@@ -273,7 +273,7 @@ func s:GetFilenameChecks() abort
\ 'glsl': ['file.glsl'],
\ 'gn': ['file.gn', 'file.gni'],
\ 'gnash': ['gnashrc', '.gnashrc', 'gnashpluginrc', '.gnashpluginrc'],
- \ 'gnuplot': ['file.gpi', '.gnuplot'],
+ \ 'gnuplot': ['file.gpi', '.gnuplot', 'file.gnuplot'],
\ 'go': ['file.go'],
\ 'gomod': ['go.mod'],
\ 'gosum': ['go.sum', 'go.work.sum'],
diff --git a/test/old/testdir/test_perl.vim b/test/old/testdir/test_perl.vim
index ce2a566f62..37b1d08b1a 100644
--- a/test/old/testdir/test_perl.vim
+++ b/test/old/testdir/test_perl.vim
@@ -104,6 +104,7 @@ func Test_window_Cursor()
endfunc
func Test_window_SetHeight()
+ throw 'skipped: very flaky '
new
perl $curwin->SetHeight(2)
call assert_equal(2, winheight(0))
diff --git a/test/old/testdir/test_winfixbuf.vim b/test/old/testdir/test_winfixbuf.vim
index d5e43cf33e..3fcc5fa5eb 100644
--- a/test/old/testdir/test_winfixbuf.vim
+++ b/test/old/testdir/test_winfixbuf.vim
@@ -1239,30 +1239,34 @@ endfunc
func Test_edit_same_buffer_in_memory()
call s:reset_all_buffers()
- let l:current = bufnr()
+ let current = bufnr()
file same_buffer
- call assert_equal(l:current, bufnr())
+ call assert_equal(current, bufnr())
set winfixbuf
edit same_buffer
- call assert_equal(l:current, bufnr())
+ call assert_equal(current, bufnr())
+ set nowinfixbuf
endfunc
" Allow :e selecting the current buffer as a full path
func Test_edit_same_buffer_on_disk_absolute_path()
+ " This fails on CI (Windows builds), why?
+ " CheckNotMSWindows
call s:reset_all_buffers()
- let l:file = tempname()
- let l:current = bufnr()
- execute "edit " . l:file
+ let file = tempname()
+ let current = bufnr()
+ execute "edit " . file
write!
- call assert_equal(l:current, bufnr())
+ call assert_equal(current, bufnr())
set winfixbuf
- execute "edit " l:file
- call assert_equal(l:current, bufnr())
+ execute "edit " file
+ call assert_equal(current, bufnr())
- call delete(l:file)
+ call delete(file)
+ set nowinfixbuf
endfunc
" Fail :enew but :enew! is allowed