-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add non-must template funcs with
may
prefix
- Loading branch information
Showing
3 changed files
with
89 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package util | ||
|
||
import "strings" | ||
|
||
func UpperFirst(s string) string { | ||
switch len(s) { | ||
case 0: | ||
return s | ||
case 1: | ||
return strings.ToUpper(s) | ||
default: | ||
return strings.ToUpper(s[0:1]) + s[1:] | ||
} | ||
} | ||
|
||
func LowerFirst(s string) string { | ||
switch len(s) { | ||
case 0: | ||
return s | ||
case 1: | ||
return strings.ToLower(s) | ||
default: | ||
return strings.ToLower(s[0:1]) + s[1:] | ||
} | ||
} |
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 util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLowerFirst(t *testing.T) { | ||
type args struct { | ||
s string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{"empty", args{""}, ""}, | ||
{"len 1", args{"A"}, "a"}, | ||
{"multiple", args{"TestArg"}, "testArg"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.want, LowerFirst(tt.args.s), "LowerFirst(%v)", tt.args.s) | ||
}) | ||
} | ||
} | ||
|
||
func TestUpperFirst(t *testing.T) { | ||
type args struct { | ||
s string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{"empty", args{""}, ""}, | ||
{"len 1", args{"a"}, "A"}, | ||
{"multiple", args{"testArg"}, "TestArg"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.want, UpperFirst(tt.args.s), "UpperFirst(%v)", tt.args.s) | ||
}) | ||
} | ||
} |