diff options
Diffstat (limited to 'test/functional/treesitter/fold_spec.lua')
-rw-r--r-- | test/functional/treesitter/fold_spec.lua | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/test/functional/treesitter/fold_spec.lua b/test/functional/treesitter/fold_spec.lua index 9ed86e87f1..a8abbc002b 100644 --- a/test/functional/treesitter/fold_spec.lua +++ b/test/functional/treesitter/fold_spec.lua @@ -359,3 +359,116 @@ void ui_refresh(void) end) end) + +describe('treesitter foldtext', function() + local test_text = [[ +void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *)) +{ + int width = INT_MAX, height = INT_MAX; + bool ext_widgets[kUIExtCount]; + for (UIExtension i = 0; (int)i < kUIExtCount; i++) { + ext_widgets[i] = true; + } + + bool inclusive = ui_override(); + for (size_t i = 0; i < ui_count; i++) { + UI *ui = uis[i]; + width = MIN(ui->width, width); + height = MIN(ui->height, height); + foo = BAR(ui->bazaar, bazaar); + for (UIExtension j = 0; (int)j < kUIExtCount; j++) { + ext_widgets[j] &= (ui->ui_ext[j] || inclusive); + } + } +}]] + local screen + + before_each(function() + screen = Screen.new(60, 5) + screen:set_default_attr_ids({ + [0] = {foreground = Screen.colors.Blue, bold = true}, + [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGray}; + [2] = {bold = true, background = Screen.colors.LightGray, foreground = Screen.colors.SeaGreen}; + [3] = {foreground = Screen.colors.DarkCyan, background = Screen.colors.LightGray}; + [4] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.LightGray}; + [5] = {bold = true, background = Screen.colors.LightGray, foreground = Screen.colors.Brown}; + [6] = {background = Screen.colors.Red1}; + [7] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.Red}; + [8] = {foreground = Screen.colors.Brown, bold = true, background = Screen.colors.Red}; + [9] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.Red}; + [10] = {bold = true}; + }) + screen:attach() + end) + + it('displays highlighted content', function() + command([[set foldmethod=manual foldtext=v:lua.vim.treesitter.foldtext() updatetime=50]]) + insert(test_text) + exec_lua([[vim.treesitter.get_parser(0, "c")]]) + + feed('ggVGzf') + screen:expect{grid=[[ + {2:^void}{1: }{3:qsort}{4:(}{2:void}{1: }{5:*}{3:base}{4:,}{1: }{2:size_t}{1: }{3:nel}{4:,}{1: }{2:size_t}{1: }{3:width}{4:,}{1: }{2:int}{1: }{4:(}{5:*}{3:compa}| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + end) + + it('handles deep nested captures', function() + command([[set foldmethod=manual foldtext=v:lua.vim.treesitter.foldtext() updatetime=50]]) + insert([[ +function FoldInfo.new() + return setmetatable({ + start_counts = {}, + stop_counts = {}, + levels0 = {}, + levels = {}, + }, FoldInfo) +end]]) + exec_lua([[vim.treesitter.get_parser(0, "lua")]]) + + feed('ggjVGkzfgg') + screen:expect{grid=[[ + ^function FoldInfo.new() | + {1: }{5:return}{1: }{4:setmetatable({}{1:·····································}| + end | + {0:~ }| + | + ]]} + + command('hi! Visual guibg=Red') + feed('GVgg') + screen:expect{grid=[[ + ^f{6:unction FoldInfo.new()} | + {7: }{8:return}{7: }{9:setmetatable({}{7:·····································}| + {6:end} | + {0:~ }| + {10:-- VISUAL LINE --} | + ]]} + + feed('10l<C-V>') + screen:expect{grid=[[ + {6:function F}^oldInfo.new() | + {7: }{8:return}{7: }{9:se}{4:tmetatable({}{1:·····································}| + {6:end} | + {0:~ }| + {10:-- VISUAL BLOCK --} | + ]]} + end) + + it('falls back to default', function() + command([[set foldmethod=manual foldtext=v:lua.vim.treesitter.foldtext()]]) + insert(test_text) + + feed('ggVGzf') + screen:expect{grid=[[ + {1:^+-- 19 lines: void qsort(void *base, size_t nel, size_t widt}| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + end) +end) |