some tests refactoring and sep by type

This commit is contained in:
Smirnov Oleksandr 2023-02-04 17:04:12 +02:00
parent de37564c79
commit ab874c6c4f
8 changed files with 46 additions and 87 deletions

View file

@ -1,41 +0,0 @@
describe("gopher.config", function()
it("can be required", function()
require "gopher.config"
end)
it(".setup() when gets empty table not edit config", function()
local c = require "gopher.config"
c.setup {}
assert.are.same(c.config.commands.go, "go")
assert.are.same(c.config.commands.gomodifytags, "gomodifytags")
assert.are.same(c.config.commands.gotests, "gotests")
assert.are.same(c.config.commands.impl, "impl")
end)
it(".setup() when get one custom value sets that", function()
local c = require "gopher.config"
c.setup { commands = {
go = "custom_go",
} }
assert.are.same(c.config.commands.go, "custom_go")
end)
it(".setup() when get all custom values sets it", function()
local c = require "gopher.config"
c.setup {
commands = {
go = "go1.18",
gomodifytags = "user-gomodifytags",
gotests = "gotests",
impl = "goimpl",
},
}
assert.are.same(c.config.commands.go, "go1.18")
assert.are.same(c.config.commands.gomodifytags, "user-gomodifytags")
assert.are.same(c.config.commands.gotests, "gotests")
assert.are.same(c.config.commands.impl, "goimpl")
end)
end)

View file

@ -1,5 +0,0 @@
describe("gopher", function()
it("can be required", function()
require "gopher"
end)
end)

View file

@ -1,19 +0,0 @@
describe("gopher._utils", function()
it("can be requried", function()
require "gopher._utils"
end)
it(".empty() with non-empty talbe", function()
local empty = require("gopher._utils").empty
local res = empty { first = "1", second = 2 }
assert.are.same(res, false)
end)
it(".empty() with empty talbe", function()
local empty = require("gopher._utils").empty
local res = empty {}
assert.are.same(res, true)
end)
end)

View file

@ -9,8 +9,7 @@ describe("gopher.struct_tags", function()
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")
local output_file = vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n")
vim.fn.writefile(input_file, temp_file)
vim.cmd("silent exe 'e " .. temp_file .. "'")
@ -30,8 +29,7 @@ describe("gopher.struct_tags", function()
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")
local output_file = vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), "\n")
vim.fn.writefile(input_file, temp_file)
vim.cmd("silent exe 'e " .. temp_file .. "'")

View file

@ -1,4 +1,3 @@
local function root(p)
local f = debug.getinfo(1, "S").source:sub(2)
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (p or "")

22
spec/unit/config_spec.lua Normal file
View file

@ -0,0 +1,22 @@
describe("unit.gopher.config", function()
it("can be required", function()
require "gopher.config"
end)
describe(".setup()", function()
local c = require "gopher.config"
it("returns defaults when gets empty table", function()
c.setup {}
assert.are.same(c.config.commands.go, "go")
assert.are.same(c.config.commands.gomodifytags, "gomodifytags")
assert.are.same(c.config.commands.gotests, "gotests")
assert.are.same(c.config.commands.impl, "impl")
end)
it("can set user opts", function()
c.setup { commands = { go = "custom_go" } }
assert.are.same(c.config.commands.go, "custom_go")
end)
end)
end)

19
spec/unit/utils_spec.lua Normal file
View file

@ -0,0 +1,19 @@
describe("gopher._utils", function()
it("can be requried", function()
require "gopher._utils"
end)
describe(".empty()", function()
local empty = require("gopher._utils").empty
it("with non-empty talbe", function()
local res = empty { first = "1", second = 2 }
assert.are.same(res, false)
end)
it("with empty talbe", function()
local res = empty {}
assert.are.same(res, true)
end)
end)
end)