Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go template function to split string into array of strings. #3108

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func Funcs() template.FuncMap {
"call": Call,
"prefixLines": prefixLines,
"notNil": notNil,
"strSplit": StrSplit,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to cover this with a test?

Copy link
Contributor Author

@khudayberdiyev25 khudayberdiyev25 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually calling go's standard library strings.Split function only.

I would add some test scenarios If maintainers put such requirement.

Copy link
Contributor

@alexandear alexandear May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to a PR requirement, every new feature should have a test. So, it's not only my preference of adding tests.

It doesn't matter how simple the function's implementation is now, someone may change its implementation during a refactoring, and we won't catch this without a test.

"reserveImport": CurrentImports.Reserve,
"lookupImport": CurrentImports.Lookup,
"go": ToGo,
Expand Down Expand Up @@ -581,6 +582,10 @@ func notNil(field string, data any) bool {
return val.IsValid() && !val.IsNil()
}

func StrSplit(s, sep string) []string {
return strings.Split(s, sep)
}

func Dump(val any) string {
switch val := val.(type) {
case int:
Expand Down
Loading