diff options
author | Stephan Seitz <stephan.seitz@fau.de> | 2020-08-30 21:53:16 +0200 |
---|---|---|
committer | Stephan Seitz <stephan.seitz@fau.de> | 2020-08-31 17:24:38 +0200 |
commit | b058c671d2fb34b53d7499d77e7eb9624e1508a9 (patch) | |
tree | f5a2a1b97ee5aada5fd2fa753c0cc5c423df3a52 /test/functional/lua/treesitter_spec.lua | |
parent | 2bbbb34ce78ee30c1ee53a9cb3fd1e7608185716 (diff) | |
download | rneovim-b058c671d2fb34b53d7499d77e7eb9624e1508a9.tar.gz rneovim-b058c671d2fb34b53d7499d77e7eb9624e1508a9.tar.bz2 rneovim-b058c671d2fb34b53d7499d77e7eb9624e1508a9.zip |
treesitter: avoid escaping complete query strings
Escape "\\" only for `vim-match?` not for `match?`
Fixes #12595
Diffstat (limited to 'test/functional/lua/treesitter_spec.lua')
-rw-r--r-- | test/functional/lua/treesitter_spec.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua index b0ac9e079a..5706272f38 100644 --- a/test/functional/lua/treesitter_spec.lua +++ b/test/functional/lua/treesitter_spec.lua @@ -198,6 +198,35 @@ void ui_refresh(void) }, res) end) + it('allow loading query with escaped quotes and capture them with `match?` and `vim-match?`', function() + if not check_parser() then return end + + insert('char* astring = "Hello World!";') + + local res = exec_lua([[ + cquery = vim.treesitter.parse_query("c", '((_) @quote (vim-match? @quote "^\\"$")) ((_) @quote (match? @quote "^\\"$"))') + parser = vim.treesitter.get_parser(0, "c") + tree = parser:parse() + res = {} + for pattern, match in cquery:iter_matches(tree:root(), 0, 0, 1) do + -- can't transmit node over RPC. just check the name and range + local mrepr = {} + for cid,node in pairs(match) do + table.insert(mrepr, {cquery.captures[cid], node:type(), node:range()}) + end + table.insert(res, {pattern, mrepr}) + end + return res + ]]) + + eq({ + { 1, { { "quote", '"', 0, 16, 0, 17 } } }, + { 2, { { "quote", '"', 0, 16, 0, 17 } } }, + { 1, { { "quote", '"', 0, 29, 0, 30 } } }, + { 2, { { "quote", '"', 0, 29, 0, 30 } } }, + }, res) + end) + it('allows to add predicates', function() insert([[ int main(void) { |