Fix man match for pages that start with p, also fix 3p pages and add tests.

This commit is contained in:
Aaron Bieber 2020-03-09 07:34:08 -06:00
parent 0474100432
commit 27a0e4c780
2 changed files with 27 additions and 1 deletions

View File

@ -18,7 +18,7 @@ func (h *OpenBSDMan) Descr() string {
// Re matches our man format
func (h *OpenBSDMan) Re() string {
return `(?i)^man: ([1-9]?p?)\s?(.+)$`
return `(?i)^man: ([1-9][p]?)?\s?(.+)$`
}
func (h *OpenBSDMan) fix(msg string) string {
@ -30,6 +30,10 @@ func (h *OpenBSDMan) fix(msg string) string {
}
if section != "" {
resp = re.ReplaceAllString(msg, "$2.$1")
if matched, _ := regexp.MatchString(`3p`, resp); matched {
resp = fmt.Sprintf("man3p/%s", resp)
}
} else {
resp = re.ReplaceAllString(msg, "$2")
}

View File

@ -0,0 +1,22 @@
package plugins
import (
"fmt"
"testing"
)
func TestMatch(t *testing.T) {
testStrings := make(map[string]string)
testStrings["man: pledge"] = "https://man.openbsd.org/pledge"
testStrings["man: 2 pledge"] = "https://man.openbsd.org/pledge.2"
testStrings["man: unveil"] = "https://man.openbsd.org/unveil"
testStrings["man: 3p vars"] = "https://man.openbsd.org/man3p/vars.3p"
om := &OpenBSDMan{}
for msg, resp := range testStrings {
matched := fmt.Sprintf("https://man.openbsd.org/%s", om.fix(msg))
if matched != resp {
t.Errorf("OpenBSDMan expected %q; got %q (%q)", resp, matched, msg)
}
}
}