From b5c3358521a5e0ae9df7e2d0252bda5a31224b2d Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Mon, 19 Dec 2022 12:27:39 +0200 Subject: [PATCH] refactor tests (#23) * fix: add `nvim-dap` as test dep. fix makefile * refactor(spec): struct_tags --- Makefile | 2 +- spec/gopher_struct_tags_spec.lua | 43 +++++++++++++++----------------- spec/minimal_init.vim | 1 + 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 9b270c1..2dc03c4 100644 --- a/Makefile +++ b/Makefile @@ -8,4 +8,4 @@ lint: selene **/*.lua test: - nvim --headless -u ./spec/minimal.vim -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal.vim'}" + nvim --headless -u ./spec/minimal_init.vim -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal_init.vim'}" diff --git a/spec/gopher_struct_tags_spec.lua b/spec/gopher_struct_tags_spec.lua index 359275d..ad8dd6e 100644 --- a/spec/gopher_struct_tags_spec.lua +++ b/spec/gopher_struct_tags_spec.lua @@ -6,47 +6,44 @@ describe("gopher.struct_tags", function() end) it("can add json tag to struct", function() - local add = require("gopher.struct_tags").add - local name = vim.fn.tempname() .. ".go" + local tag = require "gopher.struct_tags" + local temp_file = vim.fn.tempname() .. ".go" local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go") local output_file = vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n") - vim.fn.writefile(input_file, name) - vim.cmd("silent exe 'e " .. name .. "'") - - local bufn = vim.fn.bufnr "" + vim.fn.writefile(input_file, temp_file) + vim.cmd("silent exe 'e " .. temp_file .. "'") vim.bo.filetype = "go" + + local bufn = vim.fn.bufnr(0) vim.fn.setpos(".", { bufn, 3, 6, 0 }) - add() + tag.add() - vim.wait(100, function() end) - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - assert.are.same(output_file, fmt) + vim.wait(100) + assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n")) - vim.cmd("bd! " .. name) + vim.cmd("bd! " .. temp_file) end) it("can remove json tag from struct", function() - local remove = require("gopher.struct_tags").remove - local name = vim.fn.tempname() .. ".go" + local tag = require "gopher.struct_tags" + local temp_file = vim.fn.tempname() .. ".go" local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go") local output_file = vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), "\n") - vim.fn.writefile(input_file, name) - vim.cmd("silent exe 'e " .. name .. "'") - - local bufn = vim.fn.bufnr "" + vim.fn.writefile(input_file, temp_file) + vim.cmd("silent exe 'e " .. temp_file .. "'") vim.bo.filetype = "go" + + local bufn = vim.fn.bufnr() vim.fn.setpos(".", { bufn, 3, 6, 0 }) - remove() + tag.remove() - vim.wait(100, function() end) + vim.wait(100) + assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n")) - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - assert.are.same(output_file, fmt) - - vim.cmd("bd! " .. name) + vim.cmd("bd! " .. temp_file) end) end) diff --git a/spec/minimal_init.vim b/spec/minimal_init.vim index fe175a4..e30e21b 100644 --- a/spec/minimal_init.vim +++ b/spec/minimal_init.vim @@ -1,3 +1,4 @@ set rtp+=. packadd plenary.nvim packadd nvim-treesitter +packadd nvim-dap