diff options
author | Thomas Vigouroux <tomvig38@gmail.com> | 2020-09-30 15:32:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-30 09:32:43 -0400 |
commit | 3c5141d2cf359d9ac70799bb987482d753263782 (patch) | |
tree | 03fddee132f8d2e76e21a2582989d19048481c46 /test/functional/lua/treesitter_spec.lua | |
parent | d5adc8c00e07b12403c99b7d3fbd6e20a51fa1e4 (diff) | |
download | rneovim-3c5141d2cf359d9ac70799bb987482d753263782.tar.gz rneovim-3c5141d2cf359d9ac70799bb987482d753263782.tar.bz2 rneovim-3c5141d2cf359d9ac70799bb987482d753263782.zip |
treesitter: add string parser (#13008)
Diffstat (limited to 'test/functional/lua/treesitter_spec.lua')
-rw-r--r-- | test/functional/lua/treesitter_spec.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua index 128545b472..74ae6cde2b 100644 --- a/test/functional/lua/treesitter_spec.lua +++ b/test/functional/lua/treesitter_spec.lua @@ -660,4 +660,35 @@ static int nlua_schedule(lua_State *const lstate) { 10, 5, 10, 20 }, { 14, 9, 14, 27 } }, res) end) + + it("allows to create string parsers", function() + local ret = exec_lua [[ + local parser = vim.treesitter.get_string_parser("int foo = 42;", "c") + return { parser:parse():root():range() } + ]] + + eq({ 0, 0, 0, 13 }, ret) + end) + + it("allows to run queries with string parsers", function() + local txt = [[ + int foo = 42; + int bar = 13; + ]] + + local ret = exec_lua([[ + local str = ... + local parser = vim.treesitter.get_string_parser(str, "c") + + local nodes = {} + local query = vim.treesitter.parse_query("c", '((identifier) @id (eq? @id "foo"))') + + for _, node in query:iter_captures(parser:parse():root(), str, 0, 2) do + table.insert(nodes, { node:range() }) + end + + return nodes]], txt) + + eq({ {0, 10, 0, 13} }, ret) + end) end) |