diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd1ac05..be5b158 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,88 +1,85 @@ name: CI on: push: { branches: ["0.x"] } pull_request: { branches: ["0.x"] } jobs: luacheck: name: Luacheck runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Install luarocks run: sudo apt update && sudo apt install -y luarocks - name: Install luacheck run: sudo luarocks install luacheck - name: Run luacheck run: luacheck . stylua: name: StyLua runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Run stylua uses: JohnnyMorganz/stylua-action@v4.0.0 with: token: ${{ secrets.GITHUB_TOKEN }} version: latest args: --check . cargo-format: name: Cargo Format runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Set up rust uses: dtolnay/rust-toolchain@stable with: components: rustfmt - name: Lint run: cargo fmt --check test: name: Build and test runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Set up rust uses: dtolnay/rust-toolchain@stable - name: Install dependencies - run: sudo apt update && sudo apt install -y luajit build-essential luarocks + run: sudo apt update && sudo apt install -y build-essential luarocks - name: Install busted run: sudo luarocks install busted - name: Install neovim run: | test -d _neovim || { mkdir -p _neovim curl -sL "https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz" | tar xzf - --strip-components=1 -C "${PWD}/_neovim" } - name: Build run: cargo build --release - - name: Test - run: find lua -name "*_test.lua" | xargs luajit scripts/test.lua - - name: Run tests run: | export PATH="${PWD}/_neovim/bin:${PATH}" export VIM="${PWD}/_neovim/share/nvim/runtime" nvim --version nvim -l ./scripts/busted.lua ./lua diff --git a/lua/ivy/controller_test.lua b/lua/ivy/controller_test.lua deleted file mode 100644 index 9865142..0000000 --- a/lua/ivy/controller_test.lua +++ /dev/null @@ -1,51 +0,0 @@ -local vim_mock = require "ivy.vim_mock" -local window = require "ivy.window" -local controller = require "ivy.controller" - --- The number of the mock buffer where all the test completions gets put -local buffer_number = 10 - -before_each(function() - vim_mock.reset() - window.initialize() -end) - -after_each(function() - controller.destroy() -end) - -it("will run", function(t) - controller.run("Testing", function() - return { { content = "Some content" } } - end, function() - return {} - end) - - local lines = vim_mock.get_lines() - local completion_lines = lines[buffer_number] - - t.assert_equal(#completion_lines, 1) - t.assert_equal(completion_lines[1], "Some content") -end) - -it("will not try and highlight the buffer if there is nothing to highlight", function(t) - controller.items = function() - return { { content = "Hello" } } - end - - controller.update "" - local commands = vim_mock.get_commands() - t.assert_equal(#commands, 1) -end) - -it("will escape a - when passing it to be highlighted", function(t) - controller.items = function() - return { { content = "Hello" } } - end - - controller.update "some-file" - local commands = vim_mock.get_commands() - local syntax_command = commands[2] - - t.assert_equal("syntax match IvyMatch '[some\\-file]'", syntax_command) -end) diff --git a/lua/ivy/libivy_test.lua b/lua/ivy/libivy_test.lua deleted file mode 100644 index fe18455..0000000 --- a/lua/ivy/libivy_test.lua +++ /dev/null @@ -1,46 +0,0 @@ -local libivy = require "ivy.libivy" - -it("should run a simple match", function(t) - local score = libivy.ivy_match("term", "I am a serch term") - - if score <= 0 then - t.error("Score should not be less than 0 found " .. score) - end -end) - -it("should find a dot file", function(t) - local current_dir = libivy.ivy_cwd() - local results = libivy.ivy_files(".github/workflows/ci.yml", current_dir) - - if results.length ~= 2 then - t.error("Incorrect number of results found " .. results.length) - end - - if results[2].content ~= ".github/workflows/ci.yml" then - t.error("Invalid matches: " .. results[2].content) - end -end) - -it("will allow you to access the length via the metatable", function(t) - local current_dir = libivy.ivy_cwd() - local results = libivy.ivy_files(".github/workflows/ci.yml", current_dir) - - local mt = getmetatable(results) - - if results.length ~= mt.__len(results) then - t.error "The `length` property does not match the __len metamethod" - end -end) - -it("will create an iterator", function(t) - local iter = libivy.ivy_files(".github/workflows/ci.yml", libivy.ivy_cwd()) - local mt = getmetatable(iter) - - if type(mt["__index"]) ~= "function" then - t.error "The iterator does not have an __index metamethod" - end - - if type(mt["__len"]) ~= "function" then - t.error "The iterator does not have an __len metamethod" - end -end) diff --git a/lua/ivy/matcher_test.lua b/lua/ivy/matcher_test.lua deleted file mode 100644 index f80f565..0000000 --- a/lua/ivy/matcher_test.lua +++ /dev/null @@ -1,37 +0,0 @@ -local libivy = require "ivy.libivy" - --- Helper function to test a that string `one` has a higher match score than --- string `two`. If string `one` has a lower score than string `two` a string --- will be returned that can be used in body of an error. If not then `nil` is --- returned and all is good. -local match_test = function(term, one, two) - local score_one = libivy.ivy_match(term, one) - local score_two = libivy.ivy_match(term, two) - - if score_one < score_two then - return one .. " should be ranked higher than " .. two - end - - return nil -end - -it("sould match path separator", function(t) - local result = match_test("file", "some/file.lua", "somefile.lua") - if result then - t.error(result) - end -end) - -it("sould match pattern with spaces", function(t) - local result = match_test("so fi", "some/file.lua", "somefile.lua") - if result then - t.error(result) - end -end) - -it("sould match the start of a string", function(t) - local result = match_test("file", "file.lua", "somefile.lua") - if result then - t.error(result) - end -end) diff --git a/lua/ivy/prompt_test.lua b/lua/ivy/prompt_test.lua deleted file mode 100644 index ee834b6..0000000 --- a/lua/ivy/prompt_test.lua +++ /dev/null @@ -1,94 +0,0 @@ -local prompt = require "ivy.prompt" -local vim_mock = require "ivy.vim_mock" - -before_each(function() - vim_mock.reset() - prompt.destroy() -end) - --- Input a list of strings into the prompt -local input = function(input_table) - for index = 1, #input_table do - prompt.input(input_table[index]) - end -end - --- Asserts the prompt contains the correct value -local assert_prompt = function(t, expected) - local text = prompt.text() - if text ~= expected then - t.error("The prompt text should be '" .. expected .. "' found '" .. text .. "'") - end -end - -it("starts with empty text", function(t) - if prompt.text() ~= "" then - t.error "The prompt should start with empty text" - end -end) - -it("can input some text", function(t) - input { "A", "d", "e" } - assert_prompt(t, "Ade") -end) - -it("can delete a char", function(t) - input { "A", "d", "e", "BACKSPACE" } - assert_prompt(t, "Ad") -end) - -it("will reset the text", function(t) - input { "A", "d", "e" } - prompt.set "New" - assert_prompt(t, "New") -end) - -it("can move around the a word", function(t) - input { "P", "r", "o", "p", "t", "LEFT", "LEFT", "LEFT", "RIGHT", "m" } - assert_prompt(t, "Prompt") -end) - -it("can delete a word", function(t) - prompt.set "Ade Attwood" - input { "DELETE_WORD" } - assert_prompt(t, "Ade ") -end) - -it("can delete a word in the middle", function(t) - prompt.set "Ade middle A" - input { "LEFT", "LEFT", "DELETE_WORD" } - assert_prompt(t, "Ade A") -end) - -it("will delete the space and the word if the last word is single space", function(t) - prompt.set "some.thing " - input { "DELETE_WORD" } - assert_prompt(t, "some.") -end) - -it("will only delete one word from path", function(t) - prompt.set "some/nested/path" - input { "DELETE_WORD" } - assert_prompt(t, "some/nested/") -end) - -it("will delete tailing space", function(t) - prompt.set "word " - input { "DELETE_WORD" } - assert_prompt(t, "") -end) - -it("will leave a random space", function(t) - prompt.set "some word " - input { "DELETE_WORD" } - assert_prompt(t, "some ") -end) - -local special_characters = { ".", "/", "^" } -for _, char in ipairs(special_characters) do - it(string.format("will stop at a %s", char), function(t) - prompt.set(string.format("key%sValue", char)) - input { "DELETE_WORD" } - assert_prompt(t, string.format("key%s", char)) - end) -end diff --git a/lua/ivy/utils_escape_test.lua b/lua/ivy/utils_escape_test.lua deleted file mode 100644 index ebe41d2..0000000 --- a/lua/ivy/utils_escape_test.lua +++ /dev/null @@ -1,11 +0,0 @@ -local utils = require "ivy.utils" - -it("will escape a dollar in the file name", function(t) - local result = utils.escape_file_name "/path/to/$file/$name.lua" - t.assert_equal(result, "/path/to/\\$file/\\$name.lua") -end) - -it("will escape a brackets in the file name", function(t) - local result = utils.escape_file_name "/path/to/[file]/[name].lua" - t.assert_equal(result, "/path/to/\\[file\\]/\\[name\\].lua") -end) diff --git a/lua/ivy/utils_line_action_test.lua b/lua/ivy/utils_line_action_test.lua deleted file mode 100644 index f68810e..0000000 --- a/lua/ivy/utils_line_action_test.lua +++ /dev/null @@ -1,39 +0,0 @@ -local utils = require "ivy.utils" -local line_action = utils.line_action() -local vim_mock = require "ivy.vim_mock" - -before_each(function() - vim_mock.reset() -end) - -it("will run the line command", function(t) - line_action " 4: Some text" - - if #vim_mock.commands ~= 1 then - t.error "`line_action` command length should be 1" - end - - if vim_mock.commands[1] ~= "4" then - t.error "`line_action` command should be 4" - end -end) - -it("will run with more numbers", function(t) - line_action " 44: Some text" - - if #vim_mock.commands ~= 1 then - t.error "`line_action` command length should be 1" - end - - if vim_mock.commands[1] ~= "44" then - t.error "`line_action` command should be 44" - end -end) - -it("dose not run any action if no line is found", function(t) - line_action "Some text" - - if #vim_mock.commands ~= 0 then - t.error "`line_action` command length should be 1" - end -end) diff --git a/lua/ivy/utils_vimgrep_action_test.lua b/lua/ivy/utils_vimgrep_action_test.lua deleted file mode 100644 index 0c08c09..0000000 --- a/lua/ivy/utils_vimgrep_action_test.lua +++ /dev/null @@ -1,56 +0,0 @@ -local utils = require "ivy.utils" -local vimgrep_action = utils.vimgrep_action() -local vim_mock = require "ivy.vim_mock" - -before_each(function() - vim_mock.reset() -end) - -local test_data = { - { - it = "will edit some file and goto the line", - completion = "some/file.lua:2: This is some text", - action = utils.actions.EDIT, - commands = { - "edit some/file.lua", - "2", - }, - }, - { - it = "will skip the line if its not matched", - completion = "some/file.lua: This is some text", - action = utils.actions.EDIT, - commands = { "edit some/file.lua" }, - }, - { - it = "will run the vsplit command", - completion = "some/file.lua: This is some text", - action = utils.actions.VSPLIT, - commands = { "vsplit some/file.lua" }, - }, - { - it = "will run the split command", - completion = "some/file.lua: This is some text", - action = utils.actions.SPLIT, - commands = { "split some/file.lua" }, - }, -} - -for i = 1, #test_data do - local data = test_data[i] - it(data.it, function(t) - vimgrep_action(data.completion, data.action) - - if #vim_mock.commands ~= #data.commands then - t.error("Incorrect number of commands run expected " .. #data.commands .. " but found " .. #vim_mock.commands) - end - - for j = 1, #data.commands do - if vim_mock.commands[j] ~= data.commands[j] then - t.error( - "Incorrect command run expected '" .. data.commands[j] .. "' but found '" .. vim_mock.commands[j] .. "'" - ) - end - end - end) -end diff --git a/lua/ivy/window_test.lua b/lua/ivy/window_test.lua deleted file mode 100644 index dcad637..0000000 --- a/lua/ivy/window_test.lua +++ /dev/null @@ -1,33 +0,0 @@ -local vim_mock = require "ivy.vim_mock" -local window = require "ivy.window" - -before_each(function() - vim_mock.reset() -end) - -it("can initialize and destroy the window", function(t) - window.initialize() - - t.assert_equal(10, window.get_buffer()) - t.assert_equal(10, window.buffer) - - window.destroy() - t.assert_equal(nil, window.buffer) -end) - -it("can set items", function(t) - window.initialize() - - window.set_items { { content = "Line one" } } - t.assert_equal("Line one", window.get_current_selection()) -end) - -it("will set the items when a string is passed in", function(t) - window.initialize() - - local items = table.concat({ "One", "Two", "Three" }, "\n") - window.set_items(items) - - local lines = table.concat(vim_mock.get_lines()[window.buffer], "\n") - t.assert_equal(items, lines) -end)