forked from cursorless-dev/cursorless
-
Notifications
You must be signed in to change notification settings - Fork 0
Add basic lua tests #7
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
72c7c9b
initial lua test skeleton
fidgetingbits dcaab6f
feat: test adding busted workflow
fidgetingbits 682c520
fix: only install busted on Linux
d113ab8
refactor: Address review feedback
fidgetingbits e54d40e
fix: change workflows to actually work
fidgetingbits b7a80c1
fix: Address review feedback
fidgetingbits 822966d
Merge remote-tracking branch 'saidelike/nvim-talon' into lua-tests
fidgetingbits 1bff727
fix: Address task.json feedback
fidgetingbits 4689557
docs: Add neovim lua test architecture section
fidgetingbits d1be1ea
refactor: switch to standalone neovim lua test action
fidgetingbits 13514bc
fix: Remove unneeded luaVersion entry for luarocks
fidgetingbits 3bef660
docs: review busted tests documentation
d08005b
refactor: print each test name as they run
fidgetingbits 2f0f693
refactor: rename task
5c99334
refactor: better output for lua tests
1be17b8
Merge branch 'nvim-talon' into lua-tests
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 $@ | ||
fidgetingbits marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exit_code=$? | ||
|
||
rm -rf "${test_folder}" | ||
|
||
exit $exit_code |
This file contains hidden or 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) | ||
fidgetingbits marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.