Skip to content

Commit

Permalink
test: Verify number() return null
Browse files Browse the repository at this point in the history
Add a test case to verify that the function number() returns null if the given string is not a number.
  • Loading branch information
saig0 committed Aug 22, 2024
1 parent 184ea41 commit b2afedd
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.camunda.feel.impl.builtin

import org.camunda.feel.api.EvaluationFailureType.FUNCTION_INVOCATION_FAILURE
import org.camunda.feel.api.FeelEngineBuilder
import org.camunda.feel.impl.interpreter.MyCustomContext
import org.camunda.feel.impl.{EvaluationResultMatchers, FeelEngineTest}
Expand Down Expand Up @@ -218,6 +219,30 @@ class BuiltinConversionFunctionsTest
)
}

it should "return null if the string is not a number" in {

evaluateExpression(""" number("x") """) should (
returnNull() and reportFailure(
FUNCTION_INVOCATION_FAILURE,
"Failed to invoke function 'number': Can't parse 'x' as a number"
)
)

evaluateExpression(""" number("x", ".") """) should (
returnNull() and reportFailure(
FUNCTION_INVOCATION_FAILURE,
"Failed to invoke function 'number': Can't parse 'x' as a number"
)
)

evaluateExpression(""" number("x", ".", ",") """) should (
returnNull() and reportFailure(
FUNCTION_INVOCATION_FAILURE,
"Failed to invoke function 'number': Can't parse 'x' as a number"
)
)
}

"A string() function" should "convert Number" in {

evaluateExpression(""" string(1.1) """) should returnResult("1.1")
Expand Down

0 comments on commit b2afedd

Please sign in to comment.