Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry committed Jun 23, 2024
1 parent 2f6490e commit 10665f9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 52 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: pip install codespell

- name: Use codespell
run: make spell
run: codespell --quiet-level=2 --check-hidden --skip=./.git,./CHANGELOG.md

generate-doc:
runs-on: ubuntu-latest
Expand All @@ -59,6 +59,25 @@ jobs:
with:
commit_message: "docs: auto-generate vimdoc"

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Neovim & Dependencies
run: |
mkdir -p /tmp/nvim
wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage
cd /tmp/nvim
chmod a+x ./nvim.appimage
./nvim.appimage --appimage-extract
echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH
- name: Run Tests
run: |
nvim --version
nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.lua', sequential = true}"
release:
runs-on: ubuntu-latest
needs: [stylua, selene, codespell, generate-doc]
Expand Down
48 changes: 0 additions & 48 deletions Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions lua/telescope/_extensions/resession/utils.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local M = {}
local internal_substitutions = {
M.internal_substitutions = {
{ find = ":/", replace = "__" },
{ find = "/", replace = "_" },
}
Expand Down Expand Up @@ -32,7 +32,7 @@ end
M.encode_session = function(session_str, opts)
local user_substitutions = opts.path_substitutions or {}
session_str = M.apply_substitutions(session_str, user_substitutions, true)
session_str = M.apply_substitutions(session_str, internal_substitutions)
session_str = M.apply_substitutions(session_str, M.internal_substitutions)

return session_str
end
Expand All @@ -43,7 +43,7 @@ end
--- @return string[] The decoded session strings
M.decode_sessions = function(sessions, opts)
for i, session in ipairs(sessions) do
session = M.apply_substitutions(session, internal_substitutions, true)
session = M.apply_substitutions(session, M.internal_substitutions, true)
session = M.apply_substitutions(session, opts.path_substitutions)
sessions[i] = session
end
Expand Down
13 changes: 13 additions & 0 deletions tests/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local plenary_dir = os.getenv("PLENARY_DIR") or "/tmp/plenary.nvim"
local is_not_a_directory = vim.fn.isdirectory(plenary_dir) == 0
if is_not_a_directory then
vim.fn.system({ "git", "clone", "https://github.com/nvim-lua/plenary.nvim", plenary_dir })
end

vim.opt.rtp:append(".")
vim.opt.rtp:append(plenary_dir)

vim.cmd("runtime plugin/plenary.vim")
require("plenary.busted")

print("Running tests...")
45 changes: 45 additions & 0 deletions tests/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local utils = require("telescope._extensions.resession.utils")

describe("apply_substitutions", function()
it("should apply substitutions to a session string", function()
local session = "C__Users_user_AppData_Local_nvim"
local substitutions = utils.internal_substitutions
local result = utils.apply_substitutions(session, substitutions, true)
assert.are.same("C:/Users/user/AppData/Local/nvim", result)
end)

it("should apply substitutions in reverse to a session string", function()
local session = "C:/Users/user/AppData/Local/nvim"
local substitutions = utils.internal_substitutions
local result = utils.apply_substitutions(session, substitutions)
assert.are.same("C__Users_user_AppData_Local_nvim", result)
end)

it("should apply substitutions to a session string with user substitutions", function()
local session = "C:/Users/user/AppData/Local/nvim"
local substitutions = {
{ find = "C:/", replace = "D:/" },
{ find = "nvim", replace = "neovim" },
}
local result = utils.apply_substitutions(session, substitutions)
assert.are.same("D:/Users/user/AppData/Local/neovim", result)
end)
end)

describe("encode_session", function()
it("should encode a session string", function()
local session = "D:/Users/user/AppData/Local/neovim"
local opts = { path_substitutions = { { find = "C:/", replace = "D:/" } } }
local result = utils.encode_session(session, opts)
assert.are.same("C__Users_user_AppData_Local_neovim", result)
end)
end)

describe("decode_sessions", function()
it("should decode a list of session strings", function()
local sessions = { "C__Users_user_AppData_Local_neovim" }
local opts = { path_substitutions = { { find = "C:/", replace = "D:/" } } }
local result = utils.decode_sessions(sessions, opts)
assert.are.same({ "D:/Users/user/AppData/Local/neovim" }, result)
end)
end)

0 comments on commit 10665f9

Please sign in to comment.