mirror of
https://github.com/thegeeklab/drone-template-lib.git
synced 2024-11-28 23:50:35 +00:00
Merge pull request #4 from steadyapp/master
Adding custom helper for regex
This commit is contained in:
commit
4019baa6c5
@ -17,6 +17,7 @@ package template
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
@ -39,6 +40,7 @@ var (
|
||||
"lowercase": strings.ToLower,
|
||||
"trim": strings.TrimSpace,
|
||||
"title": strings.Title,
|
||||
"regexReplace": regexReplace,
|
||||
}
|
||||
)
|
||||
|
||||
@ -117,3 +119,8 @@ func uppercaseFirst(s string) string {
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func regexReplace(pattern string, input string, replacement string) string {
|
||||
re := regexp.MustCompile(pattern)
|
||||
return re.ReplaceAllString(input, replacement)
|
||||
}
|
||||
|
@ -90,3 +90,11 @@ func TestUppercaseFirst(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegexReplace(t *testing.T) {
|
||||
expected := "hello-my-String-123"
|
||||
actual := regexReplace("(.*?)\\/(.*)", "hello/my-String-123", "$1-$2")
|
||||
if actual != "hello-my-String-123" {
|
||||
t.Errorf("error, expected %s, got %s", expected, actual)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user