forked from cursorless-dev/cursorless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from fidgetingbits/lua-tests
- Loading branch information
Showing
15 changed files
with
238 additions
and
18 deletions.
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,17 @@ | ||
name: "Neovim Lua Tests" | ||
description: "Set up Neovim Lua environment and run Busted tests" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: leafo/gh-actions-lua@v9 | ||
with: | ||
luaVersion: "luajit-2.1.0-beta3" | ||
- uses: leafo/gh-actions-luarocks@v4 | ||
- shell: bash | ||
run: | | ||
luarocks install busted | ||
luarocks install luafilesystem | ||
- shell: bash | ||
run: | | ||
cd cursorless.nvim | ||
busted --run unit |
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
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,10 @@ | ||
return { | ||
_all = { | ||
lua = './test/nvim-shim.sh', | ||
output = "TAP", | ||
["defer-print"] = false, | ||
}, | ||
unit = { | ||
ROOT = {'./test/unit/'}, | ||
}, | ||
} |
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,16 @@ | ||
-- This file gets linked into plugin/helpers.lua of busted nvim config | ||
-- Functions that are exposed to all tests | ||
|
||
function _G.get_selected_text() | ||
local _, ls, cs = unpack(vim.fn.getpos("v")) | ||
local _, le, ce = unpack(vim.fn.getpos(".")) | ||
return vim.api.nvim_buf_get_text(0, ls - 1, cs - 1, le - 1, ce, {}) | ||
end | ||
|
||
function _G.convert_table_entries(tbl, func) | ||
local mapped = {} | ||
for k, v in pairs(tbl) do | ||
mapped[k] = func(v) | ||
end | ||
return mapped | ||
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,28 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
if ! [[ "${PWD}" == *"cursorless.nvim" ]]; then | ||
echo "ERROR: This script must be run from inside cursorless.nvim/ directory" | ||
exit 1 | ||
fi | ||
|
||
test_folder=$(mktemp -d "${TMPDIR-/tmp}"/cursorless-busted-test-XXXXX) | ||
export XDG_CONFIG_HOME="${test_folder}/xdg/config/" | ||
export XDG_STATE_HOME="${test_folder}/xdg/local/state/" | ||
export XDG_DATA_HOME="${test_folder}/xdg/local/share/" | ||
dependency_folder="${XDG_DATA_HOME}/nvim/site/pack/testing/start/" | ||
plugin_folder="${XDG_CONFIG_HOME}/nvim/plugin/" | ||
|
||
mkdir -p "${plugin_folder}" "${XDG_STATE_HOME}" "${dependency_folder}" | ||
ln -sf "${PWD}" "${dependency_folder}/cursorless.nvim" | ||
|
||
# Link in standalone helper functions we want all tests to be able to call | ||
ln -sf "${PWD}/test/helpers.lua" "${plugin_folder}/helpers.lua" | ||
|
||
# shellcheck disable=SC2068 | ||
command nvim --cmd 'set loadplugins' -l $@ | ||
exit_code=$? | ||
|
||
rm -rf "${test_folder}" | ||
|
||
exit $exit_code |
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,79 @@ | ||
describe("", function() | ||
local cursorless = require("cursorless.cursorless") | ||
|
||
describe("window_get_visible_lines() ->", function() | ||
it("can read one visible line", function() | ||
local pos = vim.api.nvim_win_get_cursor(0)[2] | ||
local line = vim.api.nvim_get_current_line() | ||
local nline = line:sub(0, pos) .. "hello" .. line:sub(pos + 1) | ||
vim.api.nvim_set_current_line(nline) | ||
|
||
local visible = cursorless.window_get_visible_lines() | ||
assert(table.concat(visible) == table.concat({ 1, 1 })) | ||
end) | ||
|
||
it("can read all lines visible on the window", function() | ||
local maxlines = vim.api.nvim_win_get_height(0) | ||
local lines = {} | ||
for _ = 1, (maxlines + 1) do | ||
table.insert(lines, "hello ") | ||
end | ||
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines) | ||
local visible = cursorless.window_get_visible_lines() | ||
assert(table.concat(visible) == table.concat({ 1, maxlines })) | ||
end) | ||
end) | ||
describe("select_range() ->", function() | ||
it("selects the specified range", function() | ||
local lines = "hello world" | ||
vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.split(lines, "\n")) | ||
cursorless.select_range(1, 2, 1, 4) | ||
|
||
assert(table.concat(_G.get_selected_text()) == "llo") | ||
end) | ||
end) | ||
describe("buffer_get_selection() ->", function() | ||
it( | ||
"can get the forward selection in a format expected by cursorless", | ||
function() | ||
local lines = "hello world" | ||
vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.split(lines, "\n")) | ||
cursorless.select_range(1, 2, 1, 4) | ||
assert( | ||
table.concat( | ||
_G.convert_table_entries( | ||
cursorless.buffer_get_selection(), | ||
tostring | ||
), | ||
", " | ||
) | ||
== table.concat( | ||
_G.convert_table_entries({ 1, 3, 1, 5, false }, tostring), | ||
", " | ||
) | ||
) | ||
end | ||
) | ||
it( | ||
"can get the backward selection in a format expected by cursorless", | ||
function() | ||
local lines = "hello world" | ||
vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.split(lines, "\n")) | ||
cursorless.select_range(1, 4, 1, 2) | ||
assert( | ||
table.concat( | ||
_G.convert_table_entries( | ||
cursorless.buffer_get_selection(), | ||
tostring | ||
), | ||
", " | ||
) | ||
== table.concat( | ||
_G.convert_table_entries({ 1, 3, 1, 5, true }, tostring), | ||
", " | ||
) | ||
) | ||
end | ||
) | ||
end) | ||
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
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
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