Skip to content

Commit

Permalink
StringJoinFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
yesamer committed Jun 17, 2024
1 parent 974628b commit e1c61d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,28 @@
import org.kie.dmn.feel.runtime.functions.SqrtFunction;
import org.kie.dmn.feel.runtime.functions.StddevFunction;
import org.kie.dmn.feel.runtime.functions.extended.DateFunction;
import org.kie.dmn.feel.runtime.functions.extended.StringJoinFunction;
import org.kie.dmn.feel.runtime.functions.extended.TimeFunction;

import static java.math.BigDecimal.valueOf;
import static org.assertj.core.api.Assertions.assertThat;

class ExtendedDMNProfileTest {

private final DateFunction dateFunction = DateFunction.INSTANCE;
private final TimeFunction timeFunction = TimeFunction.INSTANCE;
private final SplitFunction splitFunction = SplitFunction.INSTANCE;
private final ProductFunction productFunction = ProductFunction.INSTANCE;
private final EvenFunction evenFunction = EvenFunction.INSTANCE;
private final ExpFunction expFunction = ExpFunction.INSTANCE;
private final LogFunction logFunction = LogFunction.INSTANCE;
private final MedianFunction medianFunction = MedianFunction.INSTANCE;
private final StddevFunction stddevFunction = StddevFunction.INSTANCE;
private final ModeFunction modeFunction = ModeFunction.INSTANCE;
private final AbsFunction absFunction = AbsFunction.INSTANCE;
private final ModuloFunction moduloFunction = ModuloFunction.INSTANCE;
private final SqrtFunction sqrtFunction = SqrtFunction.INSTANCE;
private final LogFunction logFunction = LogFunction.INSTANCE;
private final ExpFunction expFunction = ExpFunction.INSTANCE;
private final EvenFunction evenFunction = EvenFunction.INSTANCE;
private final OddFunction oddFunction = OddFunction.INSTANCE;
private final ProductFunction productFunction = ProductFunction.INSTANCE;
private final SplitFunction splitFunction = SplitFunction.INSTANCE;
private final SqrtFunction sqrtFunction = SqrtFunction.INSTANCE;
private final StddevFunction stddevFunction = StddevFunction.INSTANCE;
private final StringJoinFunction stringJoinFunction = StringJoinFunction.INSTANCE;
private final TimeFunction timeFunction = TimeFunction.INSTANCE;

@Test
void dateFunctionInvokeParamStringDateTime() {
Expand Down Expand Up @@ -162,6 +164,20 @@ void evenFunctionFractional() {
assertResult(evenFunction.invoke(valueOf(2.0)), Boolean.TRUE);
}

@Test
void stringJoinFunction() {
assertResult(stringJoinFunction.invoke(Arrays.asList("a", "b", "c"), "_and_"), "a_and_b_and_c");
assertResult(stringJoinFunction.invoke(Arrays.asList("a", "b", "c"), ""), "abc");
assertResult(stringJoinFunction.invoke(Arrays.asList("a", "b", "c"), null), "abc");
assertResult(stringJoinFunction.invoke(Arrays.asList("a"), "X"), "a");
assertResult(stringJoinFunction.invoke("a", "X"), "a");
assertResult(stringJoinFunction.invoke(Arrays.asList("a", null, "c"), "X"), "aXc");
assertResult(stringJoinFunction.invoke(Collections.emptyList(), "X"), "");
assertResult(stringJoinFunction.invoke(Arrays.asList("a", "b", "c")), "abc");
assertResult(stringJoinFunction.invoke(Arrays.asList("a", null, "c")), "ac");
assertResult(stringJoinFunction.invoke(Collections.emptyList()), "");
}

private static <T> void assertResult(final FEELFnResult<T> result, final T val) {
assertThat(result.isRight()).isTrue();
assertThat(result.getOrElse(null)).isEqualTo(val);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public FEELFnResult<String> invoke(@ParameterName("list") List<?> list, @Paramet
return FEELFnResult.ofResult(sj.toString());
}

public FEELFnResult<String> invoke(@ParameterName("list") String stringValue, @ParameterName("delimiter") String delimiter) {
return invoke(List.of(stringValue), delimiter);
}

public FEELFnResult<String> invoke(@ParameterName("list") List<?> list) {
return invoke(list, null);
}
Expand Down

0 comments on commit e1c61d5

Please sign in to comment.