diff --git a/lua/tirenvi/config.lua b/lua/tirenvi/config.lua index 5e68dd2..c3fecb1 100644 --- a/lua/tirenvi/config.lua +++ b/lua/tirenvi/config.lua @@ -38,6 +38,9 @@ local defaults = { monitor = true, probe = false, }, + textobj = { + column = "l" + }, } ----------------------------------------------------------------------- @@ -51,6 +54,13 @@ local function apply(opts) end end +---@param parser_map Parser[] +local function parse_version(parser_map) + for _, parser in pairs(parser_map) do + parser._iversion = M.version_to_integer(parser.required_version) + end +end + ----------------------------------------------------------------------- -- Public API ----------------------------------------------------------------------- @@ -59,6 +69,21 @@ end function M.setup(opts) local merged = vim.tbl_deep_extend("force", {}, M, opts or {}) apply(merged) + parse_version(M.parser_map) +end + +---@param version any +---@return integer|nil +function M.version_to_integer(version) + if type(version) ~= "string" then + return nil + end + local major, minor, patch = version:match("^(%d+)%.(%d+)%.?(%d*)$") + if not major then + return nil + end + local maj, min, pat = tonumber(major), tonumber(minor), tonumber(patch) or 0 + return (maj * 100000 + min) * 100000 + pat end apply(vim.deepcopy(defaults)) diff --git a/lua/tirenvi/core/flat_parser.lua b/lua/tirenvi/core/flat_parser.lua index de7e833..fd02755 100644 --- a/lua/tirenvi/core/flat_parser.lua +++ b/lua/tirenvi/core/flat_parser.lua @@ -13,6 +13,7 @@ local log = require("tirenvi.util.log") local util = require("tirenvi.util.util") local errors = require("tirenvi.util.errors") local Blocks = require("tirenvi.core.blocks") +local config = require("tirenvi.config") local fn = vim.fn @@ -209,7 +210,7 @@ function M.check_command(parser) }) return results end - local installed = util.version_to_integer(installed_version) + local installed = config.version_to_integer(installed_version) if not installed then table.insert(results, { status = "warn", diff --git a/lua/tirenvi/core/record.lua b/lua/tirenvi/core/record.lua index 7dca27a..f1f525f 100644 --- a/lua/tirenvi/core/record.lua +++ b/lua/tirenvi/core/record.lua @@ -1,6 +1,6 @@ local CONST = require("tirenvi.constants") -local config = require("tirenvi.config") local Cell = require("tirenvi.core.cell") +local tir_vim = require("tirenvi.core.tir_vim") local M = {} M.plain = {} @@ -44,15 +44,7 @@ end ---@return Record_grid function M.grid.new_from_vi_line(vi_line) vi_line = vi_line or "" - local pipe = config.marks.pipe - if vi_line:sub(1, #pipe) == pipe then - vi_line = vi_line:sub(#pipe + 1) - end - - if vi_line:sub(- #pipe) == pipe then - vi_line = vi_line:sub(1, - #pipe - 1) - end - local cells = vim.split(vi_line, pipe, { plain = true }) + local cells = tir_vim.get_cells(vi_line) return grid_new(cells) end diff --git a/lua/tirenvi/core/tir_vim.lua b/lua/tirenvi/core/tir_vim.lua new file mode 100644 index 0000000..b42b26f --- /dev/null +++ b/lua/tirenvi/core/tir_vim.lua @@ -0,0 +1,191 @@ +local config = require("tirenvi.config") +local log = require("tirenvi.util.log") + +local pipe = config.marks.pipe +local plen = #pipe + +local M = {} + +-- private helpers + +-- local function str_byteindex(line, char_index) +-- -- local char_index = vim.str_utfindex(str, byte_index) +-- -- vim.fn.strcharpart(str, start, len) +-- return vim.str_byteindex(line, char_index) +-- end + +---@param line string +---@return boolean +local function start_with_pipe(line) + return line:sub(1, plen) == pipe +end + +---@param line string +---@return boolean +local function end_with_pipe(line) + return line:sub(-plen) == pipe +end + +---@param line string +---@return string +local function remove_start_pipe(line) + if start_with_pipe(line) then + line = line:sub(plen + 1) + end + return line +end + +---@param line string +---@return string +local function remove_end_pipe(line) + if end_with_pipe(line) then + line = line:sub(1, -plen - 1) + end + return line +end + +---@param base_pipe boolean +---@param target string +---@return boolean +local function same_block(base_pipe, target) + return base_pipe == M.has_pipe(target) +end + +---@param lines string[] +---@param irow integer +---@param step integer -- -1 or 1 +---@return integer +local function find_block_edge(lines, irow, step) + local base = lines[irow] + local base_pipe = M.has_pipe(base) + local index = irow + step + while index >= 1 and index <= #lines do + if not same_block(base_pipe, lines[index]) then + return index - step + end + index = index + step + end + return (step == -1) and 1 or #lines +end + +-- public API + +-----@param line string +-----@return integer[] +-- function M.get_cell_indexes(line) +-- local ndexes = {} +-- for ichar = 1, #line do +-- if line:sub(ichar, ichar + plen - 1) == pipe then +-- table.insert(ndexes, ichar) +-- end +-- end +-- return {} +-- end + +---@param line string +---@return integer[] +function M.get_pipe_byte_position(line) + local indexes = {} + local index = 1 + while index <= #line do + if line:sub(index, index + plen - 1) == pipe then + indexes[#indexes + 1] = index + index = index + plen + else + index = index + 1 + end + end + if #indexes > 0 then + if indexes[1] ~= 1 then + table.insert(indexes, 1, 0) + end + end + return indexes +end + +-----@param line string +-----@return integer[] +--function M.get_pipe_positions(line) +-- local indexes = M.get_pipe_indexes(line) +-- local positions = {} +-- for _, index in ipairs(indexes) do +-- positions[#positions + 1] = vim.str_utfindex(line, index - 1) + 1 +-- end +-- return positions +--end + +---@param byte_pos integer[] +---@param icol integer +---@return integer|nil +function M.get_current_col_index(byte_pos, icol) + for index, ibyte in ipairs(byte_pos) do + if icol < ibyte then + return index - 1 + end + end + return nil +end + +---@param lines string[] +---@param irow integer +---@return integer +function M.get_block_top_nrow(lines, irow) + return find_block_edge(lines, irow, -1) +end + +---@param lines string[] +---@param irow integer +---@return integer +function M.get_block_bottom_nrow(lines, irow) + return find_block_edge(lines, irow, 1) +end + +---@param count integer +---@return Range|nil +function M.get_block_range(count) +end + +---@param line string +---@return string[] +function M.get_cells(line) + line = remove_start_pipe(line) + line = remove_end_pipe(line) + return vim.split(line, pipe, { plain = true }) +end + +---@param line string +---@return boolean +function M.has_pipe(line) + return line:find(pipe, 1, true) ~= nil +end + +---@param lines string[] +---@param count integer +---@param is_around boolean +---@return Range|nil +function M.get_select(lines, count, is_around) + -- local mode = vim.fn.mode() + local irow, icol0 = unpack(vim.api.nvim_win_get_cursor(0)) + local icol = icol0 + 1 + local cline = vim.api.nvim_get_current_line() + local cbyte_pos = M.get_pipe_byte_position(cline) + if #cbyte_pos == 0 then + return nil + end + local colIndex = M.get_current_col_index(cbyte_pos, icol) + if not colIndex then + return nil + end + local trow = M.get_block_top_nrow(lines, irow) + local brow = M.get_block_bottom_nrow(lines, irow) + local tbyte_pos = M.get_pipe_byte_position(lines[trow]) + local bbyte_pos = M.get_pipe_byte_position(lines[brow]) + return { + start_row = trow, + end_row = brow, + start_col = tbyte_pos[colIndex] + (is_around and 0 or plen), + end_col = bbyte_pos[colIndex + 1] - 1 + } +end + +return M diff --git a/lua/tirenvi/core/vim_parser.lua b/lua/tirenvi/core/vim_parser.lua index 38f8ea5..c68df18 100644 --- a/lua/tirenvi/core/vim_parser.lua +++ b/lua/tirenvi/core/vim_parser.lua @@ -9,6 +9,7 @@ local util = require("tirenvi.util.util") local Blocks = require("tirenvi.core.blocks") local Record = require("tirenvi.core.record") local Attr = require("tirenvi.core.attr") +local tir_vim = require("tirenvi.core.tir_vim") -- local log = require("tirenvi.util.log") local M = {} @@ -39,7 +40,7 @@ end ---@param vi_line string ---@return Record local function tir_vim_to_ndjson(vi_line) - if util.has_pipe(vi_line) then + if tir_vim.has_pipe(vi_line) then return Record.grid.new_from_vi_line(vi_line) else return Record.plain.new_from_vi_line(vi_line) diff --git a/lua/tirenvi/editor/motion.lua b/lua/tirenvi/editor/motion.lua index 61aa2fb..7136ffb 100644 --- a/lua/tirenvi/editor/motion.lua +++ b/lua/tirenvi/editor/motion.lua @@ -1,5 +1,6 @@ local config = require("tirenvi.config") local buf_state = require("tirenvi.state.buf_state") +local tir_vim = require("tirenvi.core.tir_vim") local M = {} @@ -28,4 +29,22 @@ M.F = build_motion("F") M.t = build_motion("t") M.T = build_motion("T") +function M.g() + local bufnr = vim.api.nvim_get_current_buf() + local cursor = vim.api.nvim_win_get_cursor(0) + local row, col = cursor[1], cursor[2] + local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) + local top = tir_vim.get_block_top_nrow(lines, row) + vim.api.nvim_win_set_cursor(0, { top, col }) +end + +function M.G() + local bufnr = vim.api.nvim_get_current_buf() + local cursor = vim.api.nvim_win_get_cursor(0) + local row, col = cursor[1], cursor[2] + local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) + local bottom = tir_vim.get_block_bottom_nrow(lines, row) + vim.api.nvim_win_set_cursor(0, { bottom, col }) +end + return M diff --git a/lua/tirenvi/editor/textobj.lua b/lua/tirenvi/editor/textobj.lua new file mode 100644 index 0000000..00f9b7a --- /dev/null +++ b/lua/tirenvi/editor/textobj.lua @@ -0,0 +1,45 @@ +local tir_vim = require("tirenvi.core.tir_vim") +local buffer = require("tirenvi.state.buffer") +local config = require("tirenvi.config") +local log = require("tirenvi.util.log") + +local M = {} + +---@param is_around boolean|nil +local function setup_vl(is_around) + if vim.fn.mode() == "n" then + return + end + is_around = is_around or false + local count = vim.v.count1 + local lines = buffer.get_lines(0, 0, -1, false) + local pos = tir_vim.get_select(lines, count, is_around) + if not pos then + return + end + vim.api.nvim_win_set_cursor(0, { pos.start_row, pos.start_col - 1, }) + vim.api.nvim_feedkeys(vim.keycode(""), "n", false) + vim.cmd("normal! o") + vim.api.nvim_win_set_cursor(0, { pos.end_row, pos.end_col - 1, }) +end + +function M.setup_vil() + setup_vl() +end + +function M.setup_val() + setup_vl(true) +end + +-- setup +function M.setup(opts) + vim.keymap.set({ "o", "x" }, "i" .. config.textobj.column, M.setup_vil, { + desc = "Inner column", + }) + + vim.keymap.set({ "o", "x" }, "a" .. config.textobj.column, M.setup_val, { + desc = "Around column", + }) +end + +return M diff --git a/lua/tirenvi/init.lua b/lua/tirenvi/init.lua index d59d6cd..e92b887 100644 --- a/lua/tirenvi/init.lua +++ b/lua/tirenvi/init.lua @@ -7,10 +7,10 @@ local log = require("tirenvi.util.log") local buffer = require("tirenvi.state.buffer") local flat_parser = require("tirenvi.core.flat_parser") local vim_parser = require("tirenvi.core.vim_parser") +local tir_vim = require("tirenvi.core.tir_vim") local ui = require("tirenvi.ui") -- module ----@class tirenvi local M = {} local api = vim.api @@ -47,22 +47,20 @@ local function from_flat(bufnr, no_undo) ui.set_lines(bufnr, 0, -1, vi_lines, true, no_undo) end ----@param parser_map Parser[] -local function parse_version(parser_map) - for _, parser in pairs(parser_map) do - parser._iversion = util.version_to_integer(parser.required_version) - end -end - -- public API --- Set up tirenvi plugin (load autocmds and commands) ---@param opts {[string]:any} function M.setup(opts) + if vim.g.tirenvi_initialized then + log.error("tirenvi does not support reload. Please restart Neovim.") + return + end + vim.g.tirenvi_initialized = true config.setup(opts) - parse_version(config.parser_map) require("tirenvi.editor.autocmd").setup() require("tirenvi.editor.commands").setup() + require("tirenvi.editor.textobj").setup(config) require("tirenvi.ui").setup() end @@ -151,7 +149,7 @@ end function M.keymap_lf() local col = fn.col(".") local line = fn.getline(".") - if not util.has_pipe(line) then + if not tir_vim.has_pipe(line) then return api.nvim_replace_termcodes("", true, true, true) end if col == 1 or col > #line then @@ -163,7 +161,7 @@ end ---@return string function M.keymap_tab() local line = fn.getline(".") - if not util.has_pipe(line) then + if not tir_vim.has_pipe(line) then return api.nvim_replace_termcodes("", true, true, true) end if bo.expandtab then diff --git a/lua/tirenvi/state/buf_state.lua b/lua/tirenvi/state/buf_state.lua index 2591a1a..1d78f11 100644 --- a/lua/tirenvi/state/buf_state.lua +++ b/lua/tirenvi/state/buf_state.lua @@ -2,6 +2,7 @@ local log = require("tirenvi.util.log") local errors = require("tirenvi.util.errors") local util = require("tirenvi.util.util") local buffer = require("tirenvi.state.buffer") +local tir_vim = require("tirenvi.core.tir_vim") local M = {} @@ -26,7 +27,7 @@ end local function has_pipe(bufnr) local fl_lines = buffer.get_lines(bufnr, 0, -1, false) for _, fl_line in ipairs(fl_lines) do - if util.has_pipe(fl_line) then + if tir_vim.has_pipe(fl_line) then return true end end diff --git a/lua/tirenvi/types.lua b/lua/tirenvi/types.lua index cf3108d..616cb34 100644 --- a/lua/tirenvi/types.lua +++ b/lua/tirenvi/types.lua @@ -64,3 +64,9 @@ ---@field is_tir_vim? boolean ---@field has_parser? boolean ---@field no_vscode? boolean + +---@class Range +---@field start_row integer +---@field end_row integer +---@field start_col integer +---@field end_col integer diff --git a/lua/tirenvi/util/log.lua b/lua/tirenvi/util/log.lua index 850a206..28e6108 100644 --- a/lua/tirenvi/util/log.lua +++ b/lua/tirenvi/util/log.lua @@ -113,11 +113,24 @@ local function get_timestamp() return string.format("[+%.0fms]", delta_ms) end +local function get_bufnr_by_name(name) + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_get_name(bufnr) == name then + return bufnr + end + end + return nil +end + ---@return boolean local function ensure_log_buf() if log_bufnr and api.nvim_buf_is_valid(log_bufnr) then return log_bufnr end + log_bufnr = get_bufnr_by_name(config.log.buffer_name) + if log_bufnr then + return log_bufnr + end log_bufnr = api.nvim_create_buf(false, true) api.nvim_buf_set_name(log_bufnr, config.log.buffer_name) diff --git a/lua/tirenvi/util/util.lua b/lua/tirenvi/util/util.lua index 52ba9d1..214d20b 100644 --- a/lua/tirenvi/util/util.lua +++ b/lua/tirenvi/util/util.lua @@ -99,12 +99,6 @@ function M.to_hex(str) return table.concat(hex, " ") end ----@param line string ----@return boolean -function M.has_pipe(line) - return line:find(config.marks.pipe, 1, true) ~= nil -end - ---@param array1 any[] ---@param array2 any[] function M.extend(array1, array2) @@ -133,18 +127,4 @@ function M.get_parser(bufnr) return parser end ----@param version any ----@return integer|nil -function M.version_to_integer(version) - if type(version) ~= "string" then - return nil - end - local major, minor, patch = version:match("^(%d+)%.(%d+)%.?(%d*)$") - if not major then - return nil - end - local maj, min, pat = tonumber(major), tonumber(minor), tonumber(patch) or 0 - return (maj * 100000 + min) * 100000 + pat -end - return M diff --git a/tests/cases/check/rg_no_ascii/out-expected.txt b/tests/cases/check/rg_ng_char/out-expected.txt similarity index 100% rename from tests/cases/check/rg_no_ascii/out-expected.txt rename to tests/cases/check/rg_ng_char/out-expected.txt diff --git a/tests/cases/check/rg_ng_char/run.sh b/tests/cases/check/rg_ng_char/run.sh new file mode 100644 index 0000000..44349c9 --- /dev/null +++ b/tests/cases/check/rg_ng_char/run.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu + +rg -g '*.lua' -g '*.sh' -g '*.vim' '[^\x00-\x7F]' $TIRENVI_ROOT > out-actual.txt -- no ascii +rg "\bM:[a-zA-Z_]" $TIRENVI_ROOT/lua | grep -v function >> out-actual.txt -- no colon \ No newline at end of file diff --git a/tests/cases/check/rg_no_ascii/skip-ci b/tests/cases/check/rg_ng_char/skip-ci similarity index 100% rename from tests/cases/check/rg_no_ascii/skip-ci rename to tests/cases/check/rg_ng_char/skip-ci diff --git a/tests/cases/check/rg_no_ascii/run.sh b/tests/cases/check/rg_no_ascii/run.sh deleted file mode 100644 index 799bf75..0000000 --- a/tests/cases/check/rg_no_ascii/run.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -eu - -rg -g '*.lua' -g '*.sh' -g '*.vim' '[^\x00-\x7F]' $TIRENVI_ROOT > out-actual.txt \ No newline at end of file diff --git a/tests/cases/check/rg_no_colon/out-expected.txt b/tests/cases/check/rg_no_colon/out-expected.txt deleted file mode 100644 index e69de29..0000000 diff --git a/tests/cases/check/rg_no_colon/run.sh b/tests/cases/check/rg_no_colon/run.sh deleted file mode 100644 index cc54a48..0000000 --- a/tests/cases/check/rg_no_colon/run.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -eu - -rg "\bM:[a-zA-Z_]" $TIRENVI_ROOT/lua | grep -v function > out-actual.txt \ No newline at end of file diff --git a/tests/cases/error/invalid-table2/run.vim b/tests/cases/error/invalid-table2/run.vim index 2e99823..bfffdf2 100644 --- a/tests/cases/error/invalid-table2/run.vim +++ b/tests/cases/error/invalid-table2/run.vim @@ -2,6 +2,16 @@ source $TIRENVI_ROOT/tests/common.vim +lua << EOF +local M = require("tirenvi") +M.setup({ + log = { + output = "file", -- "notify" | "buffer" | "print" | "file" + file_name = "/tmp/tirenvi.log", + }, +}) +EOF + edit $TIRENVI_ROOT/tests/data/simple.csv Tir toggle call cursor(2, 1) diff --git a/tests/cases/error/no-mark/run.vim b/tests/cases/error/no-mark/run.vim index 45a60c8..8796a97 100644 --- a/tests/cases/error/no-mark/run.vim +++ b/tests/cases/error/no-mark/run.vim @@ -8,6 +8,10 @@ M.setup({ marks = { pipe = "a" }, + log = { + output = "buffer", -- "notify" | "buffer" | "print" | "file" + buffer_name = "tirenvi://log", + }, }) EOF diff --git a/tests/cases/motion/ftg/out-expected.txt b/tests/cases/motion/ftg/out-expected.txt new file mode 100644 index 0000000..c5ca91e --- /dev/null +++ b/tests/cases/motion/ftg/out-expected.txt @@ -0,0 +1,118 @@ +=== MESSAGE === + +=== DISPLAY === + +This document contains multiple tables embedded in normal text. +It is intended to test GFM table parsing. + +--- + +## 1. Simple table +│----⠀│---│----⠀⠀│ +│Alice│23⠀│Tokyo⠀│ +│Bob⠀⠀│31⠀│Osaka⠀│ + +Some text between tables. +This should *not* be part of any table. + +--- + +## 2. Alignment test + +│Left│Center│Right│ +│:---│:----:│----:│ +│a⠀⠀⠀ +│10⠀⠀│20⠀⠀⠀⠀│30⠀⠀⠀│ +│foo⠀│bar⠀⠀⠀│baz⠀⠀│ + +--- + +## 3. Table with inline formatting + +│Key⠀│Description⠀⠀⠀⠀│Example⠀⠀⠀⠀│ +│---⠀│-----------⠀⠀⠀⠀│-------⠀⠀⠀⠀│ +│`id`│**Primary key**│`user_001`⠀│ +│name│_Display name_⠀│**Alice**⠀⠀│ +│note│Free text⠀⠀⠀⠀⠀⠀│`a | b | c`│ + +Note: escaped pipes should be preserved. + +--- + +## 4. Different column count (block separation test) + +│A│B│ +│-│-│ +│1│2│ +│3│4│ + +Text in between. + +│A│B│C│D│ +│-│-│-│-│ +│1│2│3│4│ +│5│6│7│8│ + +--- + +## 5. Table without leading/trailing empty lines +│X⠀│Y⠀│ +│-⠀│-⠀│ +│x1│y1│ +│x2│y2│ +Text immediately after table. + +--- + +## 6. Table inside a section with lists + +- item 1 +- item 2 + +│Feature│Status│Comment⠀⠀⠀⠀│ +│-------│------│-------⠀⠀⠀⠀│ +│parser⠀│OK⠀⠀⠀⠀│fast⠀⠀⠀⠀⠀⠀⠀│ +│writer⠀│WIP⠀⠀⠀│needs tests│ +│diff⠀⠀⠀│TODO⠀⠀│later⠀⠀⠀⠀⠀⠀│ + +- item 3 +- item 4 + +--- + +## 7. Mixed content, many small tables + +### Metrics + +│Metric│Value│ +│------│-----│ +│rows⠀⠀│120⠀⠀│ +│cols⠀⠀│8⠀⠀⠀⠀│ + +### Limits + +│Name│Max⠀│ +│----│---⠀│ +│rows│1000│ +│cols│64⠀⠀│ + +### Flags + +│Flag│Meaning│ +│----│-------│ +│`-v`│verbose│ +│`-q`│quiet⠀⠀│ + +--- + +## 8. Edge-ish cases + +│Col1⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│Col2⠀│ +│----⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│----⠀│ +│trailing space│value│ +│empty⠀⠀⠀⠀⠀⠀⠀⠀⠀│⠀⠀⠀⠀⠀│ + +--- + +End of document. + diff --git a/tests/cases/motion/ftg/run.vim b/tests/cases/motion/ftg/run.vim new file mode 100644 index 0000000..616fe12 --- /dev/null +++ b/tests/cases/motion/ftg/run.vim @@ -0,0 +1,30 @@ +" Verify the screen display after executing the Tir redraw command. +" After executing a command that misaligns the border positions, the borders are aligned. + +source $TIRENVI_ROOT/tests/common.vim + +lua << EOF +vim.keymap.set({ 'n', 'o', 'x' }, 'gtf', require('tirenvi').motion.f, { expr = true, desc = '[T]irEnvi: f pipe' }) +vim.keymap.set({ 'n', 'o', 'x' }, 'gtF', require('tirenvi').motion.F, { expr = true, desc = '[T]irEnvi: F pipe' }) +vim.keymap.set({ 'n', 'o', 'x' }, 'gtt', require('tirenvi').motion.t, { expr = true, desc = '[T]irEnvi: t pipe' }) +vim.keymap.set({ 'n', 'o', 'x' }, 'gtT', require('tirenvi').motion.T, { expr = true, desc = '[T]irEnvi: T pipe' }) +vim.keymap.set('n', 'gtg', require('tirenvi').motion.g, { desc = '[T]irEnvi: block top' }) +vim.keymap.set('n', 'gtG', require('tirenvi').motion.G, { desc = '[T]irEnvi: block bottom' }) +EOF + +edit $TIRENVI_ROOT/tests/data/complex.md +call cursor(2, 1) +call feedkeys("gtg", "x") +execute "normal dd" +call feedkeys("gtG", "x") +execute "normal dd" +call cursor(11, 1) +call feedkeys("gtg", "x") +execute "normal dd" +call feedkeys("gtG", "x") +execute "normal dd" +call cursor(21, 1) +call feedkeys("gtf", "x") +execute "normal D" + +call RunTest({}) \ No newline at end of file diff --git a/tests/cases/textobj/val/out-expected.txt b/tests/cases/textobj/val/out-expected.txt new file mode 100644 index 0000000..4c6ec80 --- /dev/null +++ b/tests/cases/textobj/val/out-expected.txt @@ -0,0 +1,11 @@ +=== MESSAGE === +block of 5 lines yanked + +=== DISPLAY === +gfm +│Name⠀│Age│City⠀⠀│Age│ +│----⠀│---│----⠀⠀│---│ +│Alice│23⠀│Tokyo⠀│23⠀│ +│Bob⠀⠀│31⠀│Osaka⠀│31⠀│ +│Carol│27⠀│Nagoya│27⠀│ +markdown diff --git a/tests/cases/textobj/val/run.vim b/tests/cases/textobj/val/run.vim new file mode 100644 index 0000000..acc69b1 --- /dev/null +++ b/tests/cases/textobj/val/run.vim @@ -0,0 +1,19 @@ +source $TIRENVI_ROOT/tests/common.vim + +lua << EOF +local M = require("tirenvi") +M.setup({ + textobj = { + column = "h" + }, +}) +EOF + +edit $TIRENVI_ROOT/tests/data/simple.md +call cursor(6, 12) +call feedkeys("vah", "x") +execute "normal y" +execute "normal $" +execute "normal P" + +call RunTest({}) \ No newline at end of file diff --git a/tests/cases/textobj/vil/out-expected.txt b/tests/cases/textobj/vil/out-expected.txt new file mode 100644 index 0000000..1eac5ca --- /dev/null +++ b/tests/cases/textobj/vil/out-expected.txt @@ -0,0 +1,10 @@ +=== MESSAGE === + +=== DISPLAY === +gfm +│City⠀⠀│Age││ +│----⠀⠀│---││ +│Tokyo⠀│23⠀││ +│Osaka⠀│31⠀││ +│Nagoya│27⠀││ +markdown diff --git a/tests/cases/textobj/vil/run.vim b/tests/cases/textobj/vil/run.vim new file mode 100644 index 0000000..636ab92 --- /dev/null +++ b/tests/cases/textobj/vil/run.vim @@ -0,0 +1,13 @@ +source $TIRENVI_ROOT/tests/common.vim + +edit $TIRENVI_ROOT/tests/data/simple.md +call cursor(2, 1) +call feedkeys("vil", "x") +execute "normal d" +call cursor(4, 15) +call feedkeys("vil", "x") +execute "normal d" +execute "normal 0" +execute "normal p" + +call RunTest({}) \ No newline at end of file diff --git a/tests/common.vim b/tests/common.vim index d328678..7184973 100644 --- a/tests/common.vim +++ b/tests/common.vim @@ -24,8 +24,8 @@ M.setup({ -- probe = true, output = "print", }, - }) +vim.g.tirenvi_initialized = false EOF " ----------------------------