Defaults to main branch if all other options aren't upstreamed

This commit is contained in:
PlaiyTiziano 2023-04-09 01:35:54 +02:00
parent 8c28db76c9
commit 4b7cf31af2
4 changed files with 86 additions and 32 deletions

View file

@ -25,14 +25,8 @@ describe("openingh should set user commands", function()
end)
end)
describe("openingh should open", function()
it("repo on :OpenInGHRepo", function()
vim.cmd("OpenInGHRepo")
local status = vim.g.OPENINGH_RESULT
assert.truthy(status)
end)
it("file on :OpenInGHFile", function()
describe("OpenInGHFile", function()
it("opens a URL that links to a file", function()
vim.cmd("e ./README.md")
vim.api.nvim_win_set_cursor(0, { 3, 0 })
vim.cmd("OpenInGHFile")
@ -41,7 +35,7 @@ describe("openingh should open", function()
assert.equal(expected, status:sub(-#expected))
end)
it("file range on :'<,'>OpenInGHFile", function()
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, {})
@ -51,7 +45,7 @@ describe("openingh should open", function()
assert.equal(expected, status:sub(-#expected))
end)
it("file range on :'<,'>OpenInGHFile", function()
it("opens a URL that links to a file with a range of selected lines", function()
vim.cmd("e ./README.md")
vim.api.nvim_buf_set_mark(0, "<", 5, 0, {})
vim.api.nvim_buf_set_mark(0, ">", 10, 0, {})
@ -61,7 +55,7 @@ describe("openingh should open", function()
assert.equal(expected, status:sub(-#expected))
end)
it("file range using a keymap", function()
it("opens a URL to a file using a keymap", function()
vim.api.nvim_set_keymap("n", "ghf", ":OpenInGHFile <cr>", {})
vim.cmd("e ./README.md")
vim.api.nvim_win_set_cursor(0, { 2, 0 })
@ -71,3 +65,11 @@ describe("openingh should open", function()
assert.equal(expected, status:sub(-#expected))
end)
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)

28
tests/utils_spec.lua Normal file
View file

@ -0,0 +1,28 @@
vim.g.test = true
local utils = require("openingh.utils")
describe("is_branch_upstreamed", function()
it("returns false when the branch is not upstreamed", function()
local output = utils.is_branch_upstreamed("this branch probably does not exist")
assert.is.False(output)
end)
it("returns true when the branch is upstreamed", function()
local output = utils.is_branch_upstreamed("main")
assert.is.True(output)
end)
end)
describe("is_commit_upstreamed", function()
it("returns false when the commit is not upstreamed", function()
local output = utils.is_commit_upstreamed("2a69ced1af827535dd8124eeab19d5f6777decf1")
assert.is.False(output)
end)
it("returns true when the commit is upstreamed", function()
local commit = utils.trim(vim.fn.system("git rev-parse HEAD"))
local output = utils.is_commit_upstreamed(commit)
assert.is.True(output)
end)
end)