Skip to content

Commit e4dcf96

Browse files
committed
test: add tests for Virtual Indent
1 parent 02e71af commit e4dcf96

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tests/plenary/org/indent_spec.lua

+78
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,81 @@ describe('with "noindent",', function()
283283
test_add_line_breaks_to_existing_file()
284284
end)
285285
end)
286+
287+
describe('with "indent" and "VirtualIndent" is enabled', function()
288+
before_each(function()
289+
config:extend({ org_indent_mode = true })
290+
end)
291+
292+
it('has the correct amount of virtual indentation', function()
293+
if not VirtualIndent.enabled then
294+
return
295+
end
296+
297+
-- In order: { content, virtcol }
298+
-- See `:h virtcol` for details
299+
local content_virtcols = {
300+
{ '* TODO First task', 1 },
301+
{ 'SCHEDULED: <1970-01-01 Thu>', 3 },
302+
{ '', 2 },
303+
{ '1. Ordered list', 3 },
304+
{ ' a) nested list', 3 },
305+
{ ' over-indented', 3 },
306+
{ ' over-indented', 3 },
307+
{ ' b) nested list', 3 },
308+
{ ' under-indented', 3 },
309+
{ '2. Ordered list', 3 },
310+
{ 'Not part of the list', 3 },
311+
{ '', 2 },
312+
{ '** Second task', 1 },
313+
{ 'DEADLINE: <1970-01-01 Thu>', 4 },
314+
{ '', 3 },
315+
{ '- Unordered list', 4 },
316+
{ ' + nested list', 4 },
317+
{ ' over-indented', 4 },
318+
{ ' over-indented', 4 },
319+
{ ' + nested list', 4 },
320+
{ ' under-indented', 4 },
321+
{ '- unordered list', 4 },
322+
{ ' + nested list', 4 },
323+
{ ' * triple nested list', 4 },
324+
{ ' continuation', 4 },
325+
{ ' part of the first-level list', 4 },
326+
{ 'Not part of the list', 4 },
327+
{ '', 3 },
328+
{ '*** Incorrectly indented block', 1 },
329+
{ '#+BEGIN_SRC json', 5 },
330+
{ '{', 5 },
331+
{ ' "key": "value",', 5 },
332+
{ ' "another key": "another value"', 5 },
333+
{ '}', 5 },
334+
{ '#+END_SRC', 5 },
335+
{ '', 4 },
336+
{ '- Correctly reindents to list indentation level', 5 },
337+
{ ' #+BEGIN_SRC json', 5 },
338+
{ ' {', 5 },
339+
{ ' "key": "value",', 5 },
340+
{ ' "another key": "another value"', 5 },
341+
{ ' }', 5 },
342+
{ ' #+END_SRC', 5 },
343+
{ '- Correctly reindents when entire block overindented', 5 },
344+
{ ' #+BEGIN_SRC json', 5 },
345+
{ ' {', 5 },
346+
{ ' "key": "value",', 5 },
347+
{ ' "another key": "another value"', 5 },
348+
{ ' }', 5 },
349+
{ ' #+END_SRC', 5 }
350+
}
351+
local content = {}
352+
for _, content_virtcol in pairs(content_virtcols) do
353+
table.insert(content, content_virtcol[1])
354+
end
355+
helpers.load_file_content(content)
356+
357+
for line = 1, vim.api.nvim_buf_line_count(0) do
358+
vim.api.nvim_win_set_cursor(0, {line, 0})
359+
assert.are.same(content_virtcols[line][1], vim.api.nvim_buf_get_lines(0, line - 1, line, false)[1])
360+
assert.are.equal(content_virtcols[line][2], vim.fn.virtcol("."))
361+
end
362+
end)
363+
end)

0 commit comments

Comments
 (0)