Add toUpperCase and toLowerCase functions #285

This commit is contained in:
Francis Dong
2021-08-27 16:12:29 +08:00
committed by dxfeng10
parent 4acca47375
commit 7ec6d7056a
2 changed files with 24 additions and 0 deletions

View File

@@ -57,6 +57,8 @@ public class StringFunc implements IFunc {
FuncExecutor.register(NAME_SPACE_PREFIX + "string.indexOf", this);
FuncExecutor.register(NAME_SPACE_PREFIX + "string.startsWith", this);
FuncExecutor.register(NAME_SPACE_PREFIX + "string.endsWith", this);
FuncExecutor.register(NAME_SPACE_PREFIX + "string.toUpperCase", this);
FuncExecutor.register(NAME_SPACE_PREFIX + "string.toLowerCase", this);
}
/**
@@ -145,4 +147,12 @@ public class StringFunc implements IFunc {
return str.endsWith(suffix);
}
public String toUpperCase(String str) {
return str.toUpperCase();
}
public String toLowerCase(String str) {
return str.toLowerCase();
}
}

View File

@@ -105,6 +105,20 @@ class StringFuncTests {
assertEquals("2021-07-09 22:44:55".endsWith("44:55"), result);
}
@Test
void testToUpperCase() {
String funcExpression = "fn.string.toUpperCase(\"aBc\")";
String result = (String)FuncExecutor.getInstance().exec(null, funcExpression);
assertEquals("aBc".toUpperCase(), result);
}
@Test
void testToLowerCase() {
String funcExpression = "fn.string.toLowerCase(\"aBc\")";
String result = (String)FuncExecutor.getInstance().exec(null, funcExpression);
assertEquals("aBc".toLowerCase(), result);
}
}