Skip to content

Commit

Permalink
Correct behavior of $append function. #37
Browse files Browse the repository at this point in the history
The discrepancy is caused by a (legacy) condition in the $append function.
This was introduced to hide an older parser issue (which was fixed in the meantime) so it is no longer needed
  • Loading branch information
uw4 committed May 22, 2024
1 parent e7d2339 commit 8f8c8cd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
8 changes: 1 addition & 7 deletions src/main/java/com/dashjoin/jsonata/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2080,19 +2080,13 @@ public static Object append(Object arg1, Object arg2) {
if (!(arg2 instanceof List)) {
arg2 = new JList<>(Arrays.asList(arg2));
}
// else
// // Arg2 was a list: add it as a list element (don't flatten)
// ((List)arg1).add((List)arg2);

// Shortcut:
if (((List)arg1).isEmpty() && (arg2 instanceof Utils.RangeList))
return arg2;

arg1 = new JList<>((List)arg1); // create a new copy!
if (arg2 instanceof JList && ((JList)arg2).cons)
((List)arg1).add(arg2);
else
((List)arg1).addAll((List)arg2);
((List)arg1).addAll((List)arg2);
return arg1;
}

Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/dashjoin/jsonata/ArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import static java.util.Arrays.asList;
import static java.util.Map.of;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class ArrayTest {

@Disabled
@Test
public void testArray() {
Jsonata expr1 = jsonata("{'key': $append($.[{'x': 'y'}],$.[{'a': 'b'}])}");
Expand Down

0 comments on commit 8f8c8cd

Please sign in to comment.