aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/treesitter_spec.lua
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2020-09-01 12:50:21 +0200
committerGitHub <noreply@github.com>2020-09-01 12:50:21 +0200
commit4bcf54478ad4ce47908f2eb912b6d98d81e6a78d (patch)
treeefc995d071956130e9ac2c89cddc57b86cf2d760 /test/functional/lua/treesitter_spec.lua
parent04ab26b88591ce5afa427c9a8badb9fcf1b95685 (diff)
parentb058c671d2fb34b53d7499d77e7eb9624e1508a9 (diff)
downloadrneovim-4bcf54478ad4ce47908f2eb912b6d98d81e6a78d.tar.gz
rneovim-4bcf54478ad4ce47908f2eb912b6d98d81e6a78d.tar.bz2
rneovim-4bcf54478ad4ce47908f2eb912b6d98d81e6a78d.zip
Merge pull request #12814 from theHamsta/escape-queries
treesitter: avoid escaping complete query strings
Diffstat (limited to 'test/functional/lua/treesitter_spec.lua')
-rw-r--r--test/functional/lua/treesitter_spec.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua
index 12b0e6ef9f..aa36e6f8f0 100644
--- a/test/functional/lua/treesitter_spec.lua
+++ b/test/functional/lua/treesitter_spec.lua
@@ -250,6 +250,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) {