[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang

refactor tests (#23)

* fix: add `nvim-dap` as test dep. fix makefile

* refactor(spec): struct_tags

authored by olexsmir.xyz and committed by GitHub b5c33585 1363d550

+1 -1
Makefile
··· 8 8 selene **/*.lua 9 9 10 10 test: 11 - nvim --headless -u ./spec/minimal.vim -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal.vim'}" 11 + nvim --headless -u ./spec/minimal_init.vim -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal_init.vim'}"
+20 -23
spec/gopher_struct_tags_spec.lua
··· 6 6 end) 7 7 8 8 it("can add json tag to struct", function() 9 - local add = require("gopher.struct_tags").add 10 - local name = vim.fn.tempname() .. ".go" 9 + local tag = require "gopher.struct_tags" 10 + local temp_file = vim.fn.tempname() .. ".go" 11 11 local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go") 12 12 local output_file = 13 13 vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n") 14 14 15 - vim.fn.writefile(input_file, name) 16 - vim.cmd("silent exe 'e " .. name .. "'") 15 + vim.fn.writefile(input_file, temp_file) 16 + vim.cmd("silent exe 'e " .. temp_file .. "'") 17 + vim.bo.filetype = "go" 17 18 18 - local bufn = vim.fn.bufnr "" 19 - vim.bo.filetype = "go" 19 + local bufn = vim.fn.bufnr(0) 20 20 vim.fn.setpos(".", { bufn, 3, 6, 0 }) 21 - add() 21 + tag.add() 22 22 23 - vim.wait(100, function() end) 24 - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") 25 - assert.are.same(output_file, fmt) 23 + vim.wait(100) 24 + assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n")) 26 25 27 - vim.cmd("bd! " .. name) 26 + vim.cmd("bd! " .. temp_file) 28 27 end) 29 28 30 29 it("can remove json tag from struct", function() 31 - local remove = require("gopher.struct_tags").remove 32 - local name = vim.fn.tempname() .. ".go" 30 + local tag = require "gopher.struct_tags" 31 + local temp_file = vim.fn.tempname() .. ".go" 33 32 local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go") 34 33 local output_file = 35 34 vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), "\n") 36 35 37 - vim.fn.writefile(input_file, name) 38 - vim.cmd("silent exe 'e " .. name .. "'") 36 + vim.fn.writefile(input_file, temp_file) 37 + vim.cmd("silent exe 'e " .. temp_file .. "'") 38 + vim.bo.filetype = "go" 39 39 40 - local bufn = vim.fn.bufnr "" 41 - vim.bo.filetype = "go" 40 + local bufn = vim.fn.bufnr() 42 41 vim.fn.setpos(".", { bufn, 3, 6, 0 }) 43 - remove() 42 + tag.remove() 44 43 45 - vim.wait(100, function() end) 46 - 47 - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") 48 - assert.are.same(output_file, fmt) 44 + vim.wait(100) 45 + assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n")) 49 46 50 - vim.cmd("bd! " .. name) 47 + vim.cmd("bd! " .. temp_file) 51 48 end) 52 49 end)
+1
spec/minimal_init.vim
··· 1 1 set rtp+=. 2 2 packadd plenary.nvim 3 3 packadd nvim-treesitter 4 + packadd nvim-dap