Skip to content

Commit d5b67e9

Browse files
committed
tests 4 check snake && kebab
1 parent fe8fc41 commit d5b67e9

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

stringstyle_formatter.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,15 @@ func SetStyle(text *string, style FormattingStyle, firstSymbol CaseSetting, text
111111
return strings.ToLower(sb.String()[:1]) + result.String()
112112
case NoChanges:
113113
return sb.String()[:1] + result.String()
114+
default:
115+
return sb.String()[:1] + result.String()
114116
}
115-
return ""
116117
}
117118

119+
// GetFormattingStyleOptions function that defines formatting style, case of first char and result from string
120+
/*
121+
*
122+
*/
118123
func GetFormattingStyleOptions(style string) (FormattingStyle, CaseSetting, CaseSetting) {
119124
styleLower := strings.ToLower(style)
120125
var formattingStyle FormattingStyle
@@ -139,7 +144,12 @@ func GetFormattingStyleOptions(style string) (FormattingStyle, CaseSetting, Case
139144
}
140145

141146
if formattingStyle != Camel {
142-
147+
allSymbolsUpperCase := isStringIsUpper(runes)
148+
if allSymbolsUpperCase {
149+
textCase = ToUpper
150+
} else {
151+
textCase = ToLower
152+
}
143153
}
144154

145155
return formattingStyle, firstSymbolCase, textCase

stringstyle_formatter_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,44 @@ func TestSetFormattingStyleWithCaseModification(t *testing.T) {
103103
})
104104
}
105105
}
106+
107+
func TestGetFormattingStyleOptions(t *testing.T) {
108+
for name, test := range map[string]struct {
109+
style string
110+
expectedStyle stringFormatter.FormattingStyle
111+
expectedFirstSymbolCase stringFormatter.CaseSetting
112+
expectedTextCase stringFormatter.CaseSetting
113+
}{
114+
"snake-lower-case-style": {
115+
style: "snake",
116+
expectedStyle: stringFormatter.Snake,
117+
expectedFirstSymbolCase: stringFormatter.ToLower,
118+
expectedTextCase: stringFormatter.ToLower,
119+
},
120+
"snake-upper-case-style": {
121+
style: "SNAKE",
122+
expectedStyle: stringFormatter.Snake,
123+
expectedFirstSymbolCase: stringFormatter.ToUpper,
124+
expectedTextCase: stringFormatter.ToUpper,
125+
},
126+
"kebab-lower-case-style": {
127+
style: "kebab",
128+
expectedStyle: stringFormatter.Kebab,
129+
expectedFirstSymbolCase: stringFormatter.ToLower,
130+
expectedTextCase: stringFormatter.ToLower,
131+
},
132+
"kebab-upper-case-style": {
133+
style: "KEBAB",
134+
expectedStyle: stringFormatter.Kebab,
135+
expectedFirstSymbolCase: stringFormatter.ToUpper,
136+
expectedTextCase: stringFormatter.ToUpper,
137+
},
138+
} {
139+
t.Run(name, func(t *testing.T) {
140+
actualStyle, actualFirstSymbolCase, actualTextCase := stringFormatter.GetFormattingStyleOptions(test.style)
141+
assert.Equal(t, test.expectedStyle, actualStyle)
142+
assert.Equal(t, test.expectedFirstSymbolCase, actualFirstSymbolCase)
143+
assert.Equal(t, test.expectedTextCase, actualTextCase)
144+
})
145+
}
146+
}

0 commit comments

Comments
 (0)