openingh.nvim/tests/openingh_spec.lua

76 lines
2.3 KiB
Lua
Raw Normal View History

2022-10-30 02:03:40 +03:00
vim.g.test = true
describe("busted should run", function()
it("should start test", function()
vim.cmd([[packadd openingh.nvim]])
local status = require("plenary.reload").reload_module(".nvim")
assert.are.same(status, nil)
end)
it("require('openingh')", function()
local status = require("openingh")
assert.truthy(status)
end)
end)
describe("openingh should set user commands", function()
it("should set :OpenInGHRepo", function()
local status = vim.fn.exists(":OpenInGHRepo")
assert.truthy(status)
end)
it("should set :OpenInGHFile", function()
local status = vim.fn.exists(":OpenInGHFile")
assert.truthy(status)
end)
end)
describe("OpenInGHFile", function()
it("opens a URL that links to a file", function()
2022-10-30 02:03:40 +03:00
vim.cmd("e ./README.md")
2023-03-21 12:55:43 -04:00
vim.api.nvim_win_set_cursor(0, { 3, 0 })
2022-10-30 02:03:40 +03:00
vim.cmd("OpenInGHFile")
2023-03-21 12:55:43 -04:00
local status = vim.g.OPENINGH_RESULT
local expected = "/README.md"
assert.equal(expected, status:sub(-#expected))
end)
it("opens a URL that links to a file on the selected line", function()
vim.cmd("e ./README.md")
vim.api.nvim_buf_set_mark(0, "<", 5, 0, {})
vim.api.nvim_buf_set_mark(0, ">", 5, 0, {})
vim.cmd("'<,'>OpenInGHFile")
local status = vim.g.OPENINGH_RESULT
local expected = "/README.md#L5-L5"
2023-03-21 12:55:43 -04:00
assert.equal(expected, status:sub(-#expected))
end)
2022-10-30 02:03:40 +03:00
it("opens a URL that links to a file with a range of selected lines", function()
2023-03-21 12:55:43 -04:00
vim.cmd("e ./README.md")
vim.api.nvim_buf_set_mark(0, "<", 5, 0, {})
vim.api.nvim_buf_set_mark(0, ">", 10, 0, {})
vim.cmd("'<,'>OpenInGHFile")
2022-10-30 02:03:40 +03:00
local status = vim.g.OPENINGH_RESULT
local expected = "/README.md#L5-L10"
2023-03-21 12:55:43 -04:00
assert.equal(expected, status:sub(-#expected))
2022-10-30 02:03:40 +03:00
end)
2023-03-23 10:04:55 -04:00
it("opens a URL to a file using a keymap", function()
2023-03-23 10:04:55 -04:00
vim.api.nvim_set_keymap("n", "ghf", ":OpenInGHFile <cr>", {})
vim.cmd("e ./README.md")
vim.api.nvim_win_set_cursor(0, { 2, 0 })
2023-03-23 10:04:55 -04:00
vim.cmd("normal ghf")
local status = vim.g.OPENINGH_RESULT
local expected = "/README.md"
2023-03-23 10:04:55 -04:00
assert.equal(expected, status:sub(-#expected))
end)
2022-10-30 02:03:40 +03:00
end)
describe("OpenInGHRepo", function()
it("opens a URL with a link to the repo", function()
vim.cmd("OpenInGHRepo")
local status = vim.g.OPENINGH_RESULT
assert.truthy(status)
end)
end)