-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected result of getSelectText()
#47
Merged
Merged
Changes from 23 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
e2ce146
fixed
AgatZan 2c885de
fix: select text confirm
AgatZan 0a39831
ci: introduce
AgatZan 54a8a51
ci: introduce
AgatZan e860077
ci: introduce
AgatZan 9397259
ci: introduce
AgatZan 97208f3
ci: macos add
AgatZan bac2a4b
ci: introduce mini.test
AgatZan fb6fff6
ci: test fail
AgatZan ec91580
Merge pull request #51 from AgatZan/ci-test_mini.test
LintaoAmons 7df3daa
fixed
AgatZan 1867e9d
fix: select text confirm
AgatZan c382a79
test(utils): add test for `get_selected`
AgatZan f9b8651
test(utils): Add test to get_select
AgatZan 5a340ef
Merge branch 'issue-wrong_select' of https://github.com/AgatZan/scrat…
AgatZan 13a1fe0
remove useless test
AgatZan b0e7afb
fix(utils): Add backward compatibility
AgatZan 330b19e
fix(utils): not found getregion
AgatZan 94c1b39
fix(utils/get_selected): Fix indexes
AgatZan 5c6022b
test(utils): Add test for command mode
AgatZan b729f0f
fix(utils): Remove getregion
AgatZan 8eace59
fix(test): Selector work with raw termcode
AgatZan e4af357
test(utils): remove test for old realisation
AgatZan 7be4324
fix(init): Make reaction to range
AgatZan a305d28
fix(init): Choose line at `:Scratch` correct
AgatZan c3d5628
test(utils): `get_select` to empty file
AgatZan 993924e
test(utils/get_selected_text): coord an array
AgatZan a35bfef
test(utils/get_selected_text): correct left comparer
AgatZan b95f545
test(utils/get_selected_text): coord an array with empty string
AgatZan 52dbf4c
test(utils/get_selected_text): empty file is array of 1 empty string
AgatZan 2b3572e
test(utils/get_selected_text): select mark is `.`
AgatZan 7344ebd
test(init): introduce test of `:Scratch`
AgatZan a172984
test(init): fullfile mock of scratch_api
AgatZan a7c9d1c
test(init): Fix set keymap
AgatZan d36cbee
fix(init): add NOTE to `:Scratch`
AgatZan ec95906
test(init): log `_G.scratch_opts`
AgatZan 012fef0
revert(test/log)
AgatZan 71c2aca
ci(test): Add timeout
AgatZan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: default | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
run_tests: | ||
name: unit tests | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
neovim_version: ['v0.8.3', 'v0.9.5', 'v0.10.2', 'nightly'] | ||
include: | ||
- os: macos-latest | ||
neovim_version: v0.10.1 | ||
- os: windows-latest | ||
neovim_version: v0.10.1 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup neovim | ||
uses: rhysd/action-setup-vim@v1 | ||
with: | ||
neovim: true | ||
version: ${{ matrix.neovim_version }} | ||
- name: Run tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
test: deps/mini.nvim | ||
nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua MiniTest.run()" | ||
|
||
# Run test from file at `$FILE` environment variable | ||
test_file: deps/mini.nvim | ||
nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua MiniTest.run_file('$(FILE)')" | ||
|
||
# Download 'mini.nvim' to use its 'mini.test' testing module | ||
deps/mini.nvim: | ||
@mkdir -p deps | ||
git clone --filter=blob:none https://github.com/echasnovski/mini.nvim $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Add current directory to 'runtimepath' to be able to use 'lua' files | ||
vim.cmd([[let &rtp.=','.getcwd()]]) | ||
|
||
-- Set up 'mini.test' only when calling headless Neovim (like with `make test`) | ||
if #vim.api.nvim_list_uis() == 0 then | ||
-- Add 'mini.nvim' to 'runtimepath' to be able to use 'mini.test' | ||
-- Assumed that 'mini.nvim' is stored in 'deps/mini.nvim' | ||
vim.cmd("set rtp+=deps/mini.nvim") | ||
|
||
-- Set up 'mini.test' | ||
require("mini.test").setup() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
local child = MiniTest.new_child_neovim() | ||
local getSelectedText | ||
local function table_select(text, coord, selection_mode) | ||
local lines = {} | ||
local start_row, start_col, end_row, end_col = coord[1], coord[2], coord[3], coord[4] | ||
if selection_mode == "v" then | ||
table.insert(lines, text[start_row]:sub(start_col)) | ||
for i = start_row + 1, end_row do | ||
table.insert(lines, text[i]) | ||
end | ||
local ind = end_row - start_row + 1 | ||
lines[ind] = lines[ind]:sub(1, end_col) | ||
elseif selection_mode == "V" then | ||
for i = start_row, end_row do | ||
table.insert(lines, text[i]) | ||
end | ||
elseif selection_mode == vim.api.nvim_replace_termcodes("<C-V>", true, true, true) then | ||
for i = start_row, end_row do | ||
table.insert(lines, text[i]:sub(start_col, end_col)) | ||
end | ||
end | ||
return lines | ||
end | ||
local select_wise = function(coord, selection_mode) | ||
local vim = child | ||
local start_row, start_col, end_row, end_col = coord[1], coord[2], coord[3], coord[4] | ||
local mode = vim.api.nvim_get_mode() | ||
if mode.mode ~= "n" then | ||
local esc = vim.api.nvim_replace_termcodes("<ESC>", true, true, true) | ||
vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { esc } }, {}) | ||
vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { esc } }, {}) | ||
end | ||
selection_mode = vim.api.nvim_replace_termcodes(selection_mode, true, true, true) | ||
vim.api.nvim_cmd({ cmd = "normal", bang = true, args = { selection_mode } }, {}) | ||
|
||
vim.api.nvim_win_set_cursor(0, { start_row, start_col - 1 }) | ||
vim.cmd("normal! o") | ||
vim.api.nvim_win_set_cursor(0, { end_row, end_col - 1 }) | ||
end | ||
|
||
-- local function old_real(mark, mode) | ||
-- local _, csrow, cscol, _ = unpack(vim.fn.getpos("'<")) | ||
-- local _, cerow, cecol, _ = unpack(vim.fn.getpos("'>")) | ||
-- | ||
-- local lines = vim.fn.getline(csrow, cerow) | ||
-- local n = #lines | ||
-- if n <= 0 then | ||
-- return {} | ||
-- end | ||
-- lines[n] = string.sub(lines[n], 1, cecol) | ||
-- lines[1] = string.sub(lines[1], cscol) | ||
-- return lines | ||
-- end | ||
|
||
local new_set = MiniTest.new_set | ||
local T = new_set({ | ||
parametrize = { { "v" }, { "V" }, { vim.api.nvim_replace_termcodes("<C-V>", true, true, true) } }, | ||
}) | ||
T["param"] = new_set({ | ||
parametrize = { | ||
{ | ||
{ 1, 1, 1, 4 }, | ||
}, | ||
{ | ||
{ 1, 2, 1, 4 }, | ||
}, | ||
{ | ||
{ 2, 1, 3, 4 }, | ||
}, | ||
{ | ||
{ 1, 1, 2, 2 }, | ||
}, | ||
{ | ||
{ 1, 1, 1, 1 }, | ||
}, | ||
{ | ||
{ 1, 1, 4, 4 }, | ||
}, | ||
}, | ||
}) | ||
local BUFFER_TEXT = { | ||
"some", | ||
"text here will be", | ||
"inserted", | ||
"now", | ||
} | ||
-- T["param"]["old"] = new_set({ | ||
-- hooks = { | ||
-- pre_case = function() | ||
-- child.restart({ "-u", "scripts/minimal_init.lua" }) | ||
-- child.api.nvim_buf_set_lines(0, 0, -1, false, BUFFER_TEXT) | ||
-- end, | ||
-- post_case = function() | ||
-- child.stop() | ||
-- end, | ||
-- }, | ||
-- }) | ||
T["param"]["new"] = new_set({ | ||
hooks = { | ||
pre_case = function() | ||
child.restart({ "-u", "scripts/minimal_init.lua" }) | ||
child.api.nvim_buf_set_lines(0, 0, -1, false, BUFFER_TEXT) | ||
getSelectedText = require("scratch.utils").getSelectedText | ||
end, | ||
post_case = function() | ||
child.stop() | ||
end, | ||
}, | ||
n_retry = 2, | ||
}) | ||
-- T["param"]["old"]["not_workd"] = function(selection_mode, coord) | ||
-- select_wise(coord, selection_mode) | ||
-- MiniTest.expect.no_equality( | ||
-- table_select(BUFFER_TEXT, coord, selection_mode), | ||
-- child.lua_func(old_real) | ||
-- ) | ||
-- end | ||
T["param"]["new"]["workd"] = function(selection_mode, coord) | ||
select_wise(coord, selection_mode) | ||
MiniTest.expect.equality( | ||
table_select(BUFFER_TEXT, coord, selection_mode), | ||
child.lua_func(getSelectedText, ".", selection_mode) | ||
) | ||
end | ||
-- T["param"]["old"]["at_command"] = function(selection_mode, coord) | ||
-- select_wise(coord, selection_mode) | ||
-- child.type_keys(":") | ||
-- MiniTest.expect.equality( | ||
-- table_select(BUFFER_TEXT, coord, selection_mode), | ||
-- child.lua_func(old_real) | ||
-- ) | ||
-- end | ||
T["param"]["new"]["at_command"] = function(selection_mode, coord) | ||
select_wise(coord, selection_mode) | ||
child.type_keys(":") | ||
MiniTest.add_note("|1>--- " .. vim.inspect(child.fn.getpos("'>"))) | ||
MiniTest.add_note("|2>--- " .. vim.inspect(child.fn.getpos("."))) | ||
MiniTest.expect.equality( | ||
table_select(BUFFER_TEXT, coord, selection_mode), | ||
child.lua_func(getSelectedText, "'>", selection_mode) | ||
) | ||
end | ||
|
||
return T |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes, that test suits works, sometimes it doesn't, but I have refactored the function for that use case, so this doesn't matter.