diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70be624..da16f56 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,20 @@ jobs: - name: Check formatting run: mise run fmt:check + lint: + name: Run Lua Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v6.0.2 + + - name: Set up tools via mise + uses: jdx/mise-action@v4.0.1 + + - name: Run Lua lint + run: mise run lua:lint + test: name: Run Tests runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.lua_ls/busted.lua b/.lua_ls/busted.lua new file mode 100644 index 0000000..0607ac9 --- /dev/null +++ b/.lua_ls/busted.lua @@ -0,0 +1,36 @@ +---@meta + +---@alias BustedCallback fun() + +---@param name string +---@param callback BustedCallback +function describe(name, callback) end + +---@param name string +---@param callback BustedCallback +function it(name, callback) end + +---@param name string +---@param callback BustedCallback +function active_it(name, callback) end + +---@param callback BustedCallback +function before_each(callback) end + +---@param callback BustedCallback +function after_each(callback) end + +---@param name string +---@param callback? BustedCallback +function pending(name, callback) end + +---@class LuassertChain +---@field same fun(expected: any, actual: any, message?: string) +---@field equals fun(expected: any, actual: any, message?: string) +---@field is_true fun(value: any, message?: string) + +---@class Luassert: LuassertChain +---@field are LuassertChain + +---@type Luassert|function +assert = assert diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..5cd4d21 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "runtime.version": "LuaJIT", + "diagnostics.globals": [ + "vim" + ], + "workspace.library": [ + ".lua_ls" + ], + "workspace.checkThirdParty": false, + "workspace.ignoreDir": [ + ".git" + ] +} diff --git a/dprint.json b/dprint.json index 621e955..1ec0bb2 100644 --- a/dprint.json +++ b/dprint.json @@ -3,10 +3,20 @@ }, "markdown": { }, - "toml": { - }, "yaml": { }, + "exec": { + "commands": [ + { + "command": "stylua --allow-hidden --respect-ignores --stdin-filepath {{file_path}} -", + "exts": [".lua"] + }, + { + "command": "taplo format -", + "exts": [".toml"] + } + ] + }, "excludes": [ "CHANGELOG.md", "**/*-lock.json" @@ -20,10 +30,9 @@ "**/*.toml" ], "plugins": [ - "https://plugins.dprint.dev/RubixDev/stylua-v0.2.1.wasm", "https://plugins.dprint.dev/json-0.21.3.wasm", "https://plugins.dprint.dev/markdown-0.22.1.wasm", - "https://plugins.dprint.dev/toml-0.7.0.wasm", - "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.6.0.wasm" + "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.6.0.wasm", + "https://plugins.dprint.dev/exec-0.6.0.json@a054130d458f124f9b5c91484833828950723a5af3f8ff2bd1523bd47b83b364" ] } diff --git a/lua/bullets/actions.lua b/lua/bullets/actions.lua index 36cf962..cc54862 100644 --- a/lua/bullets/actions.lua +++ b/lua/bullets/actions.lua @@ -1,5 +1,5 @@ -local config = require("bullets.config") -local ordinal = require("bullets.ordinal") +local config = require 'bullets.config' +local ordinal = require 'bullets.ordinal' local M = {} @@ -9,7 +9,7 @@ local function style_enabled(marker) return true end - if style:sub(-1) == "+" and marker:match("^" .. vim.pesc(style:sub(1, -2)) .. "+$") then + if style:sub(-1) == '+' and marker:match('^' .. vim.pesc(style:sub(1, -2)) .. '+$') then return true end end @@ -18,13 +18,13 @@ local function style_enabled(marker) end local function parse_static(line) - local indent, marker, spacing, text = line:match("^(%s*)(\\item)(%s+)(.*)$") + local indent, marker, spacing, text = line:match '^(%s*)(\\item)(%s+)(.*)$' if not marker then - indent, marker, spacing, text = line:match("^(%s*)(#%.)(%s+)(.*)$") + indent, marker, spacing, text = line:match '^(%s*)(#%.)(%s+)(.*)$' end if not marker then - indent, marker, spacing, text = line:match("^(%s*)([%*.]+)(%s+)(.*)$") - if marker and (marker == "*" or not (marker:match("^%*+$") or marker:match("^%.+$"))) then + indent, marker, spacing, text = line:match '^(%s*)([%*.]+)(%s+)(.*)$' + if marker and (marker == '*' or not (marker:match '^%*+$' or marker:match '^%.+$')) then marker = nil end end @@ -33,7 +33,7 @@ local function parse_static(line) end return { - type = "static", + type = 'static', indent = indent, marker = marker, spacing = spacing, @@ -42,7 +42,7 @@ local function parse_static(line) end local function parse_standard(line) - local indent, marker, spacing, text = line:match("^(%s*)([-*+])(%s+)(.*)$") + local indent, marker, spacing, text = line:match '^(%s*)([-*+])(%s+)(.*)$' if not marker then return nil end @@ -59,13 +59,13 @@ local function parse_standard(line) end local function parse_numeric(line) - local indent, marker, closure, spacing, text = line:match("^(%s*)(%d+)([.)])(%s+)(.*)$") + local indent, marker, closure, spacing, text = line:match '^(%s*)(%d+)([.)])(%s+)(.*)$' if not marker then return nil end return { - type = "num", + type = 'num', indent = indent, marker = marker, closure = closure, @@ -80,13 +80,13 @@ local function parse_alpha(line) return nil end - local indent, marker, closure, spacing, text = line:match("^(%s*)(%a+)([.)])(%s+)(.*)$") + local indent, marker, closure, spacing, text = line:match '^(%s*)(%a+)([.)])(%s+)(.*)$' if not marker or #marker > max or not (marker == marker:lower() or marker == marker:upper()) then return nil end return { - type = "abc", + type = 'abc', indent = indent, marker = marker, closure = closure, @@ -100,13 +100,13 @@ local function parse_roman(line) return nil end - local indent, marker, closure, spacing, text = line:match("^(%s*)(%a+)([.)])(%s+)(.*)$") + local indent, marker, closure, spacing, text = line:match '^(%s*)(%a+)([.)])(%s+)(.*)$' if not marker or not (marker == marker:lower() or marker == marker:upper()) or not ordinal.is_roman(marker) then return nil end return { - type = "rom", + type = 'rom', indent = indent, marker = marker, closure = closure, @@ -123,7 +123,7 @@ local function parse_line(line) local standard = parse_standard(line) if standard then - standard.type = "std" + standard.type = 'std' return { standard } end @@ -145,12 +145,12 @@ local resolve_bullet local function previous_ordered_type(lnum, indent) for row = lnum - 1, 1, -1 do local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1] - if line == "" then + if line == '' then return nil end local bullet = resolve_bullet(parse_line(line), row) - if bullet and bullet.indent == indent and (bullet.type == "abc" or bullet.type == "rom") then + if bullet and bullet.indent == indent and (bullet.type == 'abc' or bullet.type == 'rom') then return bullet.type end end @@ -176,7 +176,7 @@ function resolve_bullet(bullets, lnum) end for _, bullet in ipairs(bullets) do - if bullet.type == "rom" then + if bullet.type == 'rom' then return bullet end end @@ -185,7 +185,7 @@ function resolve_bullet(bullets, lnum) end local function at_eol(line) - return vim.fn.col(".") == #line + 1 + return vim.fn.col '.' == #line + 1 end local function keys(lhs) @@ -193,12 +193,12 @@ local function keys(lhs) end local function feed_cr() - vim.api.nvim_feedkeys(keys(""), "in", false) + vim.api.nvim_feedkeys(keys '', 'in', false) end local function open_line_below() local lnum = vim.api.nvim_win_get_cursor(0)[1] - vim.api.nvim_buf_set_lines(0, lnum, lnum, false, { "" }) + vim.api.nvim_buf_set_lines(0, lnum, lnum, false, { '' }) vim.api.nvim_win_set_cursor(0, { lnum + 1, 0 }) vim.cmd.startinsert() end @@ -226,14 +226,14 @@ local function pad_right(prefix, width) return prefix end - return prefix .. string.rep(" ", width - #prefix) + return prefix .. string.rep(' ', width - #prefix) end local function next_marker(bullet) - if bullet.type == "num" then + if bullet.type == 'num' then return tostring(tonumber(bullet.marker) + 1) end - if bullet.type == "abc" then + if bullet.type == 'abc' then local marker = ordinal.number_to_abc(ordinal.abc_to_number(bullet.marker) + 1, bullet.marker == bullet.marker:lower()) if #marker > config.options.max_alpha_characters then @@ -241,7 +241,7 @@ local function next_marker(bullet) end return marker end - if bullet.type == "rom" then + if bullet.type == 'rom' then return ordinal.number_to_roman(ordinal.roman_to_number(bullet.marker) + 1, bullet.marker == bullet.marker:lower()) end @@ -249,7 +249,7 @@ local function next_marker(bullet) end local function prefix_width(bullet) - if bullet.type == "num" or bullet.type == "abc" or bullet.type == "rom" then + if bullet.type == 'num' or bullet.type == 'abc' or bullet.type == 'rom' then return #bullet.indent + #bullet.marker + #bullet.closure + #bullet.spacing end @@ -264,29 +264,29 @@ local function next_prefix(bullet) return nil end - if bullet.type == "std" then + if bullet.type == 'std' then return bullet.indent .. marker .. bullet.spacing end - if bullet.type == "static" then + if bullet.type == 'static' then return bullet.indent .. marker .. bullet.spacing end - local prefix = marker .. bullet.closure .. " " + local prefix = marker .. bullet.closure .. ' ' return bullet.indent .. pad_right(prefix, #bullet.marker + #bullet.closure + #bullet.spacing) end function current_prefix(bullet) - if bullet.type == "std" or bullet.type == "static" then + if bullet.type == 'std' or bullet.type == 'static' then return bullet.indent .. bullet.marker .. bullet.spacing end - local prefix = bullet.marker .. bullet.closure .. " " + local prefix = bullet.marker .. bullet.closure .. ' ' return bullet.indent .. pad_right(prefix, #bullet.marker + #bullet.closure + #bullet.spacing) end local function checkbox_markers() local markers = {} - local configured = config.options.checkbox_markers or "" + local configured = config.options.checkbox_markers or '' for index = 0, vim.fn.strchars(configured) - 1 do table.insert(markers, vim.fn.strcharpart(configured, index, 1)) @@ -302,12 +302,12 @@ local function checkbox_marker_index(marker, markers) end end - if marker == " " then + if marker == ' ' then return 1 end local checked = markers[#markers] - if checked and (marker:lower() == checked:lower() or marker:lower() == "x") then + if checked and (marker:lower() == checked:lower() or marker:lower() == 'x') then return #markers end @@ -315,7 +315,7 @@ local function checkbox_marker_index(marker, markers) end local function parse_checkbox_text(text) - local marker, spacing, rest = text:match("^%[([^%]]+)%](%s*)(.*)$") + local marker, spacing, rest = text:match '^%[([^%]]+)%](%s*)(.*)$' if not marker then return nil end @@ -345,17 +345,17 @@ end local function checkbox_state(checkbox) if checkbox.index == 1 then - return "unchecked" + return 'unchecked' end if checkbox.index == #checkbox.markers then - return "checked" + return 'checked' end - return "partial" + return 'partial' end local function checkbox_text(marker, checkbox) - return "[" .. marker .. "]" .. checkbox.spacing .. checkbox.rest + return '[' .. marker .. ']' .. checkbox.spacing .. checkbox.rest end local function set_checkbox_marker(lnum, bullet, checkbox, marker) @@ -364,79 +364,83 @@ end local function checkbox_continuation_prefix(bullet, prefix) local checkbox = parse_checkbox_text(bullet.text) - local unchecked = checkbox and checkbox_unchecked_marker() + if not checkbox then + return prefix + end + + local unchecked = checkbox_unchecked_marker() if not unchecked then return prefix end - return prefix .. "[" .. unchecked .. "]" .. checkbox.spacing + return prefix .. '[' .. unchecked .. ']' .. checkbox.spacing end local function is_empty_bullet_text(text) - if text == "" then + if text == '' then return true end local checkbox = parse_checkbox_text(text) - return checkbox and checkbox.rest == "" + return checkbox and checkbox.rest == '' end local function indent_unit() if not vim.o.expandtab and vim.o.shiftwidth ~= 8 then - return "\t" + return '\t' end - return string.rep(" ", vim.o.shiftwidth > 0 and vim.o.shiftwidth ~= 8 and vim.o.shiftwidth or 2) + return string.rep(' ', vim.o.shiftwidth > 0 and vim.o.shiftwidth ~= 8 and vim.o.shiftwidth or 2) end local function demote_indent_unit() if not vim.o.expandtab then - return "\t" + return '\t' end return indent_unit() end local function style_for_bullet(bullet) - if bullet.type == "std" then - return "std" .. bullet.marker + if bullet.type == 'std' then + return 'std' .. bullet.marker end - if bullet.type == "static" then + if bullet.type == 'static' then return bullet.marker end - if bullet.type == "num" then - return "num" + if bullet.type == 'num' then + return 'num' end - if bullet.type == "abc" then - return bullet.marker == bullet.marker:lower() and "abc" or "ABC" + if bullet.type == 'abc' then + return bullet.marker == bullet.marker:lower() and 'abc' or 'ABC' end - if bullet.type == "rom" then - return bullet.marker == bullet.marker:lower() and "rom" or "ROM" + if bullet.type == 'rom' then + return bullet.marker == bullet.marker:lower() and 'rom' or 'ROM' end return nil end local function bullet_for_style(style, indent) - if style == "num" then - return { type = "num", indent = indent, marker = "1", closure = ".", spacing = " ", text = "" } + if style == 'num' then + return { type = 'num', indent = indent, marker = '1', closure = '.', spacing = ' ', text = '' } end - if style == "abc" then - return { type = "abc", indent = indent, marker = "a", closure = ".", spacing = " ", text = "" } + if style == 'abc' then + return { type = 'abc', indent = indent, marker = 'a', closure = '.', spacing = ' ', text = '' } end - if style == "ABC" then - return { type = "abc", indent = indent, marker = "A", closure = ".", spacing = " ", text = "" } + if style == 'ABC' then + return { type = 'abc', indent = indent, marker = 'A', closure = '.', spacing = ' ', text = '' } end - if style == "rom" then - return { type = "rom", indent = indent, marker = "i", closure = ".", spacing = " ", text = "" } + if style == 'rom' then + return { type = 'rom', indent = indent, marker = 'i', closure = '.', spacing = ' ', text = '' } end - if style == "ROM" then - return { type = "rom", indent = indent, marker = "I", closure = ".", spacing = " ", text = "" } + if style == 'ROM' then + return { type = 'rom', indent = indent, marker = 'I', closure = '.', spacing = ' ', text = '' } end - local marker = style:match("^std(.+)$") + local marker = style:match '^std(.+)$' if marker then - return { type = "std", indent = indent, marker = marker, spacing = " ", text = "" } + return { type = 'std', indent = indent, marker = marker, spacing = ' ', text = '' } end return nil @@ -487,8 +491,8 @@ local function parent_indent(indent) end return indent - :gsub("\t$", "") - :gsub(string.rep(" ", vim.o.shiftwidth > 0 and vim.o.shiftwidth or vim.o.tabstop) .. "$", "") + :gsub('\t$', '') + :gsub(string.rep(' ', vim.o.shiftwidth > 0 and vim.o.shiftwidth or vim.o.tabstop) .. '$', '') end local function first_bullet_for_style(style, indent) @@ -498,7 +502,7 @@ end local function previous_bullet_with_style(lnum, style, indent) for row = lnum - 1, 1, -1 do local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1] - if line == "" then + if line == '' then return nil end @@ -544,21 +548,21 @@ local function change_line_level(lnum, direction) local next_style local next_indent - if direction == "demote" then + if direction == 'demote' then local unit = demote_indent_unit() next_style = index and config.options.outline_levels[index + 1] or fallback_style_for_indent(bullet.indent .. unit) next_indent = bullet.indent .. unit if not next_style then local last_style = config.options.outline_levels[#config.options.outline_levels] - if last_style and last_style:match("^std") and bullet.type == "std" then + if last_style and last_style:match '^std' and bullet.type == 'std' then next_style = style else return false end end else - if bullet.indent == "" then + if bullet.indent == '' then vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, { bullet.text }) vim.api.nvim_win_set_cursor(0, { lnum, 0 }) return true @@ -587,7 +591,7 @@ local function change_line_level(lnum, direction) local prefix = current_prefix(next_bullet) vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, { prefix .. bullet.text }) if checkbox then - prefix = prefix .. "[" .. checkbox.marker .. "]" .. checkbox.spacing + prefix = prefix .. '[' .. checkbox.marker .. ']' .. checkbox.spacing end vim.api.nvim_win_set_cursor(0, { lnum, #prefix }) return true @@ -607,8 +611,8 @@ local function visual_range(first, last) return first, last end - local start_pos = vim.fn.getpos("'<") - local end_pos = vim.fn.getpos("'>") + local start_pos = vim.fn.getpos "'<" + local end_pos = vim.fn.getpos "'>" return math.min(start_pos[2], end_pos[2]), math.max(start_pos[2], end_pos[2]) end @@ -625,38 +629,22 @@ local function change_visual_level(direction, first, last) end local function ends_with_colon(text) - return text:sub(-1) == ":" or text:sub(-3) == ":" + return text:sub(-1) == ':' or text:sub(-3) == ':' end local function spaced_lines(prefix) local lines = {} for _ = 2, config.options.line_spacing do - table.insert(lines, "") + table.insert(lines, '') end table.insert(lines, prefix) return lines, #lines end -local function previous_bullet_with_indent(lnum, indent) - for row = lnum - 1, 1, -1 do - local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1] - if line:match("^%s*$") then - return nil - end - - local previous = resolve_bullet(parse_line(line), row) - if previous and previous.indent == indent then - return previous - end - end - - return nil -end - local function previous_parent_bullet(lnum, indent) for row = lnum - 1, 1, -1 do local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1] - if line:match("^%s*$") then + if line:match '^%s*$' then return nil end @@ -672,7 +660,7 @@ end local function delete_empty_bullet(lnum, bullet, mode) local behavior = config.options.delete_last_bullet_if_empty if behavior == 0 then - if mode == "n" then + if mode == 'n' then open_line_below() else split_line() @@ -680,14 +668,14 @@ local function delete_empty_bullet(lnum, bullet, mode) return true end - if behavior == 2 and bullet.indent ~= "" then + if behavior == 2 and bullet.indent ~= '' then local parent = previous_parent_bullet(lnum, bullet.indent) - local prefix = parent and next_prefix(parent) or "" + local prefix = parent and next_prefix(parent) or '' if prefix then prefix = checkbox_continuation_prefix(bullet, prefix) end - vim.api.nvim_set_current_line(prefix or "") - vim.api.nvim_win_set_cursor(0, { lnum, #(prefix or "") }) + vim.api.nvim_set_current_line(prefix or '') + vim.api.nvim_win_set_cursor(0, { lnum, #(prefix or '') }) return true end @@ -697,14 +685,14 @@ local function delete_empty_bullet(lnum, bullet, mode) end local function wrapped_owner(lnum, line) - if not config.options.enable_wrapped_lines or line:match("^%s*$") then + if not config.options.enable_wrapped_lines or line:match '^%s*$' then return nil end - local current_indent = #(line:match("^%s*") or "") + local current_indent = #(line:match '^%s*' or '') for row = lnum - 1, 1, -1 do local previous_line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1] - if previous_line:match("^%s*$") then + if previous_line:match '^%s*$' then return nil end @@ -712,7 +700,7 @@ local function wrapped_owner(lnum, line) if previous_bullet and current_indent >= prefix_width(previous_bullet) then return previous_bullet end - if not previous_bullet and #(previous_line:match("^%s*") or "") < current_indent then + if not previous_bullet and #(previous_line:match '^%s*' or '') < current_indent then return nil end end @@ -721,17 +709,17 @@ local function wrapped_owner(lnum, line) end local function is_ordered(bullet) - return bullet.type == "num" or bullet.type == "abc" or bullet.type == "rom" + return bullet.type == 'num' or bullet.type == 'abc' or bullet.type == 'rom' end local function marker_number(bullet) - if bullet.type == "num" then + if bullet.type == 'num' then return tonumber(bullet.marker) end - if bullet.type == "abc" then + if bullet.type == 'abc' then return ordinal.abc_to_number(bullet.marker) end - if bullet.type == "rom" then + if bullet.type == 'rom' then return ordinal.roman_to_number(bullet.marker) end @@ -739,13 +727,13 @@ local function marker_number(bullet) end local function number_marker(type, value, lower) - if type == "num" then + if type == 'num' then return tostring(value) end - if type == "abc" then + if type == 'abc' then return ordinal.number_to_abc(value, lower) end - if type == "rom" then + if type == 'rom' then return ordinal.number_to_roman(value, lower) end @@ -767,12 +755,12 @@ local function boundary_bullet_at(lnum) return bullet, line end - return wrapped_owner(lnum, line or ""), line + return wrapped_owner(lnum, line or ''), line end local function line_indent(lnum) - local line = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, false)[1] or "" - return #(line:match("^%s*") or "") + local line = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, false)[1] or '' + return #(line:match '^%s*' or '') end local function first_bullet_line(lnum, min_indent) @@ -789,7 +777,7 @@ local function first_bullet_line(lnum, min_indent) if bullet and #bullet.indent >= min_indent then first = row blank_lines = 0 - elseif line and line:match("^%s*$") then + elseif line and line:match '^%s*$' then blank_lines = blank_lines + 1 if blank_lines >= config.options.line_spacing then break @@ -820,7 +808,7 @@ local function last_bullet_line(lnum, min_indent) if bullet then last = row blank_lines = 0 - elseif line:match("^%s*$") then + elseif line and line:match '^%s*$' then blank_lines = blank_lines + 1 if blank_lines >= config.options.line_spacing then break @@ -905,34 +893,34 @@ function M.insert_new_bullet() local line = vim.api.nvim_get_current_line() local bullet = resolve_bullet(parse_line(line), lnum) or wrapped_owner(lnum, line) - if mode ~= "n" and not at_eol(line) then + if mode ~= 'n' and not at_eol(line) then feed_cr() - return "" + return '' end if not bullet then - if mode == "n" then + if mode == 'n' then open_line_below() - return "" + return '' end feed_cr() - return "" + return '' end - if bullet.text:match("^%s*$") and config.options.delete_last_bullet_if_empty == 1 then - if mode ~= "n" then - vim.api.nvim_feedkeys(keys("ddi"), "n", false) - return "" + if bullet.text:match '^%s*$' and config.options.delete_last_bullet_if_empty == 1 then + if mode ~= 'n' then + vim.api.nvim_feedkeys(keys 'ddi', 'n', false) + return '' end vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, {}) vim.cmd.startinsert() - return "" + return '' end if is_empty_bullet_text(bullet.text) and delete_empty_bullet(lnum, bullet, mode) then - return "" + return '' end local prefix @@ -945,22 +933,22 @@ function M.insert_new_bullet() prefix = prefix or next_prefix(bullet) if not prefix then - if mode == "n" then + if mode == 'n' then open_line_below() - return "" + return '' end feed_cr() - return "" + return '' end prefix = checkbox_continuation_prefix(bullet, prefix) local lines, cursor_index = spaced_lines(prefix) insert_lines(lnum, lines, cursor_index) - vim.cmd.startinsert({ bang = true }) + vim.cmd.startinsert { bang = true } - return "" + return '' end function M.renumber_list() @@ -1037,7 +1025,7 @@ local function recompute_items(items) if #item.children > 0 then local checked = 0 for _, child in ipairs(item.children) do - if checkbox_state(child.checkbox) == "checked" then + if checkbox_state(child.checkbox) == 'checked' then checked = checked + 1 end end @@ -1046,7 +1034,7 @@ local function recompute_items(items) item.checkbox.marker = marker item.checkbox.index = checkbox_marker_index(marker, item.checkbox.markers) set_checkbox_marker(item.lnum, item.bullet, item.checkbox, marker) - elseif checkbox_state(item.checkbox) == "partial" then + elseif checkbox_state(item.checkbox) == 'partial' then local marker = item.checkbox.markers[1] item.checkbox.marker = marker item.checkbox.index = 1 @@ -1066,7 +1054,11 @@ local function set_descendant_checkboxes(lnum, bullet, marker) local blank_lines = 0 for row = lnum + 1, line_count do local descendant_bullet, line = bullet_at(row) - if line:match("^%s*$") then + if not line then + break + end + + if line:match '^%s*$' then blank_lines = blank_lines + 1 if blank_lines >= config.options.line_spacing then break @@ -1079,7 +1071,7 @@ local function set_descendant_checkboxes(lnum, bullet, marker) end local item = checkbox_item(row) - if item.checkbox then + if item and item.checkbox then item.checkbox.marker = marker item.checkbox.index = checkbox_marker_index(marker, item.checkbox.markers) set_checkbox_marker(row, item.bullet, item.checkbox, marker) @@ -1100,8 +1092,8 @@ function M.toggle_checkbox() local markers = item.checkbox.markers local state = checkbox_state(item.checkbox) - local marker = state == "checked" and markers[1] or checkbox_checked_marker(markers) - if state == "partial" and config.options.checkbox_partials_toggle == 0 then + local marker = state == 'checked' and markers[1] or checkbox_checked_marker(markers) + if state == 'partial' and config.options.checkbox_partials_toggle == 0 then marker = markers[1] end item.checkbox.marker = marker @@ -1122,19 +1114,19 @@ function M.recompute_checkboxes() end function M.demote() - return change_current_line_level("demote") + return change_current_line_level 'demote' end function M.promote() - return change_current_line_level("promote") + return change_current_line_level 'promote' end function M.demote_visual(first, last) - return change_visual_level("demote", first, last) + return change_visual_level('demote', first, last) end function M.promote_visual(first, last) - return change_visual_level("promote", first, last) + return change_visual_level('promote', first, last) end function M.select_checkbox() end diff --git a/lua/bullets/config.lua b/lua/bullets/config.lua index 3b31213..cd2fc1f 100644 --- a/lua/bullets/config.lua +++ b/lua/bullets/config.lua @@ -1,22 +1,22 @@ local M = {} M.defaults = { - enabled_file_types = { "markdown", "text", "gitcommit" }, + enabled_file_types = { 'markdown', 'text', 'gitcommit' }, enable_in_empty_buffers = false, set_mappings = true, - mapping_leader = "", + mapping_leader = '', custom_mappings = {}, delete_last_bullet_if_empty = 1, line_spacing = 1, pad_right = true, max_alpha_characters = 2, enable_roman_list = true, - list_item_styles = { "-", "*+", ".+", "#.", "+", "\\item" }, - outline_levels = { "ROM", "ABC", "num", "abc", "rom", "std-", "std*", "std+" }, + list_item_styles = { '-', '*+', '.+', '#.', '+', '\\item' }, + outline_levels = { 'ROM', 'ABC', 'num', 'abc', 'rom', 'std-', 'std*', 'std+' }, renumber_on_change = true, nested_checkboxes = true, enable_wrapped_lines = true, - checkbox_markers = " .oOX", + checkbox_markers = ' .oOX', checkbox_partials_toggle = 1, auto_indent_after_colon = true, } @@ -24,7 +24,7 @@ M.defaults = { M.options = vim.deepcopy(M.defaults) function M.setup(options) - M.options = vim.tbl_deep_extend("force", vim.deepcopy(M.defaults), options or {}) + M.options = vim.tbl_deep_extend('force', vim.deepcopy(M.defaults), options or {}) return M.options end diff --git a/lua/bullets/init.lua b/lua/bullets/init.lua index 1c8cc78..8efc2aa 100644 --- a/lua/bullets/init.lua +++ b/lua/bullets/init.lua @@ -1,24 +1,24 @@ -local config = require("bullets.config") +local config = require 'bullets.config' local M = {} M.did_setup = false -local augroup = vim.api.nvim_create_augroup("bullets.nvim", { clear = true }) +local augroup = vim.api.nvim_create_augroup('bullets.nvim', { clear = true }) local function actions() - return require("bullets.actions") + return require 'bullets.actions' end local function command(name, fn, opts) - vim.api.nvim_create_user_command(name, fn, vim.tbl_extend("force", { force = true }, opts or {})) + vim.api.nvim_create_user_command(name, fn, vim.tbl_extend('force', { force = true }, opts or {})) end local function map(mode, lhs, rhs, opts) - vim.keymap.set(mode, lhs, rhs, vim.tbl_extend("force", { silent = true }, opts or {})) + vim.keymap.set(mode, lhs, rhs, vim.tbl_extend('force', { silent = true }, opts or {})) end local function map_buffer(buf, mode, lhs, rhs, opts) - vim.keymap.set(mode, lhs, rhs, vim.tbl_extend("force", { buffer = buf, silent = true }, opts or {})) + vim.keymap.set(mode, lhs, rhs, vim.tbl_extend('force', { buffer = buf, silent = true }, opts or {})) end local function keys(lhs) @@ -26,109 +26,109 @@ local function keys(lhs) end local function add_commands() - command("InsertNewBullet", function() + command('InsertNewBullet', function() actions().insert_new_bullet() end) - command("RenumberList", function() + command('RenumberList', function() actions().renumber_list() end) - command("RenumberSelection", function(opts) + command('RenumberSelection', function(opts) actions().renumber_selection(opts.line1, opts.line2) end, { range = true }) - command("ToggleCheckbox", function() + command('ToggleCheckbox', function() actions().toggle_checkbox() end) - command("RecomputeCheckboxes", function() + command('RecomputeCheckboxes', function() actions().recompute_checkboxes() end) - command("BulletDemote", function() + command('BulletDemote', function() actions().demote() end) - command("BulletPromote", function() + command('BulletPromote', function() actions().promote() end) - command("BulletDemoteVisual", function(opts) + command('BulletDemoteVisual', function(opts) actions().demote_visual(opts.line1, opts.line2) end, { range = true }) - command("BulletPromoteVisual", function(opts) + command('BulletPromoteVisual', function(opts) actions().promote_visual(opts.line1, opts.line2) end, { range = true }) - command("SelectCheckbox", function() + command('SelectCheckbox', function() actions().select_checkbox() end) - command("SelectCheckboxInside", function() + command('SelectCheckboxInside', function() actions().select_checkbox_inside() end) - command("SelectBullet", function() + command('SelectBullet', function() actions().select_bullet() end) - command("SelectBulletText", function() + command('SelectBulletText', function() actions().select_bullet_text() end) end local function add_plug_mappings() - map("i", "(bullets-newline)", function() + map('i', '(bullets-newline)', function() actions().insert_new_bullet() end) - map("n", "(bullets-newline)", function() + map('n', '(bullets-newline)', function() actions().insert_new_bullet() end) - map("n", "(bullets-renumber)", function() + map('n', '(bullets-renumber)', function() actions().renumber_list() end) - map("x", "(bullets-renumber)", ":RenumberSelection") - map("n", "(bullets-toggle-checkbox)", function() + map('x', '(bullets-renumber)', ':RenumberSelection') + map('n', '(bullets-toggle-checkbox)', function() actions().toggle_checkbox() end) - map("n", "(bullets-recompute-checkboxes)", function() + map('n', '(bullets-recompute-checkboxes)', function() actions().recompute_checkboxes() end) - map({ "i", "n" }, "(bullets-demote)", function() + map({ 'i', 'n' }, '(bullets-demote)', function() actions().demote() end) - map("x", "(bullets-demote)", ":'<,'>BulletDemoteVisual") - map({ "i", "n" }, "(bullets-promote)", function() + map('x', '(bullets-demote)', ":'<,'>BulletDemoteVisual") + map({ 'i', 'n' }, '(bullets-promote)', function() actions().promote() end) - map("x", "(bullets-promote)", ":'<,'>BulletPromoteVisual") + map('x', '(bullets-promote)', ":'<,'>BulletPromoteVisual") end local function add_default_mappings(buf) local opts = config.options local leader = opts.mapping_leader - map_buffer(buf, "i", leader .. "", "(bullets-newline)", { remap = true }) - map_buffer(buf, "i", leader .. "", "") - map_buffer(buf, "n", leader .. "o", "(bullets-newline)", { remap = true }) - map_buffer(buf, "n", leader .. "gN", "(bullets-renumber)", { remap = true }) - map_buffer(buf, "x", leader .. "gN", "(bullets-renumber)", { remap = true }) - map_buffer(buf, "n", leader .. "x", "(bullets-toggle-checkbox)", { remap = true }) - map_buffer(buf, "i", leader .. "", function() + map_buffer(buf, 'i', leader .. '', '(bullets-newline)', { remap = true }) + map_buffer(buf, 'i', leader .. '', '') + map_buffer(buf, 'n', leader .. 'o', '(bullets-newline)', { remap = true }) + map_buffer(buf, 'n', leader .. 'gN', '(bullets-renumber)', { remap = true }) + map_buffer(buf, 'x', leader .. 'gN', '(bullets-renumber)', { remap = true }) + map_buffer(buf, 'n', leader .. 'x', '(bullets-toggle-checkbox)', { remap = true }) + map_buffer(buf, 'i', leader .. '', function() if not actions().demote() then - vim.api.nvim_feedkeys(keys(""), "in", false) + vim.api.nvim_feedkeys(keys '', 'in', false) end end) - map_buffer(buf, "i", leader .. "", function() + map_buffer(buf, 'i', leader .. '', function() if not actions().promote() then - vim.api.nvim_feedkeys(keys(""), "in", false) + vim.api.nvim_feedkeys(keys '', 'in', false) end end) - map_buffer(buf, "n", leader .. ">>", function() + map_buffer(buf, 'n', leader .. '>>', function() if not actions().demote() then - vim.cmd("normal! >>") + vim.cmd 'normal! >>' end end) - map_buffer(buf, "n", leader .. "<<", function() + map_buffer(buf, 'n', leader .. '<<', function() if not actions().promote() then - vim.cmd("normal! <<") + vim.cmd 'normal! <<' end end) end local function should_configure_buffer(buf) return vim.tbl_contains(config.options.enabled_file_types, vim.bo[buf].filetype) - or (config.options.enable_in_empty_buffers and vim.bo[buf].filetype == "") + or (config.options.enable_in_empty_buffers and vim.bo[buf].filetype == '') end local function add_custom_mappings(buf) @@ -145,9 +145,9 @@ local function configure_buffer(buf) end local function add_autocmds() - vim.api.nvim_clear_autocmds({ group = augroup }) + vim.api.nvim_clear_autocmds { group = augroup } - vim.api.nvim_create_autocmd("FileType", { + vim.api.nvim_create_autocmd('FileType', { group = augroup, pattern = config.options.enabled_file_types, callback = function(event) @@ -156,11 +156,11 @@ local function add_autocmds() }) if config.options.enable_in_empty_buffers then - vim.api.nvim_create_autocmd({ "BufNew", "BufRead" }, { + vim.api.nvim_create_autocmd({ 'BufNew', 'BufRead' }, { group = augroup, - pattern = "*", + pattern = '*', callback = function(event) - if vim.bo[event.buf].filetype == "" then + if vim.bo[event.buf].filetype == '' then configure_buffer(event.buf) end end, diff --git a/lua/bullets/ordinal.lua b/lua/bullets/ordinal.lua index e0ffee2..9720f82 100644 --- a/lua/bullets/ordinal.lua +++ b/lua/bullets/ordinal.lua @@ -1,19 +1,19 @@ local M = {} local roman_values = { - { 1000, "m" }, - { 900, "cm" }, - { 500, "d" }, - { 400, "cd" }, - { 100, "c" }, - { 90, "xc" }, - { 50, "l" }, - { 40, "xl" }, - { 10, "x" }, - { 9, "ix" }, - { 5, "v" }, - { 4, "iv" }, - { 1, "i" }, + { 1000, 'm' }, + { 900, 'cm' }, + { 500, 'd' }, + { 400, 'cd' }, + { 100, 'c' }, + { 90, 'xc' }, + { 50, 'l' }, + { 40, 'xl' }, + { 10, 'x' }, + { 9, 'ix' }, + { 5, 'v' }, + { 4, 'iv' }, + { 1, 'i' }, } function M.abc_to_number(value) @@ -21,15 +21,15 @@ function M.abc_to_number(value) local lower = value:lower() for i = 1, #lower do - result = result * 26 + lower:byte(i) - string.byte("a") + 1 + result = result * 26 + lower:byte(i) - string.byte 'a' + 1 end return result end function M.number_to_abc(value, lower) - local base = lower and string.byte("a") or string.byte("A") - local result = "" + local base = lower and string.byte 'a' or string.byte 'A' + local result = '' while value > 0 do value = value - 1 @@ -66,7 +66,7 @@ function M.roman_to_number(value) end function M.number_to_roman(value, lower) - local result = "" + local result = '' for _, pair in ipairs(roman_values) do local number, letters = pair[1], pair[2] diff --git a/mise.toml b/mise.toml index c172dee..ad54e38 100644 --- a/mise.toml +++ b/mise.toml @@ -3,8 +3,11 @@ dprint = "latest" gitleaks = "latest" lefthook = "latest" +lua-language-server = "3" neovim = "latest" "npm:@kitlangton/stack" = "0.1.5" +taplo = "latest" +stylua = "2" [hooks] postinstall = "lefthook install" @@ -34,6 +37,10 @@ status=0 exit $status """ +[tasks."lua:lint"] +description = "List Lua language server diagnostics" +run = "lua-language-server --check . --checklevel=Hint --check_format=pretty" + [tasks."release:signing-key"] description = "Generate/export the release-please GPG signing key" file = "scripts/release-please-gpg-key.sh" diff --git a/plugin/bullets.lua b/plugin/bullets.lua index 9611943..8e5da88 100644 --- a/plugin/bullets.lua +++ b/plugin/bullets.lua @@ -4,7 +4,7 @@ end vim.g.loaded_bullets_nvim = true -local bullets = require("bullets") +local bullets = require 'bullets' if not bullets.did_setup then bullets.setup() end diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..7e407a5 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,9 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferSingle" +call_parentheses = "None" + +[sort_requires] +enabled = true diff --git a/test/alphabetic_bullets_spec.lua b/test/alphabetic_bullets_spec.lua index 7bfc5c0..1ee34d0 100644 --- a/test/alphabetic_bullets_spec.lua +++ b/test/alphabetic_bullets_spec.lua @@ -1,140 +1,138 @@ -local helpers = require("test.helpers") -local active_it = it -local it = pending +local helpers = require 'test.helpers' -describe("Bullets.vim", function() - describe("alphabetic bullets", function() +describe('Bullets.vim', function() + describe('alphabetic bullets', function() before_each(function() helpers.reset_config() end) - active_it("adds a new upper case bullet", function() - helpers.new_buffer({ - "# Hello there", - "A. this is the first bullet", - }) + it('adds a new upper case bullet', function() + helpers.new_buffer { + '# Hello there', + 'A. this is the first bullet', + } helpers.feedkeys( - "Asecond bulletthird bulletfourth bulletfifth bullet" - .. "sixth bulletseventh bulleteighth bulletninth bullettenth bullet" + 'Asecond bulletthird bulletfourth bulletfifth bullet' + .. 'sixth bulletseventh bulleteighth bulletninth bullettenth bullet' ) assert.are.same({ - "# Hello there", - "A. this is the first bullet", - "B. second bullet", - "C. third bullet", - "D. fourth bullet", - "E. fifth bullet", - "F. sixth bullet", - "G. seventh bullet", - "H. eighth bullet", - "I. ninth bullet", - "J. tenth bullet", + '# Hello there', + 'A. this is the first bullet', + 'B. second bullet', + 'C. third bullet', + 'D. fourth bullet', + 'E. fifth bullet', + 'F. sixth bullet', + 'G. seventh bullet', + 'H. eighth bullet', + 'I. ninth bullet', + 'J. tenth bullet', }, helpers.get_lines()) end) - active_it("adds a new lower case bullet", function() - helpers.new_buffer({ - "# Hello there", - "a. this is the first bullet", - }) + it('adds a new lower case bullet', function() + helpers.new_buffer { + '# Hello there', + 'a. this is the first bullet', + } helpers.feedkeys( - "Asecond bulletthird bulletfourth bulletfifth bullet" - .. "sixth bulletseventh bulleteighth bulletninth bullettenth bullet" + 'Asecond bulletthird bulletfourth bulletfifth bullet' + .. 'sixth bulletseventh bulleteighth bulletninth bullettenth bullet' ) assert.are.same({ - "# Hello there", - "a. this is the first bullet", - "b. second bullet", - "c. third bullet", - "d. fourth bullet", - "e. fifth bullet", - "f. sixth bullet", - "g. seventh bullet", - "h. eighth bullet", - "i. ninth bullet", - "j. tenth bullet", + '# Hello there', + 'a. this is the first bullet', + 'b. second bullet', + 'c. third bullet', + 'd. fourth bullet', + 'e. fifth bullet', + 'f. sixth bullet', + 'g. seventh bullet', + 'h. eighth bullet', + 'i. ninth bullet', + 'j. tenth bullet', }, helpers.get_lines()) end) - it("adds a new bullet and loops at z", function() - require("bullets").setup({ renumber_on_change = false }) - helpers.new_buffer({ - "# Hello there", - "y. this is the first bullet", - }) + pending('adds a new bullet and loops at z', function() + require('bullets').setup { renumber_on_change = false } + helpers.new_buffer { + '# Hello there', + 'y. this is the first bullet', + } -- Type through "third bullet", then press CR twice: -- first CR inserts "ab. " (next bullet after "aa."), -- second CR on empty bullet line triggers delete-last-bullet-if-empty, -- leaving an empty line in normal mode. - helpers.feedkeys("Asecond bulletthird bullet") + helpers.feedkeys 'Asecond bulletthird bullet' -- Now in normal mode on empty line 5. Use 'A' to enter insert at end, -- type the override bullet, then continue with remaining bullets. - helpers.feedkeys("AAY. fourth bulletfifth bulletsixth bullet") + helpers.feedkeys 'AAY. fourth bulletfifth bulletsixth bullet' assert.are.same({ - "# Hello there", - "y. this is the first bullet", - "z. second bullet", - "aa. third bullet", - "AY. fourth bullet", - "AZ. fifth bullet", - "BA. sixth bullet", + '# Hello there', + 'y. this is the first bullet', + 'z. second bullet', + 'aa. third bullet', + 'AY. fourth bullet', + 'AZ. fifth bullet', + 'BA. sixth bullet', }, helpers.get_lines()) end) - active_it("does not add a new bullet when mixed case", function() + it('does not add a new bullet when mixed case', function() -- "Ab." is mixed case so the plugin doesn't recognise it as a bullet. -- CR is therefore deferred via feedkeys('n'); the 'tx' flag in our outer -- feedkeys drains that deferred CR, leaving normal mode on a new empty line. -- Use the two-step non-bullet-line pattern. - helpers.new_buffer({ - "# Hello there", - "Ab. this is the first bullet", - }) - helpers.feedkeys("A") - helpers.feedkeys("inot a bullet") + helpers.new_buffer { + '# Hello there', + 'Ab. this is the first bullet', + } + helpers.feedkeys 'A' + helpers.feedkeys 'inot a bullet' assert.are.same({ - "# Hello there", - "Ab. this is the first bullet", - "not a bullet", + '# Hello there', + 'Ab. this is the first bullet', + 'not a bullet', }, helpers.get_lines()) end) - describe("g:bullets_max_alpha_characters", function() - active_it("stops adding items after configured max (default 2)", function() - require("bullets").setup({ renumber_on_change = false }) - helpers.new_buffer({ - "# Hello there", - "zy. this is the first bullet", - }) + describe('g:bullets_max_alpha_characters', function() + it('stops adding items after configured max (default 2)', function() + require('bullets').setup { renumber_on_change = false } + helpers.new_buffer { + '# Hello there', + 'zy. this is the first bullet', + } -- "A" inserts "zz. " (within max), type "second bullet", -- then on the "zz. second bullet" line: next would be "aaa." (3 -- chars) which exceeds the default max of 2, so no bullet is inserted; -- instead a plain CR is deferred. The 'tx' flag drains it, leaving -- normal mode on a new empty line. - helpers.feedkeys("Asecond bullet") - helpers.feedkeys("inot a bullet") + helpers.feedkeys 'Asecond bullet' + helpers.feedkeys 'inot a bullet' assert.are.same({ - "# Hello there", - "zy. this is the first bullet", - "zz. second bullet", - "not a bullet", + '# Hello there', + 'zy. this is the first bullet', + 'zz. second bullet', + 'not a bullet', }, helpers.get_lines()) end) - active_it("does not bullets if configured as 0", function() - require("bullets").setup({ max_alpha_characters = 0 }) - helpers.new_buffer({ - "# Hello there", - "a. this is the first bullet", - }) + it('does not bullets if configured as 0', function() + require('bullets').setup { max_alpha_characters = 0 } + helpers.new_buffer { + '# Hello there', + 'a. this is the first bullet', + } -- With max=0, alpha bullets are disabled entirely so "a." is not -- recognized as a bullet → CR defers via feedkeys('n') - helpers.feedkeys("A") - helpers.feedkeys("inot a bullet") + helpers.feedkeys 'A' + helpers.feedkeys 'inot a bullet' assert.are.same({ - "# Hello there", - "a. this is the first bullet", - "not a bullet", + '# Hello there', + 'a. this is the first bullet', + 'not a bullet', }, helpers.get_lines()) end) end) diff --git a/test/asciidoc_spec.lua b/test/asciidoc_spec.lua index f442157..58d4b4d 100644 --- a/test/asciidoc_spec.lua +++ b/test/asciidoc_spec.lua @@ -1,29 +1,27 @@ -local helpers = require("test.helpers") -local active_it = it -local it = pending +local helpers = require 'test.helpers' -describe("AsciiDoc", function() +describe('AsciiDoc', function() before_each(function() helpers.reset_config() end) - active_it("maintains indentation in ascii doc bullets", function() + it('maintains indentation in ascii doc bullets', function() helpers.test_bullet_inserted( - "rats", - { "= Pets!", "* dogs", "** cats" }, - { "= Pets!", "* dogs", "** cats", "** rats" } + 'rats', + { '= Pets!', '* dogs', '** cats' }, + { '= Pets!', '* dogs', '** cats', '** rats' } ) end) - active_it("supports dot bullets", function() - helpers.test_bullet_inserted("cats", { "= Pets!", ". dogs" }, { "= Pets!", ". dogs", ". cats" }) + it('supports dot bullets', function() + helpers.test_bullet_inserted('cats', { '= Pets!', '. dogs' }, { '= Pets!', '. dogs', '. cats' }) end) - active_it("supports nested dot bullets", function() + it('supports nested dot bullets', function() helpers.test_bullet_inserted( - "rats", - { "= Pets!", ". dogs", ".. cats" }, - { "= Pets!", ". dogs", ".. cats", ".. rats" } + 'rats', + { '= Pets!', '. dogs', '.. cats' }, + { '= Pets!', '. dogs', '.. cats', '.. rats' } ) end) end) diff --git a/test/bullets_spec.lua b/test/bullets_spec.lua index f9085c0..c3c16b9 100644 --- a/test/bullets_spec.lua +++ b/test/bullets_spec.lua @@ -1,385 +1,383 @@ -local helpers = require("test.helpers") -local active_it = it -local it = pending +local helpers = require 'test.helpers' -describe("Bullets.vim", function() - describe("inserting new bullets", function() +describe('Bullets.vim', function() + describe('inserting new bullets', function() before_each(function() helpers.reset_config() vim.o.ignorecase = false end) - describe("on return key when cursor is not at EOL", function() - active_it("splits the line and does not add a bullet", function() + describe('on return key when cursor is not at EOL', function() + it('splits the line and does not add a bullet', function() -- G$i places cursor on last char 't' in "- this is the first bullet" -- i inserts before 't', CR is deferred (not at EOL), splits the line -- then "second bullet" is typed before 't': "second bullett" -- Temporarily disable formatoptions 'r' to avoid comment-leader insertion local saved_fo = vim.o.formatoptions - vim.cmd("set formatoptions-=r") - helpers.new_buffer({ - "# Hello there", - "- this is the first bullet", - }) + vim.cmd 'set formatoptions-=r' + helpers.new_buffer { + '# Hello there', + '- this is the first bullet', + } -- Position cursor on 't' (last char, 0-indexed col 25), enter insert before it -- CR is deferred by plugin (not at EOL); 'x' flag drains the deferred CR → split -- We end up in normal mode on new line with 't' - helpers.feedkeys("G$i") + helpers.feedkeys 'G$i' -- Now in normal mode at col 0 of "t"; insert before 't' and type - helpers.feedkeys("isecond bullet") + helpers.feedkeys 'isecond bullet' vim.o.formatoptions = saved_fo assert.are.same({ - "# Hello there", - "- this is the first bulle", - "second bullett", + '# Hello there', + '- this is the first bulle', + 'second bullett', }, helpers.get_lines()) end) end) - describe("on return key when cursor is at EOL", function() - active_it("adds a new bullet if the previous line had a known bullet type", function() + describe('on return key when cursor is at EOL', function() + it('adds a new bullet if the previous line had a known bullet type', function() helpers.test_bullet_inserted( - "do that", - { "# Hello there", "- do this" }, - { "# Hello there", "- do this", "- do that" } + 'do that', + { '# Hello there', '- do this' }, + { '# Hello there', '- do this', '- do that' } ) end) - active_it("adds a new latex bullet", function() - helpers.test_bullet_inserted("Second item", { - "\\documentclass{article}", - " \\begin{document}", - "", - " \\begin{itemize}", - " \\item First item", + it('adds a new latex bullet', function() + helpers.test_bullet_inserted('Second item', { + '\\documentclass{article}', + ' \\begin{document}', + '', + ' \\begin{itemize}', + ' \\item First item', }, { - "\\documentclass{article}", - " \\begin{document}", - "", - " \\begin{itemize}", - " \\item First item", - " \\item Second item", + '\\documentclass{article}', + ' \\begin{document}', + '', + ' \\begin{itemize}', + ' \\item First item', + ' \\item Second item', }) end) - active_it("adds a pandoc bullet if the prev line had one", function() + it('adds a pandoc bullet if the prev line had one', function() helpers.test_bullet_inserted( - "second bullet", - { "Hello there", "#. this is the first bullet" }, - { "Hello there", "#. this is the first bullet", "#. second bullet" } + 'second bullet', + { 'Hello there', '#. this is the first bullet' }, + { 'Hello there', '#. this is the first bullet', '#. second bullet' } ) end) - active_it("adds an Org mode bullet if the prev line had one", function() + it('adds an Org mode bullet if the prev line had one', function() helpers.test_bullet_inserted( - "second bullet", - { "Hello there", "**** this is the first bullet" }, - { "Hello there", "**** this is the first bullet", "**** second bullet" } + 'second bullet', + { 'Hello there', '**** this is the first bullet' }, + { 'Hello there', '**** this is the first bullet', '**** second bullet' } ) end) - active_it("adds a new numeric bullet if the previous line had numeric bullet", function() + it('adds a new numeric bullet if the previous line had numeric bullet', function() helpers.test_bullet_inserted( - "second bullet", - { "# Hello there", "1) this is the first bullet" }, - { "# Hello there", "1) this is the first bullet", "2) second bullet" } + 'second bullet', + { '# Hello there', '1) this is the first bullet' }, + { '# Hello there', '1) this is the first bullet', '2) second bullet' } ) end) - active_it("adds a new numeric bullet with right padding", function() + it('adds a new numeric bullet with right padding', function() helpers.test_bullet_inserted( - "second bullet", - { "# Hello there", "1. this is the first bullet" }, - { "# Hello there", "1. this is the first bullet", "2. second bullet" } + 'second bullet', + { '# Hello there', '1. this is the first bullet' }, + { '# Hello there', '1. this is the first bullet', '2. second bullet' } ) end) - active_it("maintains total bullet width from 9. to 10. with reduced padding", function() - require("bullets").setup({ renumber_on_change = false }) + it('maintains total bullet width from 9. to 10. with reduced padding', function() + require('bullets').setup { renumber_on_change = false } helpers.test_bullet_inserted( - "second bullet", - { "# Hello there", "9. this is the first bullet" }, - { "# Hello there", "9. this is the first bullet", "10. second bullet" } + 'second bullet', + { '# Hello there', '9. this is the first bullet' }, + { '# Hello there', '9. this is the first bullet', '10. second bullet' } ) end) - active_it("adds a new - bullet with right padding", function() + it('adds a new - bullet with right padding', function() helpers.test_bullet_inserted( - "second bullet", - { "# Hello there", "- this is the first bullet" }, - { "# Hello there", "- this is the first bullet", "- second bullet" } + 'second bullet', + { '# Hello there', '- this is the first bullet' }, + { '# Hello there', '- this is the first bullet', '- second bullet' } ) end) - active_it("does not insert a new numeric bullet for decimal numbers", function() + it('does not insert a new numeric bullet for decimal numbers', function() -- "3.14159 is an approximation of pi." is not a bullet line -- CR on non-bullet line is deferred, use two-call pattern - helpers.new_buffer({ - "# Hello there", - "3.14159 is an approximation of pi.", - }) - helpers.feedkeys("A") - helpers.feedkeys("isecond line") + helpers.new_buffer { + '# Hello there', + '3.14159 is an approximation of pi.', + } + helpers.feedkeys 'A' + helpers.feedkeys 'isecond line' assert.are.same({ - "# Hello there", - "3.14159 is an approximation of pi.", - "second line", + '# Hello there', + '3.14159 is an approximation of pi.', + 'second line', }, helpers.get_lines()) end) - active_it("adds a new roman numeral bullet", function() - require("bullets").setup({ pad_right = false }) - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - }) - helpers.feedkeys("Asecond bulletthird bulletfourth bulletfifth bullet") + it('adds a new roman numeral bullet', function() + require('bullets').setup { pad_right = false } + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + } + helpers.feedkeys 'Asecond bulletthird bulletfourth bulletfifth bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "II. second bullet", - "III. third bullet", - "IV. fourth bullet", - "V. fifth bullet", + '# Hello there', + 'I. this is the first bullet', + 'II. second bullet', + 'III. third bullet', + 'IV. fourth bullet', + 'V. fifth bullet', }, helpers.get_lines()) end) - active_it("adds a new lowercase roman numeral bullet", function() - require("bullets").setup({ pad_right = false }) - helpers.new_buffer({ - "# Hello there", - "i. this is the first bullet", - }) - helpers.feedkeys("Asecond bulletthird bulletfourth bulletfifth bullet") + it('adds a new lowercase roman numeral bullet', function() + require('bullets').setup { pad_right = false } + helpers.new_buffer { + '# Hello there', + 'i. this is the first bullet', + } + helpers.feedkeys 'Asecond bulletthird bulletfourth bulletfifth bullet' assert.are.same({ - "# Hello there", - "i. this is the first bullet", - "ii. second bullet", - "iii. third bullet", - "iv. fourth bullet", - "v. fifth bullet", + '# Hello there', + 'i. this is the first bullet', + 'ii. second bullet', + 'iii. third bullet', + 'iv. fourth bullet', + 'v. fifth bullet', }, helpers.get_lines()) end) - active_it("does not confuse with the 'ignorecase' option", function() - vim.cmd("set ignorecase") + it("does not confuse with the 'ignorecase' option", function() + vim.cmd 'set ignorecase' -- "Vi." is mixed case / not a valid roman numeral bullet → non-bullet CR - helpers.new_buffer({ - "# Hello there", - "Vi. this is the first line", - }) - helpers.feedkeys("A") - helpers.feedkeys("isecond line") + helpers.new_buffer { + '# Hello there', + 'Vi. this is the first line', + } + helpers.feedkeys 'A' + helpers.feedkeys 'isecond line' assert.are.same({ - "# Hello there", - "Vi. this is the first line", - "second line", + '# Hello there', + 'Vi. this is the first line', + 'second line', }, helpers.get_lines()) end) - active_it("does not insert a new roman bullets without following spaces", function() + it('does not insert a new roman bullets without following spaces', function() -- "m.example.com is a site." has no space after the dot → not a bullet - helpers.new_buffer({ - "# Hello there", - "m.example.com is a site.", - }) - helpers.feedkeys("A") - helpers.feedkeys("isecond line") + helpers.new_buffer { + '# Hello there', + 'm.example.com is a site.', + } + helpers.feedkeys 'A' + helpers.feedkeys 'isecond line' assert.are.same({ - "# Hello there", - "m.example.com is a site.", - "second line", + '# Hello there', + 'm.example.com is a site.', + 'second line', }, helpers.get_lines()) end) - active_it("does not insert a new roman bullets for invalid roman numbers", function() + it('does not insert a new roman bullets for invalid roman numbers', function() -- "LID." is not a valid roman numeral, so no bullet continuation -- However lines typed after non-bullet lines also get no bullet - helpers.new_buffer({ - "# Hello there", - "LID. the first line", - }) + helpers.new_buffer { + '# Hello there', + 'LID. the first line', + } -- First CR after "LID. the first line" (non-bullet) → deferred - helpers.feedkeys("A") - helpers.feedkeys("isecond line") + helpers.feedkeys 'A' + helpers.feedkeys 'isecond line' -- Now on "second line" (non-bullet) → deferred CR - helpers.feedkeys("A") - helpers.feedkeys("ivim. third line") + helpers.feedkeys 'A' + helpers.feedkeys 'ivim. third line' -- Now on "vim. third line" (non-bullet) → deferred CR - helpers.feedkeys("A") - helpers.feedkeys("ifourth line") + helpers.feedkeys 'A' + helpers.feedkeys 'ifourth line' assert.are.same({ - "# Hello there", - "LID. the first line", - "second line", - "vim. third line", - "fourth line", + '# Hello there', + 'LID. the first line', + 'second line', + 'vim. third line', + 'fourth line', }, helpers.get_lines()) end) - active_it("deletes the last bullet if it is empty", function() - require("bullets").setup({ delete_last_bullet_if_empty = 1 }) - helpers.new_buffer({ - "# Hello there", - "- this is the first bullet", - }) + it('deletes the last bullet if it is empty', function() + require('bullets').setup { delete_last_bullet_if_empty = 1 } + helpers.new_buffer { + '# Hello there', + '- this is the first bullet', + } -- First CR creates "- " empty bullet, second CR on empty bullet deletes it - helpers.feedkeys("A") + helpers.feedkeys 'A' local lines = helpers.get_lines() -- Strip trailing empty lines before comparison. - while #lines > 0 and lines[#lines] == "" do + while #lines > 0 and lines[#lines] == '' do table.remove(lines) end assert.are.same({ - "# Hello there", - "- this is the first bullet", + '# Hello there', + '- this is the first bullet', }, lines) end) - active_it("promotes the last bullet when configured to", function() - require("bullets").setup({ delete_last_bullet_if_empty = 2 }) - helpers.new_buffer({ - "# Hello there", - "- this is the first bullet", - " - this is the second bullet", - }) + it('promotes the last bullet when configured to', function() + require('bullets').setup { delete_last_bullet_if_empty = 2 } + helpers.new_buffer { + '# Hello there', + '- this is the first bullet', + ' - this is the second bullet', + } -- First CR creates new child bullet " - ", second CR promotes (dedents) - helpers.feedkeys("A") + helpers.feedkeys 'A' local lines = helpers.get_lines() -- strip trailing empty lines - while #lines > 0 and lines[#lines] == "" do + while #lines > 0 and lines[#lines] == '' do table.remove(lines) end -- The promoted bullet has a trailing space ("- ") matching plugin output assert.are.same({ - "# Hello there", - "- this is the first bullet", - " - this is the second bullet", - "- ", + '# Hello there', + '- this is the first bullet', + ' - this is the second bullet', + '- ', }, lines) end) - active_it("does not delete the last bullet when configured not to", function() - require("bullets").setup({ delete_last_bullet_if_empty = 0 }) - helpers.new_buffer({ - "# Hello there", - "- this is the first bullet", - }) + it('does not delete the last bullet when configured not to', function() + require('bullets').setup { delete_last_bullet_if_empty = 0 } + helpers.new_buffer { + '# Hello there', + '- this is the first bullet', + } -- First CR creates "- " empty bullet, second CR on empty bullet -- with config=0 does NOT delete it; a plain CR fires leaving "- " intact - helpers.feedkeys("A") + helpers.feedkeys 'A' local lines = helpers.get_lines() -- strip trailing empty lines - while #lines > 0 and lines[#lines] == "" do + while #lines > 0 and lines[#lines] == '' do table.remove(lines) end -- The non-deleted bullet retains trailing space ("- ") matching plugin output assert.are.same({ - "# Hello there", - "- this is the first bullet", - "- ", + '# Hello there', + '- this is the first bullet', + '- ', }, lines) end) - active_it("adds configured blank spacing before the next bullet", function() - require("bullets").setup({ line_spacing = 2 }) - helpers.test_bullet_inserted("second bullet", { - "# Hello there", - "1. first bullet", + it('adds configured blank spacing before the next bullet', function() + require('bullets').setup { line_spacing = 2 } + helpers.test_bullet_inserted('second bullet', { + '# Hello there', + '1. first bullet', }, { - "# Hello there", - "1. first bullet", - "", - "2. second bullet", + '# Hello there', + '1. first bullet', + '', + '2. second bullet', }) end) - active_it("can disable right padding for ordered bullets", function() - require("bullets").setup({ pad_right = false }) - helpers.test_bullet_inserted("second bullet", { - "# Hello there", - "9. first bullet", + it('can disable right padding for ordered bullets', function() + require('bullets').setup { pad_right = false } + helpers.test_bullet_inserted('second bullet', { + '# Hello there', + '9. first bullet', }, { - "# Hello there", - "9. first bullet", - "10. second bullet", + '# Hello there', + '9. first bullet', + '10. second bullet', }) end) - active_it("indents after a line ending in a colon", function() - require("bullets").setup({ auto_indent_after_colon = true }) - helpers.new_buffer({ - "# Hello there", - "a. first bullet", - }) - helpers.feedkeys("Asecond bullet:third bulletfourth bullet") + it('indents after a line ending in a colon', function() + require('bullets').setup { auto_indent_after_colon = true } + helpers.new_buffer { + '# Hello there', + 'a. first bullet', + } + helpers.feedkeys 'Asecond bullet:third bulletfourth bullet' assert.are.same({ - "# Hello there", - "a. first bullet", - "b. second bullet:", - " i. third bullet", - " ii. fourth bullet", + '# Hello there', + 'a. first bullet', + 'b. second bullet:', + ' i. third bullet', + ' ii. fourth bullet', }, helpers.get_lines()) end) - active_it("indents after a line ending in a fullwidth colon", function() - require("bullets").setup({ auto_indent_after_colon = true }) - helpers.new_buffer({ - "# Hello there", - "a. first bullet", - }) - helpers.feedkeys("Asecond bullet:third bullet") + it('indents after a line ending in a fullwidth colon', function() + require('bullets').setup { auto_indent_after_colon = true } + helpers.new_buffer { + '# Hello there', + 'a. first bullet', + } + helpers.feedkeys 'Asecond bullet:third bullet' assert.are.same({ - "# Hello there", - "a. first bullet", - "b. second bullet:", - " i. third bullet", + '# Hello there', + 'a. first bullet', + 'b. second bullet:', + ' i. third bullet', }, helpers.get_lines()) end) - active_it("can disable colon auto indentation", function() - require("bullets").setup({ auto_indent_after_colon = false }) - helpers.test_bullet_inserted("second bullet:", { - "# Hello there", - "a. first bullet", + it('can disable colon auto indentation', function() + require('bullets').setup { auto_indent_after_colon = false } + helpers.test_bullet_inserted('second bullet:', { + '# Hello there', + 'a. first bullet', }, { - "# Hello there", - "a. first bullet", - "b. second bullet:", + '# Hello there', + 'a. first bullet', + 'b. second bullet:', }) - helpers.feedkeys("Athird bullet") + helpers.feedkeys 'Athird bullet' assert.are.same({ - "# Hello there", - "a. first bullet", - "b. second bullet:", - "c. third bullet", + '# Hello there', + 'a. first bullet', + 'b. second bullet:', + 'c. third bullet', }, helpers.get_lines()) end) - active_it("toggles roman numeral bullets with enable_roman_list", function() + it('toggles roman numeral bullets with enable_roman_list', function() -- Disable alpha lists to isolate test to roman numerals - require("bullets").setup({ max_alpha_characters = 0, enable_roman_list = true }) - helpers.new_buffer({ - "# Hello there", - "i. this is the first bullet", - }) + require('bullets').setup { max_alpha_characters = 0, enable_roman_list = true } + helpers.new_buffer { + '# Hello there', + 'i. this is the first bullet', + } -- Type second and third bullets (roman numeral bullets) - helpers.feedkeys("Asecond bulletthird bullet") + helpers.feedkeys 'Asecond bulletthird bullet' -- Disable roman list mid-test - require("bullets").setup({ max_alpha_characters = 0, enable_roman_list = false }) + require('bullets').setup { max_alpha_characters = 0, enable_roman_list = false } -- Type fourth and fifth (no roman numeral prefix now) -- We're in normal mode, need to append and continue - helpers.feedkeys("A") - helpers.feedkeys("ifourth bullet") - helpers.feedkeys("A") - helpers.feedkeys("ififth bullet") + helpers.feedkeys 'A' + helpers.feedkeys 'ifourth bullet' + helpers.feedkeys 'A' + helpers.feedkeys 'ififth bullet' assert.are.same({ - "# Hello there", - "i. this is the first bullet", - "ii. second bullet", - "iii. third bullet", - "fourth bullet", - "fifth bullet", + '# Hello there', + 'i. this is the first bullet', + 'ii. second bullet', + 'iii. third bullet', + 'fourth bullet', + 'fifth bullet', }, helpers.get_lines()) end) end) diff --git a/test/checkboxes_spec.lua b/test/checkboxes_spec.lua index b69d76f..dc65b83 100644 --- a/test/checkboxes_spec.lua +++ b/test/checkboxes_spec.lua @@ -1,343 +1,343 @@ -local helpers = require("test.helpers") +local helpers = require 'test.helpers' -describe("checkboxes", function() - describe("inserting checkboxes", function() - it("inserts another checkbox after the previous one", function() +describe('checkboxes', function() + describe('inserting checkboxes', function() + it('inserts another checkbox after the previous one', function() helpers.test_bullet_inserted( - "do that", - { "# Hello there", "- [ ] do this" }, - { "# Hello there", "- [ ] do this", "- [ ] do that" } + 'do that', + { '# Hello there', '- [ ] do this' }, + { '# Hello there', '- [ ] do this', '- [ ] do that' } ) end) - it("inserts a * checkbox after the previous one", function() + it('inserts a * checkbox after the previous one', function() helpers.test_bullet_inserted( - "do that", - { "# Hello there", "* [ ] do this" }, - { "# Hello there", "* [ ] do this", "* [ ] do that" } + 'do that', + { '# Hello there', '* [ ] do this' }, + { '# Hello there', '* [ ] do this', '* [ ] do that' } ) end) - it("inserts an empty checkbox even if prev line was checked", function() + it('inserts an empty checkbox even if prev line was checked', function() helpers.test_bullet_inserted( - "do that", - { "# Hello there", "- [x] do this" }, - { "# Hello there", "- [x] do this", "- [ ] do that" } + 'do that', + { '# Hello there', '- [x] do this' }, + { '# Hello there', '- [x] do this', '- [ ] do that' } ) end) end) - describe("toggling checkboxes", function() + describe('toggling checkboxes', function() before_each(function() helpers.reset_config() end) - it("toggle a bullet", function() - helpers.new_buffer({ - "# Hello there", - "- [ ] first bullet", - "- [X] second bullet", - "- [x] third bullet", - "- [.] fourth bullet", - "- [o] fifth bullet", - "- [O] sixth bullet", - "- not a checkbox", - }) + it('toggle a bullet', function() + helpers.new_buffer { + '# Hello there', + '- [ ] first bullet', + '- [X] second bullet', + '- [x] third bullet', + '- [.] fourth bullet', + '- [o] fifth bullet', + '- [O] sixth bullet', + '- not a checkbox', + } -- Move to line 2 (first bullet line), then toggle each - helpers.feedkeys("gg") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") + helpers.feedkeys 'gg' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' assert.are.same({ - "# Hello there", - "- [X] first bullet", - "- [ ] second bullet", - "- [ ] third bullet", - "- [X] fourth bullet", - "- [X] fifth bullet", - "- [X] sixth bullet", - "- not a checkbox", + '# Hello there', + '- [X] first bullet', + '- [ ] second bullet', + '- [ ] third bullet', + '- [X] fourth bullet', + '- [X] fifth bullet', + '- [X] sixth bullet', + '- not a checkbox', }, helpers.get_lines()) end) - it("toggle a bullet and adjust parent", function() - helpers.new_buffer({ - "# Hello there", - "- [ ] first bullet", - " - [ ] second bullet", - " - [ ] third bullet", - }) - helpers.feedkeys("G") - vim.cmd("ToggleCheckbox") + it('toggle a bullet and adjust parent', function() + helpers.new_buffer { + '# Hello there', + '- [ ] first bullet', + ' - [ ] second bullet', + ' - [ ] third bullet', + } + helpers.feedkeys 'G' + vim.cmd 'ToggleCheckbox' assert.are.same({ - "# Hello there", - "- [X] first bullet", - " - [X] second bullet", - " - [X] third bullet", + '# Hello there', + '- [X] first bullet', + ' - [X] second bullet', + ' - [X] third bullet', }, helpers.get_lines()) end) - it("toggle a bullet and adjust children", function() - helpers.new_buffer({ - "# Hello there", - "- [ ] first bullet", - " - [ ] second bullet", - " - [ ] third bullet", - }) - helpers.feedkeys("ggj") - vim.cmd("ToggleCheckbox") + it('toggle a bullet and adjust children', function() + helpers.new_buffer { + '# Hello there', + '- [ ] first bullet', + ' - [ ] second bullet', + ' - [ ] third bullet', + } + helpers.feedkeys 'ggj' + vim.cmd 'ToggleCheckbox' assert.are.same({ - "# Hello there", - "- [X] first bullet", - " - [X] second bullet", - " - [X] third bullet", + '# Hello there', + '- [X] first bullet', + ' - [X] second bullet', + ' - [X] third bullet', }, helpers.get_lines()) end) - it("does not toggle checkboxes after a blank separator", function() - helpers.new_buffer({ - "# Hello there", - "- [ ] first bullet", - " - [ ] second bullet", - "", - " - [ ] separate bullet", - }) - helpers.feedkeys("ggj") - vim.cmd("ToggleCheckbox") + it('does not toggle checkboxes after a blank separator', function() + helpers.new_buffer { + '# Hello there', + '- [ ] first bullet', + ' - [ ] second bullet', + '', + ' - [ ] separate bullet', + } + helpers.feedkeys 'ggj' + vim.cmd 'ToggleCheckbox' assert.are.same({ - "# Hello there", - "- [X] first bullet", - " - [X] second bullet", - "", - " - [ ] separate bullet", + '# Hello there', + '- [X] first bullet', + ' - [X] second bullet', + '', + ' - [ ] separate bullet', }, helpers.get_lines()) end) - it("toggle a bullet and calculate completion", function() - helpers.new_buffer({ - "# Hello there", - "- [ ] first bullet", - " - [ ] second bullet", - " - [ ] third bullet", - " - [ ] fourth bullet", - " - [ ] fifth bullet", - " - [ ] sixth bullet", - " - [ ] seventh bullet", - " - [ ] eighth bullet", - " - [ ] ninth bullet", - " - [ ] tenth bullet", - " - [ ] eleventh bullet", - " - [ ] twelfth bullet", - " - [ ] thirteenth bullet", - " - [ ] fourteenth bullet", - " - [ ] fifteenth bullet", - " - [ ] sixteenth bullet", - " - [X] seventeenth bullet", - " - [X] eighteenth bullet", - " - [X] ninteenth bullet", - " - [X] twentieth bullet", - " - [X] twenty-first bullet", - }) + it('toggle a bullet and calculate completion', function() + helpers.new_buffer { + '# Hello there', + '- [ ] first bullet', + ' - [ ] second bullet', + ' - [ ] third bullet', + ' - [ ] fourth bullet', + ' - [ ] fifth bullet', + ' - [ ] sixth bullet', + ' - [ ] seventh bullet', + ' - [ ] eighth bullet', + ' - [ ] ninth bullet', + ' - [ ] tenth bullet', + ' - [ ] eleventh bullet', + ' - [ ] twelfth bullet', + ' - [ ] thirteenth bullet', + ' - [ ] fourteenth bullet', + ' - [ ] fifteenth bullet', + ' - [ ] sixteenth bullet', + ' - [X] seventeenth bullet', + ' - [X] eighteenth bullet', + ' - [X] ninteenth bullet', + ' - [X] twentieth bullet', + ' - [X] twenty-first bullet', + } -- cursor starts at last line (line 21), go to line 4 (3j from top = line 4) -- new_buffer places cursor at last line, so we need to go to line 4 - helpers.feedkeys("gg") - helpers.feedkeys("3j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("6j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("2j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") - helpers.feedkeys("2j") - vim.cmd("ToggleCheckbox") + helpers.feedkeys 'gg' + helpers.feedkeys '3j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys '6j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys '2j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' + helpers.feedkeys '2j' + vim.cmd 'ToggleCheckbox' assert.are.same({ - "# Hello there", - "- [.] first bullet", - " - [.] second bullet", - " - [X] third bullet", - " - [ ] fourth bullet", - " - [ ] fifth bullet", - " - [ ] sixth bullet", - " - [O] seventh bullet", - " - [ ] eighth bullet", - " - [X] ninth bullet", - " - [X] tenth bullet", - " - [X] eleventh bullet", - " - [X] twelfth bullet", - " - [X] thirteenth bullet", - " - [X] fourteenth bullet", - " - [X] fifteenth bullet", - " - [X] sixteenth bullet", - " - [O] seventeenth bullet", - " - [ ] eighteenth bullet", - " - [X] ninteenth bullet", - " - [X] twentieth bullet", - " - [X] twenty-first bullet", + '# Hello there', + '- [.] first bullet', + ' - [.] second bullet', + ' - [X] third bullet', + ' - [ ] fourth bullet', + ' - [ ] fifth bullet', + ' - [ ] sixth bullet', + ' - [O] seventh bullet', + ' - [ ] eighth bullet', + ' - [X] ninth bullet', + ' - [X] tenth bullet', + ' - [X] eleventh bullet', + ' - [X] twelfth bullet', + ' - [X] thirteenth bullet', + ' - [X] fourteenth bullet', + ' - [X] fifteenth bullet', + ' - [X] sixteenth bullet', + ' - [O] seventeenth bullet', + ' - [ ] eighteenth bullet', + ' - [X] ninteenth bullet', + ' - [X] twentieth bullet', + ' - [X] twenty-first bullet', }, helpers.get_lines()) end) - it("adds and toggles bullets using UTF characters", function() - require("bullets").setup({ checkbox_markers = "✗○◐●✓" }) + it('adds and toggles bullets using UTF characters', function() + require('bullets').setup { checkbox_markers = '✗○◐●✓' } -- Ensure produces tabs (not spaces) regardless of user config vim.opt.expandtab = false - helpers.new_buffer({ - "# Hello there", - "- [ ] first bullet", - }) + helpers.new_buffer { + '# Hello there', + '- [ ] first bullet', + } -- Toggle first bullet (cursor at line 2 already via new_buffer) - helpers.feedkeys("j") - vim.cmd("ToggleCheckbox") + helpers.feedkeys 'j' + vim.cmd 'ToggleCheckbox' -- Open new line and type "second bullet" - helpers.feedkeys("osecond bullet") + helpers.feedkeys 'osecond bullet' -- Open new line with indent and type "third bullet" - helpers.feedkeys("othird bullet") + helpers.feedkeys 'othird bullet' -- Open new line (same indent) and type "fourth bullet", then toggle - helpers.feedkeys("ofourth bullet") - vim.cmd("ToggleCheckbox") + helpers.feedkeys 'ofourth bullet' + vim.cmd 'ToggleCheckbox' -- Open new line with dedent and type "fifth bullet", then toggle - helpers.feedkeys("ofifth bullet") - vim.cmd("ToggleCheckbox") + helpers.feedkeys 'ofifth bullet' + vim.cmd 'ToggleCheckbox' -- Open new line and type "sixth bullet", toggle twice - helpers.feedkeys("osixth bullet") - vim.cmd("ToggleCheckbox") - vim.cmd("ToggleCheckbox") + helpers.feedkeys 'osixth bullet' + vim.cmd 'ToggleCheckbox' + vim.cmd 'ToggleCheckbox' assert.are.same({ - "# Hello there", - "- [✓] first bullet", - "- [◐] second bullet", - "\t- [✗] third bullet", - "\t- [✓] fourth bullet", - "- [✓] fifth bullet", - "- [✗] sixth bullet", + '# Hello there', + '- [✓] first bullet', + '- [◐] second bullet', + '\t- [✗] third bullet', + '\t- [✓] fourth bullet', + '- [✓] fifth bullet', + '- [✗] sixth bullet', }, helpers.get_lines()) end) - it("recomputes checkboxes recursively on RecomputeCheckboxes", function() - require("bullets").setup({ checkbox_markers = " .¼½¾X" }) - helpers.new_buffer({ - "# Hello there", - "- [ ] EXPECTED: ¼", - " - [X] checkbox leaf", - " - [ ] EXPECTED: CHECKED", - " - [ ] EXPECTED: CHECKED", - " - [ ] EXPECTED: CHECKED", - " - [X] checkbox leaf", - " - [X] checkbox leaf", - " - [X] EXPECTED: ¾", - " - [X] checkbox leaf", - " - [X] checkbox leaf", - " - [X] checkbox leaf", - " - [ ] checkbox leaf", - " - [X] EXPECTED: ½", - " - [ ] EXPECTED: CHECKED", - " - [ ] EXPECTED: CHECKED", - " - [X] checkbox leaf", - " - [½] checkbox leaf (EXPECTED: UNCHECKED)", - " - [½] EXPECTED: UNCHECKED", - " - [ ] checkbox leaf", - " - [½] checkbox leaf (EXPECTED: UNCHECKED)", - }) - helpers.feedkeys("gg") - helpers.feedkeys("9j") - vim.cmd("RecomputeCheckboxes") + it('recomputes checkboxes recursively on RecomputeCheckboxes', function() + require('bullets').setup { checkbox_markers = ' .¼½¾X' } + helpers.new_buffer { + '# Hello there', + '- [ ] EXPECTED: ¼', + ' - [X] checkbox leaf', + ' - [ ] EXPECTED: CHECKED', + ' - [ ] EXPECTED: CHECKED', + ' - [ ] EXPECTED: CHECKED', + ' - [X] checkbox leaf', + ' - [X] checkbox leaf', + ' - [X] EXPECTED: ¾', + ' - [X] checkbox leaf', + ' - [X] checkbox leaf', + ' - [X] checkbox leaf', + ' - [ ] checkbox leaf', + ' - [X] EXPECTED: ½', + ' - [ ] EXPECTED: CHECKED', + ' - [ ] EXPECTED: CHECKED', + ' - [X] checkbox leaf', + ' - [½] checkbox leaf (EXPECTED: UNCHECKED)', + ' - [½] EXPECTED: UNCHECKED', + ' - [ ] checkbox leaf', + ' - [½] checkbox leaf (EXPECTED: UNCHECKED)', + } + helpers.feedkeys 'gg' + helpers.feedkeys '9j' + vim.cmd 'RecomputeCheckboxes' assert.are.same({ - "# Hello there", - "- [¼] EXPECTED: ¼", - " - [X] checkbox leaf", - " - [X] EXPECTED: CHECKED", - " - [X] EXPECTED: CHECKED", - " - [X] EXPECTED: CHECKED", - " - [X] checkbox leaf", - " - [X] checkbox leaf", - " - [¾] EXPECTED: ¾", - " - [X] checkbox leaf", - " - [X] checkbox leaf", - " - [X] checkbox leaf", - " - [ ] checkbox leaf", - " - [½] EXPECTED: ½", - " - [X] EXPECTED: CHECKED", - " - [X] EXPECTED: CHECKED", - " - [X] checkbox leaf", - " - [ ] checkbox leaf (EXPECTED: UNCHECKED)", - " - [ ] EXPECTED: UNCHECKED", - " - [ ] checkbox leaf", - " - [ ] checkbox leaf (EXPECTED: UNCHECKED)", + '# Hello there', + '- [¼] EXPECTED: ¼', + ' - [X] checkbox leaf', + ' - [X] EXPECTED: CHECKED', + ' - [X] EXPECTED: CHECKED', + ' - [X] EXPECTED: CHECKED', + ' - [X] checkbox leaf', + ' - [X] checkbox leaf', + ' - [¾] EXPECTED: ¾', + ' - [X] checkbox leaf', + ' - [X] checkbox leaf', + ' - [X] checkbox leaf', + ' - [ ] checkbox leaf', + ' - [½] EXPECTED: ½', + ' - [X] EXPECTED: CHECKED', + ' - [X] EXPECTED: CHECKED', + ' - [X] checkbox leaf', + ' - [ ] checkbox leaf (EXPECTED: UNCHECKED)', + ' - [ ] EXPECTED: UNCHECKED', + ' - [ ] checkbox leaf', + ' - [ ] checkbox leaf (EXPECTED: UNCHECKED)', }, helpers.get_lines()) end) - it("recomputes checkboxes correctly on reindents", function() - require("bullets").setup({ checkbox_markers = " /X" }) - helpers.new_buffer({ - "# Hello there", - "- [X] parent bullet", - " - [X] first child bullet", - }) + it('recomputes checkboxes correctly on reindents', function() + require('bullets').setup { checkbox_markers = ' /X' } + helpers.new_buffer { + '# Hello there', + '- [X] parent bullet', + ' - [X] first child bullet', + } -- Press CR at end of last line to add a new child bullet - helpers.feedkeys("GA") - vim.cmd("RecomputeCheckboxes") + helpers.feedkeys 'GA' + vim.cmd 'RecomputeCheckboxes' assert.are.same({ - "# Hello there", - "- [/] parent bullet", - " - [X] first child bullet", - " - [ ] ", + '# Hello there', + '- [/] parent bullet', + ' - [X] first child bullet', + ' - [ ] ', }, helpers.get_lines()) -- Phase 2: press CR on the new empty bullet, which should dedent/remove it - require("bullets").setup({ checkbox_markers = " /X", delete_last_bullet_if_empty = 2 }) - helpers.feedkeys("A") - vim.cmd("RecomputeCheckboxes") + require('bullets').setup { checkbox_markers = ' /X', delete_last_bullet_if_empty = 2 } + helpers.feedkeys 'A' + vim.cmd 'RecomputeCheckboxes' assert.are.same({ - "# Hello there", - "- [X] parent bullet", - " - [X] first child bullet", - "- [ ] ", + '# Hello there', + '- [X] parent bullet', + ' - [X] first child bullet', + '- [ ] ', }, helpers.get_lines()) end) - it("handles skip-level checkbox trees", function() - require("bullets").setup({ checkbox_markers = " /X" }) - helpers.new_buffer({ - "# Hello there", - "- [X] parent bullet (EXPECTED: /)", - " - skip: not checkbox content", - " - [ ] new root bullet (EXPECTED: /)", - " - [ ] first child bullet", - " - [X] first child bullet", - " - [X] first child bullet", - " - [ ] first child bullet", - }) - helpers.feedkeys("gg") - helpers.feedkeys("2j") - vim.cmd("RecomputeCheckboxes") + it('handles skip-level checkbox trees', function() + require('bullets').setup { checkbox_markers = ' /X' } + helpers.new_buffer { + '# Hello there', + '- [X] parent bullet (EXPECTED: /)', + ' - skip: not checkbox content', + ' - [ ] new root bullet (EXPECTED: /)', + ' - [ ] first child bullet', + ' - [X] first child bullet', + ' - [X] first child bullet', + ' - [ ] first child bullet', + } + helpers.feedkeys 'gg' + helpers.feedkeys '2j' + vim.cmd 'RecomputeCheckboxes' assert.are.same({ - "# Hello there", - "- [/] parent bullet (EXPECTED: /)", - " - skip: not checkbox content", - " - [/] new root bullet (EXPECTED: /)", - " - [ ] first child bullet", - " - [X] first child bullet", - " - [X] first child bullet", - " - [ ] first child bullet", + '# Hello there', + '- [/] parent bullet (EXPECTED: /)', + ' - skip: not checkbox content', + ' - [/] new root bullet (EXPECTED: /)', + ' - [ ] first child bullet', + ' - [X] first child bullet', + ' - [X] first child bullet', + ' - [ ] first child bullet', }, helpers.get_lines()) end) end) diff --git a/test/filetypes_spec.lua b/test/filetypes_spec.lua index 8649f13..93e78b0 100644 --- a/test/filetypes_spec.lua +++ b/test/filetypes_spec.lua @@ -1,21 +1,20 @@ -local helpers = require("test.helpers") -local it = pending +local helpers = require 'test.helpers' -describe("filetypes", function() - it("creates mapping for bullets on empty buffer if configured", function() +describe('filetypes', function() + pending('creates mapping for bullets on empty buffer if configured', function() -- g:bullets_enable_in_empty_buffers defaults to 0, so a new buffer with -- no filetype does NOT get the bullet mapping. - vim.cmd("enew") - vim.cmd("setlocal formatoptions= comments=") -- prevent '#' comment-continuation - helpers.feedkeys("i# Hello there- this is the first bulletthis is the second bullet") - assert.are.same({ "# Hello there", "- this is the first bullet", "this is the second bullet" }, helpers.get_lines()) + vim.cmd 'enew' + vim.cmd 'setlocal formatoptions= comments=' -- prevent '#' comment-continuation + helpers.feedkeys 'i# Hello there- this is the first bulletthis is the second bullet' + assert.are.same({ '# Hello there', '- this is the first bullet', 'this is the second bullet' }, helpers.get_lines()) end) - it("should have text filetype for .txt", function() - local tmpfile = vim.fn.tempname() .. ".txt" - vim.cmd("edit " .. tmpfile) + pending('should have text filetype for .txt', function() + local tmpfile = vim.fn.tempname() .. '.txt' + vim.cmd('edit ' .. tmpfile) local ft = vim.bo.filetype - assert.is_true(ft == "text" or ft == "markdown", "Expected 'text' or 'markdown' filetype, got: " .. tostring(ft)) - vim.cmd("bdelete!") + assert.is_true(ft == 'text' or ft == 'markdown', "Expected 'text' or 'markdown' filetype, got: " .. tostring(ft)) + vim.cmd 'bdelete!' end) end) diff --git a/test/helpers.lua b/test/helpers.lua index 6b5ee8b..761d3ee 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -2,14 +2,14 @@ local M = {} -- Replaces termcodes and feeds keys synchronously (including mapped keys) function M.feedkeys(keys) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), "tx", false) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), 'tx', false) end -- Opens a fresh buffer with the given lines and the 'text' filetype, -- positions the cursor at the end of the last line, and returns the bufnr. function M.new_buffer(lines) - vim.cmd("enew") - vim.bo.filetype = "text" + vim.cmd 'enew' + vim.bo.filetype = 'text' vim.api.nvim_buf_set_lines(0, 0, -1, false, lines) local last = #lines vim.api.nvim_win_set_cursor(0, { last, #lines[last] }) @@ -25,32 +25,32 @@ end -- then asserts the buffer matches expected_lines. function M.test_bullet_inserted(second_bullet, initial_lines, expected_lines) M.new_buffer(initial_lines) - M.feedkeys("A" .. second_bullet) + M.feedkeys('A' .. second_bullet) assert.are.same(expected_lines, M.get_lines()) end -- Resets bullets.nvim to the plugin defaults used by the specs. -- Call in before_each for any describe block that mutates config. function M.reset_config() - require("bullets").setup({ - enabled_file_types = { "markdown", "text", "gitcommit", "scratch" }, + require('bullets').setup { + enabled_file_types = { 'markdown', 'text', 'gitcommit', 'scratch' }, enable_in_empty_buffers = true, set_mappings = true, - mapping_leader = "", + mapping_leader = '', custom_mappings = {}, max_alpha_characters = 2, auto_indent_after_colon = true, line_spacing = 1, renumber_on_change = true, nested_checkboxes = true, - checkbox_markers = " .oOX", + checkbox_markers = ' .oOX', checkbox_partials_toggle = 1, - outline_levels = { "ROM", "ABC", "num", "abc", "rom", "std-", "std*", "std+" }, + outline_levels = { 'ROM', 'ABC', 'num', 'abc', 'rom', 'std-', 'std*', 'std+' }, enable_roman_list = true, enable_wrapped_lines = true, pad_right = true, delete_last_bullet_if_empty = 1, - }) + } end return M diff --git a/test/minimal_init.lua b/test/minimal_init.lua index 630245d..d38f25c 100644 --- a/test/minimal_init.lua +++ b/test/minimal_init.lua @@ -1,16 +1,16 @@ -- Resolve the repo root relative to this file's location -local script_path = debug.getinfo(1, "S").source:sub(2) -- strip leading '@' -local repo_root = vim.fn.fnamemodify(script_path, ":p:h:h") +local script_path = debug.getinfo(1, 'S').source:sub(2) -- strip leading '@' +local repo_root = vim.fn.fnamemodify(script_path, ':p:h:h') -local plenary_path = "/tmp/plenary.nvim" +local plenary_path = '/tmp/plenary.nvim' if not vim.uv.fs_stat(plenary_path) then - vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/nvim-lua/plenary.nvim", plenary_path }) + vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/nvim-lua/plenary.nvim', plenary_path } end vim.opt.rtp:prepend(plenary_path) vim.opt.rtp:prepend(repo_root) -vim.cmd("filetype plugin on") -vim.cmd("runtime plugin/bullets.lua") -vim.cmd("set formatoptions=") -vim.cmd("set noexpandtab") +vim.cmd 'filetype plugin on' +vim.cmd 'runtime plugin/bullets.lua' +vim.cmd 'set formatoptions=' +vim.cmd 'set noexpandtab' diff --git a/test/nested_bullets_spec.lua b/test/nested_bullets_spec.lua index 6aca7be..d85f07a 100644 --- a/test/nested_bullets_spec.lua +++ b/test/nested_bullets_spec.lua @@ -1,9 +1,7 @@ -local helpers = require("test.helpers") -local active_it = it -local pending_it = pending +local helpers = require 'test.helpers' -describe("Bullets.vim", function() - describe("nested bullets", function() +describe('Bullets.vim', function() + describe('nested bullets', function() before_each(function() helpers.reset_config() -- Plugin uses `normal! >>` / `normal! <<` internally which respect shiftwidth/expandtab. @@ -13,618 +11,614 @@ describe("Bullets.vim", function() vim.opt.tabstop = 4 end) - active_it("demotes a bullet one outline level", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "II. second bullet", - }) + it('demotes a bullet one outline level', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + 'II. second bullet', + } - helpers.feedkeys("gg2j>>") + helpers.feedkeys 'gg2j>>' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', }, helpers.get_lines()) end) - active_it("promotes a bullet one outline level", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "\tB. third bullet", - }) + it('promotes a bullet one outline level', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + '\tB. third bullet', + } - helpers.feedkeys("gg3j<<") + helpers.feedkeys 'gg3j<<' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "II. third bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + 'II. third bullet', }, helpers.get_lines()) end) - active_it("demotes an empty bullet", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - }) + it('demotes an empty bullet', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + } - helpers.feedkeys("GAsecond bullet") + helpers.feedkeys 'GAsecond bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', }, helpers.get_lines()) end) - active_it("promotes an empty bullet", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - }) + it('promotes an empty bullet', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + } - helpers.feedkeys("GAthird bullet") + helpers.feedkeys 'GAthird bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "II. third bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + 'II. third bullet', }, helpers.get_lines()) end) - active_it("uses configured outline levels", function() - require("bullets").setup({ outline_levels = { "num", "ABC", "std*" } }) - helpers.new_buffer({ - "# Hello there", - "1. first bullet", - "\tA. second bullet", - "\t\t* third bullet", - "2. fourth bullet", - }) + it('uses configured outline levels', function() + require('bullets').setup { outline_levels = { 'num', 'ABC', 'std*' } } + helpers.new_buffer { + '# Hello there', + '1. first bullet', + '\tA. second bullet', + '\t\t* third bullet', + '2. fourth bullet', + } vim.api.nvim_win_set_cursor(0, { 5, 0 }) - vim.cmd("BulletDemote") + vim.cmd 'BulletDemote' vim.api.nvim_win_set_cursor(0, { 3, 0 }) - vim.cmd("BulletPromote") + vim.cmd 'BulletPromote' vim.api.nvim_win_set_cursor(0, { 4, 0 }) - vim.cmd("BulletDemote") + vim.cmd 'BulletDemote' assert.are.same({ - "# Hello there", - "1. first bullet", - "2. second bullet", - "\t\t\t* third bullet", - "\tA. fourth bullet", + '# Hello there', + '1. first bullet', + '2. second bullet', + '\t\t\t* third bullet', + '\tA. fourth bullet', }, helpers.get_lines()) end) - active_it("preserves the last standard outline level when demoting beyond configured levels", function() - helpers.new_buffer({ - "# Hello there", - "\t\t\t\t\t\t\t+ ninth bullet", - }) + it('preserves the last standard outline level when demoting beyond configured levels', function() + helpers.new_buffer { + '# Hello there', + '\t\t\t\t\t\t\t+ ninth bullet', + } vim.api.nvim_win_set_cursor(0, { 2, 0 }) - vim.cmd("BulletDemote") + vim.cmd 'BulletDemote' assert.are.same({ - "# Hello there", - "\t\t\t\t\t\t\t\t+ ninth bullet", + '# Hello there', + '\t\t\t\t\t\t\t\t+ ninth bullet', }, helpers.get_lines()) end) - active_it("removes a bullet when promoting at the top outline level", function() - helpers.new_buffer({ - "# Hello there", - "I. first bullet", - }) + it('removes a bullet when promoting at the top outline level', function() + helpers.new_buffer { + '# Hello there', + 'I. first bullet', + } - helpers.feedkeys("ggj<<") + helpers.feedkeys 'ggj<<' assert.are.same({ - "# Hello there", - "first bullet", + '# Hello there', + 'first bullet', }, helpers.get_lines()) end) - active_it("promotes bullets in a visual range", function() - require("bullets").setup({ outline_levels = { "num", "abc", "std*" } }) - helpers.new_buffer({ - "# Hello there", - "1. first bullet", - "\ta. second bullet", - "\tb. third bullet", - }) + it('promotes bullets in a visual range', function() + require('bullets').setup { outline_levels = { 'num', 'abc', 'std*' } } + helpers.new_buffer { + '# Hello there', + '1. first bullet', + '\ta. second bullet', + '\tb. third bullet', + } - vim.cmd("3,4BulletPromoteVisual") + vim.cmd '3,4BulletPromoteVisual' assert.are.same({ - "# Hello there", - "1. first bullet", - "2. second bullet", - "3. third bullet", + '# Hello there', + '1. first bullet', + '2. second bullet', + '3. third bullet', }, helpers.get_lines()) end) - active_it("demotes bullets in a visual range", function() - require("bullets").setup({ outline_levels = { "num", "abc", "std*" } }) - helpers.new_buffer({ - "# Hello there", - "1. first bullet", - "2. second bullet", - "3. third bullet", - }) + it('demotes bullets in a visual range', function() + require('bullets').setup { outline_levels = { 'num', 'abc', 'std*' } } + helpers.new_buffer { + '# Hello there', + '1. first bullet', + '2. second bullet', + '3. third bullet', + } - vim.cmd("3,4BulletDemoteVisual") + vim.cmd '3,4BulletDemoteVisual' assert.are.same({ - "# Hello there", - "1. first bullet", - "\ta. second bullet", - "\tb. third bullet", + '# Hello there', + '1. first bullet', + '\ta. second bullet', + '\tb. third bullet', }, helpers.get_lines()) end) - pending_it("demotes an existing bullet", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "II. second bullet", - "III. third bullet", - "IV. fourth bullet", - "V. fifth bullet", - "VI. sixth bullet", - "VII. seventh bullet", - "VIII. eighth bullet", - "IX. ninth bullet", - }) + pending('demotes an existing bullet', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + 'II. second bullet', + 'III. third bullet', + 'IV. fourth bullet', + 'V. fifth bullet', + 'VI. sixth bullet', + 'VII. seventh bullet', + 'VIII. eighth bullet', + 'IX. ninth bullet', + } -- Go to line 3 (gg + 2j), enter insert, demote with - helpers.feedkeys("gg2ji") + helpers.feedkeys 'gg2ji' -- Back to normal mode, go down 1 line, demote 3 times with >> - helpers.feedkeys("j>>>>>>") + helpers.feedkeys 'j>>>>>>' -- Continue demoting subsequent lines - helpers.feedkeys("j>>>>>>>>") - helpers.feedkeys("j>>>>>>>>>>") - helpers.feedkeys("j>>>>>>>>") - helpers.feedkeys(">>>>") - helpers.feedkeys("j>>>>>>>>") - helpers.feedkeys(">>>>>>") - helpers.feedkeys("j>>>>>>>>") - helpers.feedkeys(">>>>>>>>") - helpers.feedkeys("j>>>>>>>>") - helpers.feedkeys(">>>>>>>>>>") + helpers.feedkeys 'j>>>>>>>>' + helpers.feedkeys 'j>>>>>>>>>>' + helpers.feedkeys 'j>>>>>>>>' + helpers.feedkeys '>>>>' + helpers.feedkeys 'j>>>>>>>>' + helpers.feedkeys '>>>>>>' + helpers.feedkeys 'j>>>>>>>>' + helpers.feedkeys '>>>>>>>>' + helpers.feedkeys 'j>>>>>>>>' + helpers.feedkeys '>>>>>>>>>>' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "\t\t\t1. third bullet", - "\t\t\t\ta. fourth bullet", - "\t\t\t\t\ti. fifth bullet", - "\t\t\t\t\t\t- sixth bullet", - "\t\t\t\t\t\t\t* seventh bullet", - "\t\t\t\t\t\t\t\t+ eighth bullet", - "\t\t\t\t\t\t\t\t\t+ ninth bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + '\t\t\t1. third bullet', + '\t\t\t\ta. fourth bullet', + '\t\t\t\t\ti. fifth bullet', + '\t\t\t\t\t\t- sixth bullet', + '\t\t\t\t\t\t\t* seventh bullet', + '\t\t\t\t\t\t\t\t+ eighth bullet', + '\t\t\t\t\t\t\t\t\t+ ninth bullet', }, helpers.get_lines()) end) - pending_it("promotes an existing bullet", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "\t\t\t1. third bullet", - "\t\t\t\ta. fourth bullet", - "\t\t\t\t\ti. fifth bullet", - "\t\t\t\t\t\t- sixth bullet", - "\t\t\t\t\t\t\t* seventh bullet", - "\t\t\t\t\t\t\t\t+ eighth bullet", - }) + pending('promotes an existing bullet', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + '\t\t\t1. third bullet', + '\t\t\t\ta. fourth bullet', + '\t\t\t\t\ti. fifth bullet', + '\t\t\t\t\t\t- sixth bullet', + '\t\t\t\t\t\t\t* seventh bullet', + '\t\t\t\t\t\t\t\t+ eighth bullet', + } -- Go to line 3 (gg + 2j), promote with << - helpers.feedkeys("gg2j<<") + helpers.feedkeys 'gg2j<<' -- Go to line 4, enter insert, demote twice with - helpers.feedkeys("ji") + helpers.feedkeys 'ji' -- Continue promoting subsequent lines - helpers.feedkeys("j<<<<<<") - helpers.feedkeys("j<<<<<<") - helpers.feedkeys("<<<<") - helpers.feedkeys("j<<<<<<") - helpers.feedkeys("<<<<<<") - helpers.feedkeys("j<<<<<<") - helpers.feedkeys("<<<<<<<<") - helpers.feedkeys("j<<<<<<") - helpers.feedkeys("<<<<<<") - helpers.feedkeys("<<<<") + helpers.feedkeys 'j<<<<<<' + helpers.feedkeys 'j<<<<<<' + helpers.feedkeys '<<<<' + helpers.feedkeys 'j<<<<<<' + helpers.feedkeys '<<<<<<' + helpers.feedkeys 'j<<<<<<' + helpers.feedkeys '<<<<<<<<' + helpers.feedkeys 'j<<<<<<' + helpers.feedkeys '<<<<<<' + helpers.feedkeys '<<<<' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "II. second bullet", - "\tA. third bullet", - "\tB. fourth bullet", - "III. fifth bullet", - "IV. sixth bullet", - "V. seventh bullet", - "VI. eighth bullet", + '# Hello there', + 'I. this is the first bullet', + 'II. second bullet', + '\tA. third bullet', + '\tB. fourth bullet', + 'III. fifth bullet', + 'IV. sixth bullet', + 'V. seventh bullet', + 'VI. eighth bullet', }, helpers.get_lines()) end) - pending_it("demotes an empty bullet", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - }) + pending('demotes an empty bullet', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + } -- Enter insert at end, press CR (on bullet line), demote with , type - helpers.feedkeys("GAsecond bullet") + helpers.feedkeys 'GAsecond bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', }, helpers.get_lines()) end) - pending_it("promotes an empty bullet", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - }) + pending('promotes an empty bullet', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + } -- Enter insert at end, press CR (on bullet line), promote with , type - helpers.feedkeys("GAthird bullet") + helpers.feedkeys 'GAthird bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "II. third bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + 'II. third bullet', }, helpers.get_lines()) end) - pending_it("restarts numbering with multiple outlines", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - }) + pending('restarts numbering with multiple outlines', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + } -- GA enters insert at end, on bullet line creates new bullet, then -- again on bullet line (empty), which should delete the empty bullet -- (delete_last_bullet_if_empty), leaving normal mode. Then another does -- the same. Then we type a new bullet manually. - helpers.feedkeys("GA") + helpers.feedkeys 'GA' -- Now on a new empty bullet line. CR again triggers delete-last-bullet - helpers.feedkeys("A") + helpers.feedkeys 'A' -- Again on empty line - helpers.feedkeys("A") + helpers.feedkeys 'A' -- Now type the manual bullet header - helpers.feedkeys("iA. first bullet") + helpers.feedkeys 'iA. first bullet' -- Enter insert at end, CR on bullet line, demote, type - helpers.feedkeys("Asecond bullet") + helpers.feedkeys 'Asecond bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "", - "A. first bullet", - "\t1. second bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + '', + 'A. first bullet', + '\t1. second bullet', }, helpers.get_lines()) end) - pending_it("works with custom outline level definitions", function() - vim.g.bullets_outline_levels = { "num", "ABC", "std*" } - helpers.new_buffer({ - "# Hello there", - }) + pending('works with custom outline level definitions', function() + vim.g.bullets_outline_levels = { 'num', 'ABC', 'std*' } + helpers.new_buffer { + '# Hello there', + } -- Enter insert at end, CR (non-bullet line header, deferred CR) - helpers.feedkeys("GA") + helpers.feedkeys 'GA' -- Now in normal mode on new empty line - type the first bullet - helpers.feedkeys("i1. first bullet") + helpers.feedkeys 'i1. first bullet' -- CR on bullet line - stays in insert after plugin fires - helpers.feedkeys("Asecond bullet") + helpers.feedkeys 'Asecond bullet' -- CR on bullet line, then demote, then type - helpers.feedkeys("Athird bullet") - helpers.feedkeys("Afourth bullet") - helpers.feedkeys("Afifth bullet") - helpers.feedkeys("Asixth bullet") - helpers.feedkeys("Aseventh bullet") - helpers.feedkeys("Aeighth bullet") + helpers.feedkeys 'Athird bullet' + helpers.feedkeys 'Afourth bullet' + helpers.feedkeys 'Afifth bullet' + helpers.feedkeys 'Asixth bullet' + helpers.feedkeys 'Aseventh bullet' + helpers.feedkeys 'Aeighth bullet' -- demote twice, then type - helpers.feedkeys("Aninth bullet") + helpers.feedkeys 'Aninth bullet' -- demote once, then type - helpers.feedkeys("Atenth bullet") - helpers.feedkeys("Aeleventh bullet") + helpers.feedkeys 'Atenth bullet' + helpers.feedkeys 'Aeleventh bullet' assert.are.same({ - "# Hello there", - "1. first bullet", - "2. second bullet", - "\tA. third bullet", - "\tB. fourth bullet", - "\t\t* fifth bullet", - "\t\t* sixth bullet", - "\t\t\t* seventh bullet", - "\t\t\t* eighth bullet", - "\tC. ninth bullet", - "3. tenth bullet", - "4. eleventh bullet", + '# Hello there', + '1. first bullet', + '2. second bullet', + '\tA. third bullet', + '\tB. fourth bullet', + '\t\t* fifth bullet', + '\t\t* sixth bullet', + '\t\t\t* seventh bullet', + '\t\t\t* eighth bullet', + '\tC. ninth bullet', + '3. tenth bullet', + '4. eleventh bullet', }, helpers.get_lines()) end) - pending_it("promotes and demotes from different starting levels", function() - helpers.new_buffer({ - "# Hello there", - "1. this is the first bullet", - "\ta. second bullet", - }) + pending('promotes and demotes from different starting levels', function() + helpers.new_buffer { + '# Hello there', + '1. this is the first bullet', + '\ta. second bullet', + } -- In insert mode at end, promote with (still in insert after plugin's :BulletPromote) - helpers.feedkeys("GA") + helpers.feedkeys 'GA' -- Now "2. second bullet" in normal mode - CR on bullet line, demote, type - helpers.feedkeys("Athird bullet") + helpers.feedkeys 'Athird bullet' -- Two CRs: first creates empty \tb. bullet, second deletes it (delete_last_bullet_if_empty) - helpers.feedkeys("A") - helpers.feedkeys("A") + helpers.feedkeys 'A' + helpers.feedkeys 'A' -- Type the non-bullet manually on the blank line - helpers.feedkeys("i+ fourth bullet") + helpers.feedkeys 'i+ fourth bullet' -- CR on + bullet line, demote, type - helpers.feedkeys("Afifth bullet") + helpers.feedkeys 'Afifth bullet' -- Two CRs: first creates empty \t+ bullet, second deletes it - helpers.feedkeys("A") - helpers.feedkeys("A") + helpers.feedkeys 'A' + helpers.feedkeys 'A' -- Type the non-bullet manually - helpers.feedkeys("i* sixth bullet") + helpers.feedkeys 'i* sixth bullet' -- CR on * bullet line creates * seventh bullet, type it - helpers.feedkeys("Aseventh bullet") + helpers.feedkeys 'Aseventh bullet' -- Re-enter insert at end and demote with . - helpers.feedkeys("A") + helpers.feedkeys 'A' assert.are.same({ - "# Hello there", - "1. this is the first bullet", - "2. second bullet", - "\ta. third bullet", - "+ fourth bullet", - "\t+ fifth bullet", - "* sixth bullet", - "\t+ seventh bullet", + '# Hello there', + '1. this is the first bullet', + '2. second bullet', + '\ta. third bullet', + '+ fourth bullet', + '\t+ fifth bullet', + '* sixth bullet', + '\t+ seventh bullet', }, helpers.get_lines()) end) - pending_it("does not nest beyond defined levels", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "\t\t1. third bullet", - "\t\t\ta. fourth bullet", - "\t\t\t\ti. fifth bullet", - "\t\t\t\tii. sixth bullet", - "\t\t\t\t\t- seventh bullet", - "\t\t\t\t\t\t* eighth bullet", - "\t\t\t\t\t\t\t+ ninth bullet", - }) + pending('does not nest beyond defined levels', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + '\t\t1. third bullet', + '\t\t\ta. fourth bullet', + '\t\t\t\ti. fifth bullet', + '\t\t\t\tii. sixth bullet', + '\t\t\t\t\t- seventh bullet', + '\t\t\t\t\t\t* eighth bullet', + '\t\t\t\t\t\t\t+ ninth bullet', + } -- GA enters insert at end, CR on bullet line, demote with , type - helpers.feedkeys("GAtenth bullet") - helpers.feedkeys("Aeleventh bullet") + helpers.feedkeys 'GAtenth bullet' + helpers.feedkeys 'Aeleventh bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "\t\t1. third bullet", - "\t\t\ta. fourth bullet", - "\t\t\t\ti. fifth bullet", - "\t\t\t\tii. sixth bullet", - "\t\t\t\t\t- seventh bullet", - "\t\t\t\t\t\t* eighth bullet", - "\t\t\t\t\t\t\t+ ninth bullet", - "\t\t\t\t\t\t\t\t+ tenth bullet", - "\t\t\t\t\t\t\t\t+ eleventh bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + '\t\t1. third bullet', + '\t\t\ta. fourth bullet', + '\t\t\t\ti. fifth bullet', + '\t\t\t\tii. sixth bullet', + '\t\t\t\t\t- seventh bullet', + '\t\t\t\t\t\t* eighth bullet', + '\t\t\t\t\t\t\t+ ninth bullet', + '\t\t\t\t\t\t\t\t+ tenth bullet', + '\t\t\t\t\t\t\t\t+ eleventh bullet', }, helpers.get_lines()) end) - pending_it("removes bullet when promoting top level bullet", function() - helpers.new_buffer({ - "# Hello there", - "A. this is the first bullet", - "", - "I. second bullet", - "\tA. third bullet", - }) + pending('removes bullet when promoting top level bullet', function() + helpers.new_buffer { + '# Hello there', + 'A. this is the first bullet', + '', + 'I. second bullet', + '\tA. third bullet', + } -- Go to line 2 (gg + j), promote with << - helpers.feedkeys("ggj<<") + helpers.feedkeys 'ggj<<' -- Go to line 5 (3j from line 2 = line 5), enter insert, promote twice - helpers.feedkeys("3ji") + helpers.feedkeys '3ji' assert.are.same({ - "# Hello there", - "this is the first bullet", - "", - "I. second bullet", - "third bullet", + '# Hello there', + 'this is the first bullet', + '', + 'I. second bullet', + 'third bullet', }, helpers.get_lines()) end) - pending_it("handle standard bullets when they are not in outline list", function() - vim.g.bullets_outline_levels = { "num", "ABC" } - helpers.new_buffer({ - "# Hello there", - "1. this is the first bullet", - "\t- standard bullet", - }) + pending('handle standard bullets when they are not in outline list', function() + vim.g.bullets_outline_levels = { 'num', 'ABC' } + helpers.new_buffer { + '# Hello there', + '1. this is the first bullet', + '\t- standard bullet', + } -- GA enters insert at end, CR on bullet line (standard bullet), type - helpers.feedkeys("GAsecond standard bullet") + helpers.feedkeys 'GAsecond standard bullet' -- CR on bullet line, promote with , type - helpers.feedkeys("Asecond bullet") + helpers.feedkeys 'Asecond bullet' -- CR on bullet line, type - helpers.feedkeys("Athird bullet") + helpers.feedkeys 'Athird bullet' assert.are.same({ - "# Hello there", - "1. this is the first bullet", - "\t- standard bullet", - "\t- second standard bullet", - "2. second bullet", - "3. third bullet", + '# Hello there', + '1. this is the first bullet', + '\t- standard bullet', + '\t- second standard bullet', + '2. second bullet', + '3. third bullet', }, helpers.get_lines()) end) - pending_it("adds new nested bullets with correct alpha/roman numerals", function() - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - }) + pending('adds new nested bullets with correct alpha/roman numerals', function() + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + } -- All CRs are on bullet lines. After , insert mode remains active -- so the sequence can continue by typing text and pressing for the next line. - helpers.feedkeys( - "GAthird bulletfourth bulletfifth bulletsixth bulletseventh bullet" - ) - helpers.feedkeys( - "Aeighth bulletninth bullettenth bulleteleventh bullettwelfth bullet" - ) + helpers.feedkeys 'GAthird bulletfourth bulletfifth bulletsixth bulletseventh bullet' + helpers.feedkeys 'Aeighth bulletninth bullettenth bulleteleventh bullettwelfth bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "\tA. second bullet", - "\t\t1. third bullet", - "\t\t\ta. fourth bullet", - "\t\t\t\ti. fifth bullet", - "\t\t\t\t\t- sixth bullet", - "\t\t\t\t\t- seventh bullet", - "\t\t\t\tii. eighth bullet", - "\t\t\tb. ninth bullet", - "\t\t2. tenth bullet", - "\tB. eleventh bullet", - "II. twelfth bullet", + '# Hello there', + 'I. this is the first bullet', + '\tA. second bullet', + '\t\t1. third bullet', + '\t\t\ta. fourth bullet', + '\t\t\t\ti. fifth bullet', + '\t\t\t\t\t- sixth bullet', + '\t\t\t\t\t- seventh bullet', + '\t\t\t\tii. eighth bullet', + '\t\t\tb. ninth bullet', + '\t\t2. tenth bullet', + '\tB. eleventh bullet', + 'II. twelfth bullet', }, helpers.get_lines()) end) - pending_it("changes levels in visual mode", function() - vim.g.bullets_outline_levels = { "num", "abc", "std*" } - helpers.new_buffer({ - "# Hello there", - "1. first bullet", - "\ta. second bullet", - "\tb. third bullet", - "\t\t* fourth bullet", - "\t\t* fifth bullet", - "\t\t\tsixth bullet", - "\t\t* seventh bullet", - "2. eighth bullet", - "\t\ta. ninth bullet", - "\ta. tenth bullet", - "\tb. eleventh bullet", - "3. twelfth bullet", - "\t thirteenth bullet", - "\ta. fourteenth bullet", - "\t\t* fifteenth bullet", - "4. sixteenth bullet", - }) + pending('changes levels in visual mode', function() + vim.g.bullets_outline_levels = { 'num', 'abc', 'std*' } + helpers.new_buffer { + '# Hello there', + '1. first bullet', + '\ta. second bullet', + '\tb. third bullet', + '\t\t* fourth bullet', + '\t\t* fifth bullet', + '\t\t\tsixth bullet', + '\t\t* seventh bullet', + '2. eighth bullet', + '\t\ta. ninth bullet', + '\ta. tenth bullet', + '\tb. eleventh bullet', + '3. twelfth bullet', + '\t thirteenth bullet', + '\ta. fourteenth bullet', + '\t\t* fifteenth bullet', + '4. sixteenth bullet', + } -- After each visual < or > operation, the plugin re-enters visual mode (via s:set_selection). -- Exit visual mode before starting each fresh visual selection. - helpers.feedkeys("gg3jv<") - helpers.feedkeys("jv2j<") - helpers.feedkeys("jvj>") - helpers.feedkeys("jvj<") + helpers.feedkeys 'gg3jv<' + helpers.feedkeys 'jv2j<' + helpers.feedkeys 'jvj>' + helpers.feedkeys 'jvj<' -- The plugin leaves us in visual mode with the same selection. - helpers.feedkeys("<") - helpers.feedkeys("jv>") - helpers.feedkeys("3jv2j>") + helpers.feedkeys '<' + helpers.feedkeys 'jv>' + helpers.feedkeys '3jv2j>' -- Repeat the operation on the same visual selection. - helpers.feedkeys(">") + helpers.feedkeys '>' assert.are.same({ - "# Hello there", - "1. first bullet", - "\ta. second bullet", - "2. third bullet", - "\ta. fourth bullet", - "\tb. fifth bullet", - "\t\tsixth bullet", - "\t\t\t* seventh bullet", - "\tc. eighth bullet", - "3. ninth bullet", - "tenth bullet", - "\t\ta. eleventh bullet", - "4. twelfth bullet", - "\t thirteenth bullet", - "\t\t\ta. fourteenth bullet", - "\t\t\t\t* fifteenth bullet", - "\t\ta. sixteenth bullet", + '# Hello there', + '1. first bullet', + '\ta. second bullet', + '2. third bullet', + '\ta. fourth bullet', + '\tb. fifth bullet', + '\t\tsixth bullet', + '\t\t\t* seventh bullet', + '\tc. eighth bullet', + '3. ninth bullet', + 'tenth bullet', + '\t\ta. eleventh bullet', + '4. twelfth bullet', + '\t thirteenth bullet', + '\t\t\ta. fourteenth bullet', + '\t\t\t\t* fifteenth bullet', + '\t\ta. sixteenth bullet', }, helpers.get_lines()) end) - pending_it("add and change bullets with multiple line spacing and wrapped lines", function() + pending('add and change bullets with multiple line spacing and wrapped lines', function() vim.g.bullets_line_spacing = 2 - helpers.new_buffer({ - "# Hello there", - "I. this is the first bullet", - }) + helpers.new_buffer { + '# Hello there', + 'I. this is the first bullet', + } -- GA enters insert at end, CR on bullet line (with line_spacing=2, creates empty line too) -- Then type 'second bullet', then CR again, demote, type 'third bullet' - helpers.feedkeys("GAsecond bullet") - helpers.feedkeys("Athird bullet") + helpers.feedkeys 'GAsecond bullet' + helpers.feedkeys 'Athird bullet' -- After CR on bullet line with line_spacing=2, cursor is on the new empty line after the bullet -- dd deletes that line, then inserts '\twrapped bullet'. - helpers.feedkeys("A") - helpers.feedkeys("dd") - helpers.feedkeys("i\twrapped bullet") + helpers.feedkeys 'A' + helpers.feedkeys 'dd' + helpers.feedkeys 'i\twrapped bullet' -- Then CR, type 'fourth bullet' - helpers.feedkeys("Afourth bullet") + helpers.feedkeys 'Afourth bullet' assert.are.same({ - "# Hello there", - "I. this is the first bullet", - "", - "II. second bullet", - "", - "\tA. third bullet", - "\twrapped bullet", - "", - "\tB. fourth bullet", + '# Hello there', + 'I. this is the first bullet', + '', + 'II. second bullet', + '', + '\tA. third bullet', + '\twrapped bullet', + '', + '\tB. fourth bullet', }, helpers.get_lines()) end) - pending_it("indents after a line ending in a colon", function() + pending('indents after a line ending in a colon', function() vim.g.bullets_auto_indent_after_colon = 1 - helpers.new_buffer({ - "# Hello there", - "a. this is the first bullet", - }) + helpers.new_buffer { + '# Hello there', + 'a. this is the first bullet', + } -- GA enters insert at end, CR on bullet line, type second bullet ending with colon - helpers.feedkeys("GAthis is the second bullet:") + helpers.feedkeys 'GAthis is the second bullet:' -- CR after colon should auto-indent - helpers.feedkeys("Athis bullet is indented") - helpers.feedkeys("Athis bullet is also indented") + helpers.feedkeys 'Athis bullet is indented' + helpers.feedkeys 'Athis bullet is also indented' -- Check first phase local lines1 = helpers.get_lines() -- Remove trailing empty lines before comparison. - while #lines1 > 0 and lines1[#lines1] == "" do + while #lines1 > 0 and lines1[#lines1] == '' do table.remove(lines1) end assert.are.same({ - "# Hello there", - "a. this is the first bullet", - "b. this is the second bullet:", - "\ti. this bullet is indented", - "\tii. this bullet is also indented", + '# Hello there', + 'a. this is the first bullet', + 'b. this is the second bullet:', + '\ti. this bullet is indented', + '\tii. this bullet is also indented', }, lines1) -- Phase 2: reset buffer with same content, test fullwidth colon - helpers.new_buffer({ - "# Hello there", - "a. this is the first bullet", - }) + helpers.new_buffer { + '# Hello there', + 'a. this is the first bullet', + } -- Use GA to enter insert at end of the last line. - helpers.feedkeys("GAthis is the second bullet that ends with fullwidth colon:") - helpers.feedkeys("Athis bullet is indented") - helpers.feedkeys("Athis bullet is also indented") + helpers.feedkeys 'GAthis is the second bullet that ends with fullwidth colon:' + helpers.feedkeys 'Athis bullet is indented' + helpers.feedkeys 'Athis bullet is also indented' local lines2 = helpers.get_lines() - while #lines2 > 0 and lines2[#lines2] == "" do + while #lines2 > 0 and lines2[#lines2] == '' do table.remove(lines2) end assert.are.same({ - "# Hello there", - "a. this is the first bullet", - "b. this is the second bullet that ends with fullwidth colon:", - "\ti. this bullet is indented", - "\tii. this bullet is also indented", + '# Hello there', + 'a. this is the first bullet', + 'b. this is the second bullet that ends with fullwidth colon:', + '\ti. this bullet is indented', + '\tii. this bullet is also indented', }, lines2) end) end) diff --git a/test/poc_spec.lua b/test/poc_spec.lua index 3380756..331cfb9 100644 --- a/test/poc_spec.lua +++ b/test/poc_spec.lua @@ -1,65 +1,65 @@ local function feedkeys(keys) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), "tx", false) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), 'tx', false) end -describe("Bullets.vim", function() +describe('Bullets.vim', function() before_each(function() - require("bullets").setup({ - enabled_file_types = { "text" }, + require('bullets').setup { + enabled_file_types = { 'text' }, enable_in_empty_buffers = false, set_mappings = true, - mapping_leader = "", + mapping_leader = '', custom_mappings = {}, - }) + } end) - it("loads the plugin", function() - assert.equals(2, vim.fn.exists(":InsertNewBullet")) + it('loads the plugin', function() + assert.equals(2, vim.fn.exists ':InsertNewBullet') end) - it("preserves native normal-mode o behavior", function() - vim.cmd("enew") - vim.bo.filetype = "text" - vim.api.nvim_buf_set_lines(0, 0, -1, false, { "plain" }) + it('preserves native normal-mode o behavior', function() + vim.cmd 'enew' + vim.bo.filetype = 'text' + vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'plain' }) vim.api.nvim_win_set_cursor(0, { 1, 0 }) - feedkeys("ohello") + feedkeys 'ohello' - assert.are.same({ "plain", "hello" }, vim.api.nvim_buf_get_lines(0, 0, -1, false)) + assert.are.same({ 'plain', 'hello' }, vim.api.nvim_buf_get_lines(0, 0, -1, false)) end) - it("preserves native insert-mode return fallback", function() - vim.cmd("enew") - vim.bo.filetype = "text" - vim.api.nvim_buf_set_lines(0, 0, -1, false, { "plain" }) - vim.api.nvim_win_set_cursor(0, { 1, #"plain" }) + it('preserves native insert-mode return fallback', function() + vim.cmd 'enew' + vim.bo.filetype = 'text' + vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'plain' }) + vim.api.nvim_win_set_cursor(0, { 1, #'plain' }) - feedkeys("Anext") + feedkeys 'Anext' - assert.are.same({ "plain", "next" }, vim.api.nvim_buf_get_lines(0, 0, -1, false)) + assert.are.same({ 'plain', 'next' }, vim.api.nvim_buf_get_lines(0, 0, -1, false)) end) - it("does not install default mappings when disabled", function() - require("bullets").setup({ - enabled_file_types = { "text" }, + it('does not install default mappings when disabled', function() + require('bullets').setup { + enabled_file_types = { 'text' }, set_mappings = false, - }) - vim.cmd("enew") - vim.bo.filetype = "text" + } + vim.cmd 'enew' + vim.bo.filetype = 'text' - assert.equals("", vim.fn.maparg("o", "n")) - assert.equals("", vim.fn.maparg(">>", "n")) + assert.equals('', vim.fn.maparg('o', 'n')) + assert.equals('', vim.fn.maparg('>>', 'n')) end) - it("inserts a new bullet on ", function() - vim.cmd("enew") - vim.bo.filetype = "text" - vim.api.nvim_buf_set_lines(0, 0, -1, false, { "- first item" }) - vim.api.nvim_win_set_cursor(0, { 1, #"- first item" }) + it('inserts a new bullet on ', function() + vim.cmd 'enew' + vim.bo.filetype = 'text' + vim.api.nvim_buf_set_lines(0, 0, -1, false, { '- first item' }) + vim.api.nvim_win_set_cursor(0, { 1, #'- first item' }) - feedkeys("A") + feedkeys 'A' local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) - assert.equals("- ", lines[2]) + assert.equals('- ', lines[2]) end) end) diff --git a/test/renumber_bullets_spec.lua b/test/renumber_bullets_spec.lua index ead0f40..9603a90 100644 --- a/test/renumber_bullets_spec.lua +++ b/test/renumber_bullets_spec.lua @@ -1,301 +1,301 @@ -local helpers = require("test.helpers") +local helpers = require 'test.helpers' -describe("re-numbering", function() +describe('re-numbering', function() before_each(function() helpers.reset_config() end) - it("renumbers a selected list correctly", function() - helpers.new_buffer({ - "# Hello there", - "33. this is the first bullet", - "2. this is the second bullet", - "1. this is the third bullet", - "4. this is the fourth bullet", - }) - helpers.feedkeys("ggVGgN") + it('renumbers a selected list correctly', function() + helpers.new_buffer { + '# Hello there', + '33. this is the first bullet', + '2. this is the second bullet', + '1. this is the third bullet', + '4. this is the fourth bullet', + } + helpers.feedkeys 'ggVGgN' assert.are.same({ - "# Hello there", - "1. this is the first bullet", - "2. this is the second bullet", - "3. this is the third bullet", - "4. this is the fourth bullet", + '# Hello there', + '1. this is the first bullet', + '2. this is the second bullet', + '3. this is the third bullet', + '4. this is the fourth bullet', }, helpers.get_lines()) end) - it("renumbers a list containing checkboxes", function() - helpers.new_buffer({ - "# Hello there", - "33. this is the first bullet", - "- [x] this is the second bullet", - "1. this is the third bullet", - " - [ ] this is the fourth bullet", - "4. this is the fifth bullet", - "", - "- [o] second bullet list", - "b. second item", - "- [x] third item", - }) + it('renumbers a list containing checkboxes', function() + helpers.new_buffer { + '# Hello there', + '33. this is the first bullet', + '- [x] this is the second bullet', + '1. this is the third bullet', + ' - [ ] this is the fourth bullet', + '4. this is the fifth bullet', + '', + '- [o] second bullet list', + 'b. second item', + '- [x] third item', + } -- cursor is at line 10; move to line 2 (j from line 1 = line 2) - helpers.feedkeys("ggj") - helpers.feedkeys("gN") - helpers.feedkeys("}j") - helpers.feedkeys("gN") + helpers.feedkeys 'ggj' + helpers.feedkeys 'gN' + helpers.feedkeys '}j' + helpers.feedkeys 'gN' assert.are.same({ - "# Hello there", - "1. this is the first bullet", - "- [x] this is the second bullet", - "2. this is the third bullet", - " - [ ] this is the fourth bullet", - "3. this is the fifth bullet", - "", - "- [o] second bullet list", - "a. second item", - "- [x] third item", + '# Hello there', + '1. this is the first bullet', + '- [x] this is the second bullet', + '2. this is the third bullet', + ' - [ ] this is the fourth bullet', + '3. this is the fifth bullet', + '', + '- [o] second bullet list', + 'a. second item', + '- [x] third item', }, helpers.get_lines()) end) - it("renumbers a nested list", function() - require("bullets").setup({ line_spacing = 2 }) - helpers.new_buffer({ - "# Hello there", - "0. zero bullet", - "", - "X. first bullet", - "", - "- second bullet", - "\twrapped line", - "", - "a. third bullet", - "", - "I. fourth bullet", - "", - "\tV. fifth bullet", - "", - "\t\tB. sixth bullet", - "", - "\t* seventh bullet", - "", - "\t\ti. eighth bullet", - "", - "\t\tx. ninth bullet", - "\t\t\t wrapped line", - "", - "\t\t\ta. tenth bullet", - "wrapped line without indent", - "", - "\tC. eleventh bullet", - "\t\t0. twelfth bullet", - "", - "\t\t\t* thirteenth bullet", - "", - "\t\t\t\t+ fourteenth bullet", - "", - "\t\t\tb. fifteenth bullet", - "", - "\t\ta. sixteenth bullet", - "", - "\t\t\t8. seventeenth bullet", - "", - "\t\t\t0. eighteenth bullet", - "\t\t\t\t wrapped line", - "", - "\tnormal indented line", - "next normal line", - "", - "1. nineteenth bullet", - "", - "x. twentieth bullet", - "", - "", - "v. twenty-first bullet", - "- twenty-second bullet", - "", - "", - "v. twenty-third bullet", - }) + it('renumbers a nested list', function() + require('bullets').setup { line_spacing = 2 } + helpers.new_buffer { + '# Hello there', + '0. zero bullet', + '', + 'X. first bullet', + '', + '- second bullet', + '\twrapped line', + '', + 'a. third bullet', + '', + 'I. fourth bullet', + '', + '\tV. fifth bullet', + '', + '\t\tB. sixth bullet', + '', + '\t* seventh bullet', + '', + '\t\ti. eighth bullet', + '', + '\t\tx. ninth bullet', + '\t\t\t wrapped line', + '', + '\t\t\ta. tenth bullet', + 'wrapped line without indent', + '', + '\tC. eleventh bullet', + '\t\t0. twelfth bullet', + '', + '\t\t\t* thirteenth bullet', + '', + '\t\t\t\t+ fourteenth bullet', + '', + '\t\t\tb. fifteenth bullet', + '', + '\t\ta. sixteenth bullet', + '', + '\t\t\t8. seventeenth bullet', + '', + '\t\t\t0. eighteenth bullet', + '\t\t\t\t wrapped line', + '', + '\tnormal indented line', + 'next normal line', + '', + '1. nineteenth bullet', + '', + 'x. twentieth bullet', + '', + '', + 'v. twenty-first bullet', + '- twenty-second bullet', + '', + '', + 'v. twenty-third bullet', + } -- Go to line 4 (gg then 3j from line 1) and renumber from there - helpers.feedkeys("gg3j") - helpers.feedkeys("gN") + helpers.feedkeys 'gg3j' + helpers.feedkeys 'gN' -- Go to last line then 3k up and renumber - helpers.feedkeys("G3k") - helpers.feedkeys("gN") + helpers.feedkeys 'G3k' + helpers.feedkeys 'gN' assert.are.same({ - "# Hello there", - "1. zero bullet", - "", - "2. first bullet", - "", - "- second bullet", - "\twrapped line", - "", - "3. third bullet", - "", - "4. fourth bullet", - "", - "\tI. fifth bullet", - "", - "\t\tA. sixth bullet", - "", - "\t* seventh bullet", - "", - "\t\ti. eighth bullet", - "", - "\t\tii. ninth bullet", - "\t\t\t wrapped line", - "", - "\t\t\ta. tenth bullet", - "wrapped line without indent", - "", - "\tII. eleventh bullet", - "\t\t1. twelfth bullet", - "", - "\t\t\t* thirteenth bullet", - "", - "\t\t\t\t+ fourteenth bullet", - "", - "\t\t\ta. fifteenth bullet", - "", - "\t\t2. sixteenth bullet", - "", - "\t\t\t1. seventeenth bullet", - "", - "\t\t\t2. eighteenth bullet", - "\t\t\t\t wrapped line", - "", - "\tnormal indented line", - "next normal line", - "", - "1. nineteenth bullet", - "", - "x. twentieth bullet", - "", - "", - "i. twenty-first bullet", - "- twenty-second bullet", - "", - "", - "v. twenty-third bullet", + '# Hello there', + '1. zero bullet', + '', + '2. first bullet', + '', + '- second bullet', + '\twrapped line', + '', + '3. third bullet', + '', + '4. fourth bullet', + '', + '\tI. fifth bullet', + '', + '\t\tA. sixth bullet', + '', + '\t* seventh bullet', + '', + '\t\ti. eighth bullet', + '', + '\t\tii. ninth bullet', + '\t\t\t wrapped line', + '', + '\t\t\ta. tenth bullet', + 'wrapped line without indent', + '', + '\tII. eleventh bullet', + '\t\t1. twelfth bullet', + '', + '\t\t\t* thirteenth bullet', + '', + '\t\t\t\t+ fourteenth bullet', + '', + '\t\t\ta. fifteenth bullet', + '', + '\t\t2. sixteenth bullet', + '', + '\t\t\t1. seventeenth bullet', + '', + '\t\t\t2. eighteenth bullet', + '\t\t\t\t wrapped line', + '', + '\tnormal indented line', + 'next normal line', + '', + '1. nineteenth bullet', + '', + 'x. twentieth bullet', + '', + '', + 'i. twenty-first bullet', + '- twenty-second bullet', + '', + '', + 'v. twenty-third bullet', }, helpers.get_lines()) end) - it("visually renumbers a nested list", function() - require("bullets").setup({ line_spacing = 2 }) - helpers.new_buffer({ - "# Hello there", - "0. zero bullet", - "", - "X. first bullet", - "", - "- second bullet", - "\twrapped line", - "", - "a. third bullet", - "", - "I. fourth bullet", - "", - "\tV. fifth bullet", - "", - "\t\tB. sixth bullet", - "", - "\t* seventh bullet", - "", - "\t\ti. eighth bullet", - "", - "\t\tx. ninth bullet", - "\t\t\t wrapped line", - "", - "\t\t\ta. tenth bullet", - "wrapped line without indent", - "", - "\tC. eleventh bullet", - "\t\t0. twelfth bullet", - "", - "\t\t\t* thirteenth bullet", - "", - "\t\t\t\t+ fourteenth bullet", - "", - "\t\t\td. fifteenth bullet", - "", - "\t\ta. sixteenth bullet", - "", - "\t\t\t8. seventeenth bullet", - "", - "\t\t\t0. eighteenth bullet", - "\t\t\t\t wrapped line", - "", - "\tnormal indented line", - "next normal line", - "", - "1. nineteenth bullet", - "", - "x. twentieth bullet", - "", - "", - "v. twenty-first bullet", - "- twenty-second bullet", - "", - "", - "v. twenty-third bullet", - }) + it('visually renumbers a nested list', function() + require('bullets').setup { line_spacing = 2 } + helpers.new_buffer { + '# Hello there', + '0. zero bullet', + '', + 'X. first bullet', + '', + '- second bullet', + '\twrapped line', + '', + 'a. third bullet', + '', + 'I. fourth bullet', + '', + '\tV. fifth bullet', + '', + '\t\tB. sixth bullet', + '', + '\t* seventh bullet', + '', + '\t\ti. eighth bullet', + '', + '\t\tx. ninth bullet', + '\t\t\t wrapped line', + '', + '\t\t\ta. tenth bullet', + 'wrapped line without indent', + '', + '\tC. eleventh bullet', + '\t\t0. twelfth bullet', + '', + '\t\t\t* thirteenth bullet', + '', + '\t\t\t\t+ fourteenth bullet', + '', + '\t\t\td. fifteenth bullet', + '', + '\t\ta. sixteenth bullet', + '', + '\t\t\t8. seventeenth bullet', + '', + '\t\t\t0. eighteenth bullet', + '\t\t\t\t wrapped line', + '', + '\tnormal indented line', + 'next normal line', + '', + '1. nineteenth bullet', + '', + 'x. twentieth bullet', + '', + '', + 'v. twenty-first bullet', + '- twenty-second bullet', + '', + '', + 'v. twenty-third bullet', + } -- From line 1, go down 2 (to line 3), select to last line minus 1 (VGk), then renumber - helpers.feedkeys("gg2jVGkgN") + helpers.feedkeys 'gg2jVGkgN' assert.are.same({ - "# Hello there", - "0. zero bullet", - "", - "I. first bullet", - "", - "- second bullet", - "\twrapped line", - "", - "II. third bullet", - "", - "III. fourth bullet", - "", - "\tI. fifth bullet", - "", - "\t\tA. sixth bullet", - "", - "\t* seventh bullet", - "", - "\t\ti. eighth bullet", - "", - "\t\tii. ninth bullet", - "\t\t\t wrapped line", - "", - "\t\t\ta. tenth bullet", - "wrapped line without indent", - "", - "\tII. eleventh bullet", - "\t\t1. twelfth bullet", - "", - "\t\t\t* thirteenth bullet", - "", - "\t\t\t\t+ fourteenth bullet", - "", - "\t\t\ti. fifteenth bullet", - "", - "\t\t2. sixteenth bullet", - "", - "\t\t\t1. seventeenth bullet", - "", - "\t\t\t2. eighteenth bullet", - "\t\t\t\t wrapped line", - "", - "\tnormal indented line", - "next normal line", - "", - "IV. nineteenth bullet", - "", - "V. twentieth bullet", - "", - "", - "VI. twenty-first bullet", - "- twenty-second bullet", - "", - "", - "v. twenty-third bullet", + '# Hello there', + '0. zero bullet', + '', + 'I. first bullet', + '', + '- second bullet', + '\twrapped line', + '', + 'II. third bullet', + '', + 'III. fourth bullet', + '', + '\tI. fifth bullet', + '', + '\t\tA. sixth bullet', + '', + '\t* seventh bullet', + '', + '\t\ti. eighth bullet', + '', + '\t\tii. ninth bullet', + '\t\t\t wrapped line', + '', + '\t\t\ta. tenth bullet', + 'wrapped line without indent', + '', + '\tII. eleventh bullet', + '\t\t1. twelfth bullet', + '', + '\t\t\t* thirteenth bullet', + '', + '\t\t\t\t+ fourteenth bullet', + '', + '\t\t\ti. fifteenth bullet', + '', + '\t\t2. sixteenth bullet', + '', + '\t\t\t1. seventeenth bullet', + '', + '\t\t\t2. eighteenth bullet', + '\t\t\t\t wrapped line', + '', + '\tnormal indented line', + 'next normal line', + '', + 'IV. nineteenth bullet', + '', + 'V. twentieth bullet', + '', + '', + 'VI. twenty-first bullet', + '- twenty-second bullet', + '', + '', + 'v. twenty-third bullet', }, helpers.get_lines()) end) end) diff --git a/test/wrapping_bullets_spec.lua b/test/wrapping_bullets_spec.lua index 5d9a79e..941b81f 100644 --- a/test/wrapping_bullets_spec.lua +++ b/test/wrapping_bullets_spec.lua @@ -1,88 +1,86 @@ -local helpers = require("test.helpers") -local active_it = it -local it = pending +local helpers = require 'test.helpers' -describe("wrapped bullets", function() +describe('wrapped bullets', function() before_each(function() helpers.reset_config() end) - active_it("inserts a new bullet after a wrapped bullet", function() - helpers.test_bullet_inserted("do that", { - "# Hello there", - "- do this", - " this is the second line of the first bullet", + it('inserts a new bullet after a wrapped bullet', function() + helpers.test_bullet_inserted('do that', { + '# Hello there', + '- do this', + ' this is the second line of the first bullet', }, { - "# Hello there", - "- do this", - " this is the second line of the first bullet", - "- do that", + '# Hello there', + '- do this', + ' this is the second line of the first bullet', + '- do that', }) end) - active_it("does not insert wrapped bullets when disabled", function() - require("bullets").setup({ enable_wrapped_lines = false }) - helpers.new_buffer({ - "# Hello there", - "- do this", - " this is the second line of the first bullet", - }) - helpers.feedkeys("A") - helpers.feedkeys("ido that") + it('does not insert wrapped bullets when disabled', function() + require('bullets').setup { enable_wrapped_lines = false } + helpers.new_buffer { + '# Hello there', + '- do this', + ' this is the second line of the first bullet', + } + helpers.feedkeys 'A' + helpers.feedkeys 'ido that' assert.are.same({ - "# Hello there", - "- do this", - " this is the second line of the first bullet", - "do that", + '# Hello there', + '- do this', + ' this is the second line of the first bullet', + 'do that', }, helpers.get_lines()) end) - active_it("does not insert wrapped bullets unnecessarily", function() + it('does not insert wrapped bullets unnecessarily', function() -- When is pressed on a non-bullet line the plugin defers the actual -- newline via feedkeys('n'). Using two separate feedkeys calls ensures the -- deferred CR fires (the 'x' flag drains it) before we type the next text. - vim.cmd("enew") - vim.bo.filetype = "text" + vim.cmd 'enew' + vim.bo.filetype = 'text' vim.api.nvim_buf_set_lines(0, 0, -1, false, { - "# Hello there", - "- do this", - " this is the second line of the first bullet", - "", - "no bullets after this line", + '# Hello there', + '- do this', + ' this is the second line of the first bullet', + '', + 'no bullets after this line', }) - vim.api.nvim_win_set_cursor(0, { 5, #"no bullets after this line" }) + vim.api.nvim_win_set_cursor(0, { 5, #'no bullets after this line' }) -- feedkeys 'tx' exits insert mode after draining typeahead. After the first -- call the plugin's deferred '\' has fired (new empty line 6) and we are -- in normal mode. The second call uses 'i' to re-enter insert before typing. - helpers.feedkeys("A") - helpers.feedkeys("ido that") + helpers.feedkeys 'A' + helpers.feedkeys 'ido that' assert.are.same({ - "# Hello there", - "- do this", - " this is the second line of the first bullet", - "", - "no bullets after this line", - "do that", + '# Hello there', + '- do this', + ' this is the second line of the first bullet', + '', + 'no bullets after this line', + 'do that', }, helpers.get_lines()) end) - active_it("does not insert wrapped bullets after whitespace-only separators", function() - helpers.new_buffer({ - "# Hello there", - "- do this", - " this is the second line of the first bullet", - " ", - " no bullets after this line", - }) - helpers.feedkeys("A") - helpers.feedkeys("ido that") + it('does not insert wrapped bullets after whitespace-only separators', function() + helpers.new_buffer { + '# Hello there', + '- do this', + ' this is the second line of the first bullet', + ' ', + ' no bullets after this line', + } + helpers.feedkeys 'A' + helpers.feedkeys 'ido that' assert.are.same({ - "# Hello there", - "- do this", - " this is the second line of the first bullet", - " ", - " no bullets after this line", - "do that", + '# Hello there', + '- do this', + ' this is the second line of the first bullet', + ' ', + ' no bullets after this line', + 'do that', }, helpers.get_lines()) end) end)