diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23931ea..de0afd6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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] diff --git a/Makefile b/Makefile deleted file mode 100644 index cd6dea3..0000000 --- a/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -ifeq ($(OS),Windows_NT) - GREEN= - RESTORE= -else - GREEN="\033[0;32m" - RESTORE="\033[0m" -endif - -# make the output of the message appear green -define style_calls - $(eval $@_msg = $(1)) - echo ${GREEN}${$@_msg}${RESTORE} -endef - -lint: style-lint - @$(call style_calls,"Running selene") - @selene --display-style quiet --config ./.selene.toml lua - @$(call style_calls,"Done!") - -.PHONY: lint - -style-lint: - @$(call style_calls,"Running stylua check") - @stylua --color always -f ./.stylua.toml --check lua - @$(call style_calls,"Done!") - -.PHONY: style-lint - -format: - @$(call style_calls,"Running stylua format") - @stylua --color always -f ./.stylua.toml lua - @$(call style_calls,"Done!") - -.PHONY: format - -spell: - @$(call style_calls,"Running codespell check") - @codespell --quiet-level=2 --check-hidden --skip=./.git,./CHANGELOG.md - @$(call style_calls,"Done!") - -.PHONY: spell - -spell-write: - @$(call style_calls,"Running codespell write") - @codespell --quiet-level=2 --check-hidden --skip=./.git,./CHANGELOG.md --write-changes - @$(call style_calls,"Done!") - -.PHONY: spell-write diff --git a/lua/telescope/_extensions/resession/utils.lua b/lua/telescope/_extensions/resession/utils.lua index b38e7c3..743f29b 100644 --- a/lua/telescope/_extensions/resession/utils.lua +++ b/lua/telescope/_extensions/resession/utils.lua @@ -1,5 +1,5 @@ local M = {} -local internal_substitutions = { +M.internal_substitutions = { { find = ":/", replace = "__" }, { find = "/", replace = "_" }, } @@ -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 @@ -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 diff --git a/tests/init.lua b/tests/init.lua new file mode 100644 index 0000000..4a6409f --- /dev/null +++ b/tests/init.lua @@ -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...") diff --git a/tests/utils_spec.lua b/tests/utils_spec.lua new file mode 100644 index 0000000..080fcd2 --- /dev/null +++ b/tests/utils_spec.lua @@ -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)