@@ -19,6 +19,7 @@ package org.camunda.feel.impl.builtin
1919import org .scalatest .matchers .should .Matchers
2020import org .scalatest .flatspec .AnyFlatSpec
2121import org .camunda .feel ._
22+ import org .camunda .feel .api .EvaluationFailureType .FUNCTION_INVOCATION_FAILURE
2223import org .camunda .feel .impl .{EvaluationResultMatchers , FeelEngineTest , FeelIntegrationTest }
2324import org .camunda .feel .syntaxtree ._
2425
@@ -570,4 +571,32 @@ class BuiltinListFunctionsTest
570571 evaluateExpression(" is empty([1,2,3]) " ) should returnResult(false )
571572 evaluateExpression(" is empty(list: [1]) " ) should returnResult(false )
572573 }
574+
575+ " A partition() function" should " return list partitioned by _" in {
576+ evaluateExpression(" partition([1,2,3,4,5], 2) " ) should returnResult(
577+ List (List (1 , 2 ), List (3 , 4 ), List (5 ))
578+ )
579+ evaluateExpression(" partition(list: [1,2,3,4,5], size: 2) " ) should returnResult(
580+ List (List (1 , 2 ), List (3 , 4 ), List (5 ))
581+ )
582+
583+ evaluateExpression(" partition([], 2) " ) should returnResult(List ())
584+ evaluateExpression(" partition([1], 2) " ) should returnResult(List (List (1 )))
585+ }
586+
587+ it should " return null if the size is invalid" in {
588+ evaluateExpression(" partition([1,2], 0) " ) should (
589+ returnNull() and reportFailure(
590+ FUNCTION_INVOCATION_FAILURE ,
591+ " Failed to invoke function 'partition': 'size' should be greater than zero but was '0'"
592+ )
593+ )
594+
595+ evaluateExpression(" partition([1,2], -1) " ) should (
596+ returnNull() and reportFailure(
597+ FUNCTION_INVOCATION_FAILURE ,
598+ " Failed to invoke function 'partition': 'size' should be greater than zero but was '-1'"
599+ )
600+ )
601+ }
573602}
0 commit comments