-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(template functions): Use function Title instead of ToTitle to get…
… Capitalize strings instead of upper strings using cases.Title because the strings.Title function is deprecated and refs to cases.Title
- Loading branch information
Showing
5 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package provider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestRenderStringTemplate(t *testing.T) { | ||
template := ` | ||
Plainmarkdown: {{ plainmarkdown .Text }} | ||
Split: {{ $arr := split .Text " "}}{{ index $arr 3 }} | ||
Trimspace: {{ trimspace .Text }} | ||
Lower: {{ upper .Text }} | ||
Upper: {{ lower .Text }} | ||
Title: {{ title .Text }} | ||
Prefixlines: | ||
{{ prefixlines " " .MultiLineTest }} | ||
` | ||
|
||
expectedString := ` | ||
Plainmarkdown: my Odly cAsed striNg | ||
Split: striNg | ||
Trimspace: my Odly cAsed striNg | ||
Lower: MY ODLY CASED STRING | ||
Upper: my odly cased string | ||
Title: My Odly Cased String | ||
Prefixlines: | ||
This text used | ||
multiple lines | ||
` | ||
result, err := renderStringTemplate("testTemplate", template, struct { | ||
Text string | ||
MultiLineTest string | ||
}{ | ||
Text: "my Odly cAsed striNg", | ||
MultiLineTest: `This text used | ||
multiple lines`, | ||
}) | ||
|
||
if err != nil { | ||
t.Error(err) | ||
} | ||
if !cmp.Equal(expectedString, result) { | ||
t.Errorf("expected: %+v, got: %+v", expectedString, result) | ||
} | ||
} |