Fix man match for pages that start with p, also fix 3p pages and add tests.
This commit is contained in:
parent
0474100432
commit
27a0e4c780
@ -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")
|
||||
}
|
||||
|
22
plugins/openbsd_man_test.go
Normal file
22
plugins/openbsd_man_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user