Co-authored-by: Christopher Thonfeld-Guckes <ctg@triarc-labs.com>
This commit is contained in:
Christopher Thonfeld-Guckes
2022-10-19 17:08:25 +02:00
committed by GitHub
parent 11c43c3c2b
commit a3fbb82853
2 changed files with 27 additions and 1 deletions

View File

@@ -61,7 +61,15 @@ public class TitlecaseLambda implements Mustache.Lambda {
}
private String titleCase(final String input) {
return input.substring(0, 1).toUpperCase(Locale.ROOT) + input.substring(1);
if(input == null || "".equals(input)){
return "";
}
String firstLetter = input.substring(0, 1).toUpperCase(Locale.ROOT);
if (input.length() == 1) {
return firstLetter;
}
return firstLetter + input.substring(1);
}
@Override

View File

@@ -15,6 +15,24 @@ public class TitlecaseLambdaTest extends LambdaTest {
test("Once Upon A Time", "{{#titlecase}}once upon a time{{/titlecase}}", ctx);
}
@Test
public void titlecaseSingleLetterTest() {
// Given
Map<String, Object> ctx = context("titlecase", new TitlecaseLambda());
// When & Then
test("O", "{{#titlecase}}o{{/titlecase}}", ctx);
}
@Test
public void titlecaseEmptyStringTest() {
// Given
Map<String, Object> ctx = context("titlecase", new TitlecaseLambda());
// When & Then
test("", "{{#titlecase}}{{/titlecase}}", ctx);
}
@Test
public void titlecaseWithDelimiterTest() {
// Given