Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/gx/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local go_handler = require("gx.handlers.go")
local commit_handler = require("gx.handlers.commit")
local markdown_handler = require("gx.handlers.markdown")
local cve_handler = require("gx.handlers.cve")
local python_pep_handler = require("gx.handlers.python-pep")
local search_handler = require("gx.handlers.search")

local M = {}
Expand Down Expand Up @@ -48,6 +49,7 @@ local function resolve_handlers(handlers)
add_handler(resolved, go_handler, handlers.go and exists.go == nil)
add_handler(resolved, markdown_handler, handlers.markdown and exists.markdown == nil)
add_handler(resolved, cve_handler, handlers.cve and exists.cve == nil)
add_handler(resolved, python_pep_handler, handlers.python_pep and exists.python_pep == nil)
add_handler(resolved, url_handler, handlers.url and exists.url == nil)
add_handler(resolved, search_handler, handlers.search and exists.search == nil)
-- ###
Expand Down
18 changes: 18 additions & 0 deletions lua/gx/handlers/python-pep.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local helper = require("gx.helper")

---@type GxHandler
local M = {
name = "python-pep",
filetype = nil,
filename = nil,
}

function M.handle(mode, line, _)
local id = helper.find(line, mode, "PEP%s?-?(%d+)")
if not id then
return
end
return "https://peps.python.org/" .. "pep-" .. id
end

return M
13 changes: 13 additions & 0 deletions test/spec/gx/handlers/python-pep_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local handler = require("gx.handlers.python-pep")

describe("python-pep_handler_does_work", function()
it("python-pep", function()
assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP-484"))
end)
it("python-pep", function()
assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP484"))
end)
it("python-pep", function()
assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP 484"))
end)
end)