Skip to content

Commit

Permalink
Add Title function.
Browse files Browse the repository at this point in the history
Add tests for Title function.

Signed-off-by: aliwoto <[email protected]>
  • Loading branch information
ALiwoto committed Apr 14, 2022
1 parent 0f2006b commit 6fac922
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ module github.com/AnimeKaizoku/ssg

go 1.18

require golang.org/x/text v0.3.7 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
4 changes: 4 additions & 0 deletions ssg/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ func ToValidIntegerString(value string) string {
return newValue
}

func Title(value string) string {
return _titleCaser.String(value)
}

func ToInt64(value string) int64 {
i, _ := strconv.ParseInt(ToValidIntegerString(value), 10, 64)
return i
Expand Down
10 changes: 10 additions & 0 deletions ssg/vars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ssg

import (
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

var (
_titleCaser = cases.Title(language.Und, cases.NoLower)
)
26 changes: 26 additions & 0 deletions tests/strong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ import (
ws "github.com/AnimeKaizoku/ssg/ssg"
)

func TestTitleCase(t *testing.T) {
const (
str1 = "string1"
str2 = "thisIsString2"
str3 = "HelloThere"
)

tmp := ws.Title(str1)
if tmp != "String1" {
t.Errorf("Expected %s, got %s", "String1", tmp)
return
}

tmp = ws.Title(str2)
if tmp != "ThisIsString2" {
t.Errorf("Expected %s, got %s", "ThisIsString2", tmp)
return
}

tmp = ws.Title(str3)
if tmp != "HelloThere" {
t.Errorf("Expected %s, got %s", "HelloThere", tmp)
return
}
}

func TestStrong(t *testing.T) {
LogStr("Hi")
LogInt(5)
Expand Down

1 comment on commit 6fac922

@ALiwoto
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please sign in to comment.