Skip to content

Commit 33ee564

Browse files
committed
feat: add function is blank() to check if a string is blank or not
1 parent a299adb commit 33ee564

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

src/main/scala/org/camunda/feel/impl/builtin/BooleanBuiltinFunctions.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ object BooleanBuiltinFunctions {
2525
"not" -> List(notFunction),
2626
"is defined" -> List(isDefinedFunction),
2727
"get or else" -> List(getOrElse),
28-
"assert" -> List(assertFunction, assertFunction2),
29-
"is blank" -> List(isBlankFunction)
28+
"assert" -> List(assertFunction, assertFunction2)
3029
)
3130

3231
private def notFunction =
@@ -71,11 +70,4 @@ object BooleanBuiltinFunctions {
7170
}
7271
)
7372

74-
private def isBlankFunction = builtinFunction(
75-
params = List("string"),
76-
invoke = {case List(ValString(string)) =>
77-
ValBoolean(string.isBlank)
78-
}
79-
)
80-
8173
}

src/main/scala/org/camunda/feel/impl/builtin/StringBuiltinFunctions.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ object StringBuiltinFunctions {
4545
"extract" -> List(extractFunction),
4646
"trim" -> List(trimFunction),
4747
"uuid" -> List(uuidFunction),
48-
"to base64" -> List(toBase64Function)
48+
"to base64" -> List(toBase64Function),
49+
"is blank" -> List(isBlankFunction)
4950
)
5051

5152
private def substringFunction = builtinFunction(
@@ -287,4 +288,11 @@ object StringBuiltinFunctions {
287288
}
288289
)
289290

291+
private def isBlankFunction = builtinFunction(
292+
params = List("string"),
293+
invoke = {case List(ValString(string)) =>
294+
ValBoolean(string.isBlank)
295+
}
296+
)
297+
290298
}

src/test/scala/org/camunda/feel/impl/builtin/BuiltinFunctionsTest.scala

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -243,27 +243,4 @@ class BuiltinFunctionsTest
243243
"Assertion failure on evaluate the expression 'list contains(assert(my_list, my_list != null, \"The condition is not true\"), 2)': The condition is not true"
244244
)
245245
}
246-
247-
"A is blank() function" should "return Boolean" in {
248-
evaluateExpression(
249-
expression = """ is blank("") """
250-
) should returnResult(true)
251-
252-
evaluateExpression(
253-
expression = """ is blank(" ") """
254-
) should returnResult(true)
255-
256-
evaluateExpression(
257-
expression = """ is blank("hello world") """
258-
) should returnResult(false)
259-
260-
evaluateExpression(
261-
expression = """ is blank(" hello world ") """
262-
) should returnResult(false)
263-
264-
evaluateExpression(
265-
expression = """ is blank("\t\n\r\f") """
266-
) should returnResult(true)
267-
}
268-
269246
}

src/test/scala/org/camunda/feel/impl/builtin/BuiltinStringFunctionsTest.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,32 @@ class BuiltinStringFunctionsTest
195195

196196
evaluateExpression(""" to base64(value: "Camunda") """) should returnResult("Q2FtdW5kYQ==")
197197
}
198+
199+
"A is blank() function" should "return true if the string contains only whitespace" in {
200+
evaluateExpression(
201+
expression = """ is blank("") """
202+
) should returnResult(true)
203+
204+
evaluateExpression(
205+
expression = """ is blank(" ") """
206+
) should returnResult(true)
207+
208+
evaluateExpression(
209+
expression = """ is blank("\t\n\r\f") """
210+
) should returnResult(true)
211+
212+
evaluateExpression(
213+
expression = """ is blank(string: "") """
214+
) should returnResult(true)
215+
}
216+
217+
"A is blank() function" should "return false if the string contains only non-whitespace characters" in {
218+
evaluateExpression(
219+
expression = """ is blank("hello world") """
220+
) should returnResult(false)
221+
222+
evaluateExpression(
223+
expression = """ is blank(" hello world ") """
224+
) should returnResult(false)
225+
}
198226
}

0 commit comments

Comments
 (0)