Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ object BooleanBuiltinFunctions {
"not" -> List(notFunction),
"is defined" -> List(isDefinedFunction),
"get or else" -> List(getOrElse),
"assert" -> List(assertFunction, assertFunction2)
"assert" -> List(assertFunction, assertFunction2),
"is blank" -> List(isBlankFunction)
)

private def notFunction =
Expand Down Expand Up @@ -70,4 +71,11 @@ object BooleanBuiltinFunctions {
}
)

private def isBlankFunction = builtinFunction(
params = List("string"),
invoke = {case List(ValString(string)) =>
ValBoolean(string.isBlank)
}
)
Copy link
Member

Choose a reason for hiding this comment

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

❌ Since is blank() is a function for a string argument, we should add the function to StringBuiltinFunctions.

BooleanBuiltinFunctions is for functions with a boolean argument.


}
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,27 @@ class BuiltinFunctionsTest
"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"
)
}

"A is blank() function" should "return Boolean" in {
Copy link
Member

Choose a reason for hiding this comment

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

❌ Same as the implementation, we should add the test cases to BuiltinStringFunctionsTest.

evaluateExpression(
expression = """ is blank("") """
) should returnResult(true)
Copy link
Member

Choose a reason for hiding this comment

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

❌ Add one more test case that verifies the invocation of the function with named parameters:

evaluateExpression(
      expression = """ is blank(string: "") """
    ) should returnResult(true)

This kind of test ensures that we don't change the parameter name accidentally.


evaluateExpression(
expression = """ is blank(" ") """
) should returnResult(true)

evaluateExpression(
expression = """ is blank("hello world") """
) should returnResult(false)

evaluateExpression(
expression = """ is blank(" hello world ") """
) should returnResult(false)

evaluateExpression(
expression = """ is blank("\t\n\r\f") """
) should returnResult(true)
Copy link
Member

Choose a reason for hiding this comment

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

🔧 We could split the test cases into:

  • should "return true if the string contains only whitespace"
  • should "return false if the string contains non-whitespace characters"

}

}