diff options
author | Amaan Qureshi <amaanq12@gmail.com> | 2023-08-22 00:51:38 -0400 |
---|---|---|
committer | Christian Clason <c.clason@uni-graz.at> | 2023-08-24 09:05:44 +0900 |
commit | c6ec7fa8d741d6301701067ecd095bf02e7a741a (patch) | |
tree | af5ef153b6f27bf67e70d2ed74a55eccf85071f2 /test/functional/treesitter/parser_spec.lua | |
parent | 466c18b8185c44f4fbf67ae91a2ffe27c1919306 (diff) | |
download | rneovim-c6ec7fa8d741d6301701067ecd095bf02e7a741a.tar.gz rneovim-c6ec7fa8d741d6301701067ecd095bf02e7a741a.tar.bz2 rneovim-c6ec7fa8d741d6301701067ecd095bf02e7a741a.zip |
feat(treesitter): add 'injection.self' and 'injection.parent'
Co-authored-by: ObserverOfTime <chronobserver@disroot.org>
Diffstat (limited to 'test/functional/treesitter/parser_spec.lua')
-rw-r--r-- | test/functional/treesitter/parser_spec.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua index ae7cf58293..56af0c8738 100644 --- a/test/functional/treesitter/parser_spec.lua +++ b/test/functional/treesitter/parser_spec.lua @@ -696,6 +696,39 @@ int x = INT_MAX; end) end) + describe("when using injection.self", function() + it("should inject the source language", function() + exec_lua([[ + parser = vim.treesitter.get_parser(0, "c", { + injections = { + c = '(preproc_def (preproc_arg) @injection.content (#set! injection.self)) (preproc_function_def value: (preproc_arg) @injection.content (#set! injection.self))'}}) + parser:parse(true) + ]]) + + eq("table", exec_lua("return type(parser:children().c)")) + eq(5, exec_lua("return #parser:children().c:trees()")) + eq({ + {0, 0, 7, 0}, -- root tree + {3, 14, 3, 17}, -- VALUE 123 + {4, 15, 4, 18}, -- VALUE1 123 + {5, 15, 5, 18}, -- VALUE2 123 + {1, 26, 1, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) + {2, 29, 2, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) + }, get_ranges()) + + helpers.feed('ggo<esc>') + eq(5, exec_lua("return #parser:children().c:trees()")) + eq({ + {0, 0, 8, 0}, -- root tree + {4, 14, 4, 17}, -- VALUE 123 + {5, 15, 5, 18}, -- VALUE1 123 + {6, 15, 6, 18}, -- VALUE2 123 + {2, 26, 2, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) + {3, 29, 3, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) + }, get_ranges()) + end) + end) + describe("when using the offset directive", function() it("should shift the range by the directive amount", function() exec_lua([[ |