Skip to content

Commit e55c6b8

Browse files
committed
test: add test to validate VirtualIndent dynamic attach functionality
1 parent 7f0829b commit e55c6b8

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tests/plenary/org/indent_spec.lua

+83
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,87 @@ describe('with "indent" and "VirtualIndent" is enabled', function()
338338
assert.are.equal(content_virtcols[line][2], vim.fn.virtcol('.'))
339339
end
340340
end)
341+
342+
it('Virtual Indent detaches and reattaches in response to toggling `vim.b.org_indent_mode`', function()
343+
if not vim.b.org_indent_mode then
344+
return
345+
end
346+
347+
local content_virtcols = {
348+
{ '* TODO First task', 1 },
349+
{ 'SCHEDULED: <1970-01-01 Thu>', 3 },
350+
{ '', 2 },
351+
{ '1. Ordered list', 3 },
352+
{ ' a) nested list', 3 },
353+
{ ' over-indented', 3 },
354+
{ ' over-indented', 3 },
355+
{ ' b) nested list', 3 },
356+
{ ' under-indented', 3 },
357+
{ '2. Ordered list', 3 },
358+
{ 'Not part of the list', 3 },
359+
{ '', 2 },
360+
{ '** Second task', 1 },
361+
{ 'DEADLINE: <1970-01-01 Thu>', 4 },
362+
{ '', 3 },
363+
{ '- Unordered list', 4 },
364+
{ ' + nested list', 4 },
365+
{ ' over-indented', 4 },
366+
{ ' over-indented', 4 },
367+
{ ' + nested list', 4 },
368+
{ ' under-indented', 4 },
369+
{ '- unordered list', 4 },
370+
{ ' + nested list', 4 },
371+
{ ' * triple nested list', 4 },
372+
{ ' continuation', 4 },
373+
{ ' part of the first-level list', 4 },
374+
{ 'Not part of the list', 4 },
375+
{ '', 3 },
376+
{ '*** Incorrectly indented block', 1 },
377+
{ '#+BEGIN_SRC json', 5 },
378+
{ '{', 5 },
379+
{ ' "key": "value",', 5 },
380+
{ ' "another key": "another value"', 5 },
381+
{ '}', 5 },
382+
{ '#+END_SRC', 5 },
383+
{ '', 4 },
384+
{ '- Correctly reindents to list indentation level', 5 },
385+
{ ' #+BEGIN_SRC json', 5 },
386+
{ ' {', 5 },
387+
{ ' "key": "value",', 5 },
388+
{ ' "another key": "another value"', 5 },
389+
{ ' }', 5 },
390+
{ ' #+END_SRC', 5 },
391+
{ '- Correctly reindents when entire block overindented', 5 },
392+
{ ' #+BEGIN_SRC json', 5 },
393+
{ ' {', 5 },
394+
{ ' "key": "value",', 5 },
395+
{ ' "another key": "another value"', 5 },
396+
{ ' }', 5 },
397+
{ ' #+END_SRC', 5 },
398+
}
399+
local content = {}
400+
for _, content_virtcol in pairs(content_virtcols) do
401+
table.insert(content, content_virtcol[1])
402+
end
403+
helpers.load_file_content(content)
404+
405+
-- Check if VirtualIndent correctly detaches in response to disabling `vim.b.org_indent_mode`
406+
vim.b.org_indent_mode = false
407+
-- Give VirtualIndent long enough to react to the change in `vim.b.org_indent_mode`
408+
vim.wait(60)
409+
for line = 1, vim.api.nvim_buf_line_count(0) do
410+
vim.api.nvim_win_set_cursor(0, { line, 0 })
411+
assert.are.equal(0, vim.fn.virtcol('.'))
412+
end
413+
414+
-- Check if VirtualIndent correctly attaches in response to disabling `vim.b.org_indent_mode`
415+
vim.b.org_indent_mode = true
416+
-- Give VirtualIndent long enough to react to the change in `vim.b.org_indent_mode`
417+
vim.wait(60)
418+
for line = 1, vim.api.nvim_buf_line_count(0) do
419+
vim.api.nvim_win_set_cursor(0, { line, 0 })
420+
assert.are.same(content_virtcols[line][1], vim.api.nvim_buf_get_lines(0, line - 1, line, false)[1])
421+
assert.are.equal(content_virtcols[line][2], vim.fn.virtcol('.'))
422+
end
423+
end)
341424
end)

0 commit comments

Comments
 (0)