Skip to content

Commit

Permalink
function/stdlib: Rename "RegexpReplace" to "RegexReplace"
Browse files Browse the repository at this point in the history
This is for consistency with the two other functions "Regex" and
"RegexAll" that pre-existed and are already being used in other codebases
(so cannot be renamed now).
  • Loading branch information
apparentlymart committed Mar 9, 2020
1 parent b86baa5 commit 440c597
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions cty/function/stdlib/string_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ var ReplaceFunc = function.New(&function.Spec{
},
})

// RegexpReplaceFunc is a function that searches a given string for another
// RegexReplaceFunc is a function that searches a given string for another
// given substring, and replaces each occurence with a given replacement
// string. The substr argument must be a valid regular expression.
var RegexpReplaceFunc = function.New(&function.Spec{
var RegexReplaceFunc = function.New(&function.Spec{
Params: []function.Parameter{
{
Name: "str",
Expand Down Expand Up @@ -75,6 +75,6 @@ func Replace(str, substr, replace cty.Value) (cty.Value, error) {
return ReplaceFunc.Call([]cty.Value{str, substr, replace})
}

func RegexpReplace(str, substr, replace cty.Value) (cty.Value, error) {
return RegexpReplaceFunc.Call([]cty.Value{str, substr, replace})
func RegexReplace(str, substr, replace cty.Value) (cty.Value, error) {
return RegexReplaceFunc.Call([]cty.Value{str, substr, replace})
}
6 changes: 3 additions & 3 deletions cty/function/stdlib/string_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRegexReplace(t *testing.T) {

for _, test := range tests {
t.Run(test.Input.GoString(), func(t *testing.T) {
got, err := RegexpReplace(test.Input, test.Substr, test.Replace)
got, err := RegexReplace(test.Input, test.Substr, test.Replace)

if err != nil {
t.Fatalf("unexpected error: %s", err)
Expand All @@ -93,8 +93,8 @@ func TestRegexReplace(t *testing.T) {
}
}

func TestRegexReplace_invalid_regex(t *testing.T) {
_, err := RegexpReplace(cty.StringVal(""), cty.StringVal("("), cty.StringVal(""))
func TestRegexReplaceInvalidRegex(t *testing.T) {
_, err := RegexReplace(cty.StringVal(""), cty.StringVal("("), cty.StringVal(""))
if err == nil {
t.Fatal("expected an error")
}
Expand Down

0 comments on commit 440c597

Please sign in to comment.