Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Vishakha Karimungi <[email protected]>
Co-authored-by: Vishakha Karimungi <[email protected]>
  • Loading branch information
vish35 and Vishakha Karimungi authored Jul 25, 2024
1 parent b53d2dc commit 9cf16a8
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public ArrayNode addObject(ArrayNode result, ObjectNode obj) {
String key = it.next();
ObjectNode cell = JsonNodeFactory.instance.objectNode();
cell.set(key, obj.get(key));
result = (ArrayNode) append(result, cell);
result = concat(result, cell);
}
return result;
}
Expand Down Expand Up @@ -197,6 +197,7 @@ ArrayNode concat(ArrayNode base, JsonNode appendage) {
result.add(elt);
}
if (appendage.isArray()) {
result.removeAll();
for (JsonNode elt : appendage) {
result.add(elt);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.api.jsonata4java.expressions.functions;

import static com.api.jsonata4java.expressions.utils.Utils.test;

import org.junit.Test;

public class SpreadFunctionTest {

@Test
public void testSpreadForGeneratingCombinationList() throws Exception {
test("$spread($$.array1 ~> $map(function($v1) {\n" +
" $$.array2 ~> $map(function($v2) {\n" +
" $v1 & '#' & $v2\n" +
" })\n" +
" }))", "[\n" +
" \"abcd#pp\",\n" +
" \"abcd#uu\",\n" +
" \"abcd#tt\",\n" +
" \"abcd#uu\",\n" +
" \"abcd#ww\",\n" +
" \"abcd#gg\",\n" +
" \"abcd#qq\",\n" +
" \"abcd#nn\",\n" +
" \"abcd#ff\",\n" +
" \"cdef#pp\",\n" +
" \"cdef#uu\",\n" +
" \"cdef#tt\",\n" +
" \"cdef#uu\",\n" +
" \"cdef#ww\",\n" +
" \"cdef#gg\",\n" +
" \"cdef#qq\",\n" +
" \"cdef#nn\",\n" +
" \"cdef#ff\",\n" +
" \"efgh#pp\",\n" +
" \"efgh#uu\",\n" +
" \"efgh#tt\",\n" +
" \"efgh#uu\",\n" +
" \"efgh#ww\",\n" +
" \"efgh#gg\",\n" +
" \"efgh#qq\",\n" +
" \"efgh#nn\",\n" +
" \"efgh#ff\",\n" +
" \"ghij#pp\",\n" +
" \"ghij#uu\",\n" +
" \"ghij#tt\",\n" +
" \"ghij#uu\",\n" +
" \"ghij#ww\",\n" +
" \"ghij#gg\",\n" +
" \"ghij#qq\",\n" +
" \"ghij#nn\",\n" +
" \"ghij#ff\",\n" +
" \"ijkl#pp\",\n" +
" \"ijkl#uu\",\n" +
" \"ijkl#tt\",\n" +
" \"ijkl#uu\",\n" +
" \"ijkl#ww\",\n" +
" \"ijkl#gg\",\n" +
" \"ijkl#qq\",\n" +
" \"ijkl#nn\",\n" +
" \"ijkl#ff\",\n" +
" \"klmn#pp\",\n" +
" \"klmn#uu\",\n" +
" \"klmn#tt\",\n" +
" \"klmn#uu\",\n" +
" \"klmn#ww\",\n" +
" \"klmn#gg\",\n" +
" \"klmn#qq\",\n" +
" \"klmn#nn\",\n" +
" \"klmn#ff\",\n" +
" \"mnop#pp\",\n" +
" \"mnop#uu\",\n" +
" \"mnop#tt\",\n" +
" \"mnop#uu\",\n" +
" \"mnop#ww\",\n" +
" \"mnop#gg\",\n" +
" \"mnop#qq\",\n" +
" \"mnop#nn\",\n" +
" \"mnop#ff\"\n" +
"]", null, "{\n" +
" \"array1\": [\n" +
" \"abcd\",\n" +
" \"cdef\",\n" +
" \"efgh\",\n" +
" \"ghij\",\n" +
" \"ijkl\",\n" +
" \"klmn\",\n" +
" \"mnop\"\n" +
" ],\n" +
" \"array2\": [\n" +
" \"pp\",\n" +
" \"uu\",\n" +
" \"tt\",\n" +
" \"uu\",\n" +
" \"ww\",\n" +
" \"gg\",\n" +
" \"qq\",\n" +
" \"nn\",\n" +
" \"ff\"\n" +
" ]\n" +
"}");
}

}

0 comments on commit 9cf16a8

Please sign in to comment.