Skip to content

Commit 237431e

Browse files
committed
test: Verify list functions with zero position
Add a test case to verify that list function with a zero position returns null.
1 parent 61a5064 commit 237431e

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ package org.camunda.feel.impl.builtin
1818

1919
import org.scalatest.matchers.should.Matchers
2020
import org.scalatest.flatspec.AnyFlatSpec
21-
import org.camunda.feel._
2221
import org.camunda.feel.api.EvaluationFailureType.FUNCTION_INVOCATION_FAILURE
23-
import org.camunda.feel.impl.{EvaluationResultMatchers, FeelEngineTest, FeelIntegrationTest}
24-
import org.camunda.feel.syntaxtree._
22+
import org.camunda.feel.impl.{EvaluationResultMatchers, FeelEngineTest}
2523

2624
import java.time.LocalDate
27-
import scala.math.BigDecimal.int2bigDecimal
2825

2926
/** @author
3027
* Philipp
@@ -257,6 +254,21 @@ class BuiltinListFunctionsTest
257254
evaluateExpression(" sublist([1,2,3], 1, 2) ") should returnResult(List(1, 2))
258255
}
259256

257+
it should "return null if the start position is 0" in {
258+
259+
evaluateExpression(" sublist([1,2,3], 0) ") should (returnNull() and reportFailure(
260+
failureType = FUNCTION_INVOCATION_FAILURE,
261+
failureMessage =
262+
"Failed to invoke function 'sublist': start position must be a non-zero number"
263+
))
264+
265+
evaluateExpression(" sublist([1,2,3], 0, 2) ") should (returnNull() and reportFailure(
266+
failureType = FUNCTION_INVOCATION_FAILURE,
267+
failureMessage =
268+
"Failed to invoke function 'sublist': start position must be a non-zero number"
269+
))
270+
}
271+
260272
"A append() function" should "return list with item appended" in {
261273

262274
evaluateExpression(" append([1,2], 3) ") should returnResult(List(1, 2, 3))
@@ -274,11 +286,28 @@ class BuiltinListFunctionsTest
274286
evaluateExpression(" insert before([1,3],2,2) ") should returnResult(List(1, 2, 3))
275287
}
276288

289+
it should "return null if the position is 0" in {
290+
291+
evaluateExpression(" insert before([1,3],0,2) ") should (returnNull() and reportFailure(
292+
failureType = FUNCTION_INVOCATION_FAILURE,
293+
failureMessage =
294+
"Failed to invoke function 'insert before': position must be a non-zero number"
295+
))
296+
}
297+
277298
"A remove() function" should "return list with item at _ removed" in {
278299

279300
evaluateExpression(" remove([1,1,3],2) ") should returnResult(List(1, 3))
280301
}
281302

303+
it should "return null if the position is 0" in {
304+
305+
evaluateExpression(" remove([1,2,3], 0) ") should (returnNull() and reportFailure(
306+
failureType = FUNCTION_INVOCATION_FAILURE,
307+
failureMessage = "Failed to invoke function 'remove': position must be a non-zero number"
308+
))
309+
}
310+
282311
"A reverse() function" should "reverse the list" in {
283312

284313
evaluateExpression(" reverse([1,2,3]) ") should returnResult(List(3, 2, 1))

0 commit comments

Comments
 (0)