Skip to content

Commit

Permalink
Feature/bug multi layer array 61 (#62)
Browse files Browse the repository at this point in the history
* bug fix

* removed comment
  • Loading branch information
FransVanEk authored May 25, 2023
1 parent aed7bfd commit ccbe244
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion JLio.Commands/Logic/CopyMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private int GetInnerArrayIndex()
var toPath = JsonPathMethods.SplitPath(ToPath);
if (!fromPath.HasArrayIndication || !toPath.HasArrayIndication) return -1;
var index = fromPath.GetSameElementsIndex(toPath);
if (!HasArrayNotationAfterIndex(fromPath, index))
if (!HasArrayNotationAfterIndex(fromPath, index) || index > 1)
return index;

return -1;
Expand Down
17 changes: 17 additions & 0 deletions JLio.UnitTests/CommandsTests/CopyMoveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ public void CanCopyMovePropertiesInAnLayeredArray(string startobject, string mov
expectedValue)));
}

[TestCase(
"{\"firstArray\":[{\"target\":[],\"secondArray\":[{\"id\":\"item1\",\"sub\":{\"name\":\"item 1\"}},{\"id\":\"item2\",\"sub\":{\"name\":\"item 2\"}}]},{\"target\":[],\"secondArray\":[{\"id\":\"item3\",\"sub\":{\"name\":\"item 3\"}},{\"id\":\"item4\",\"sub\":{\"name\":\"item 4\"}}]}]}",
"$.firstArray[*].secondArray[*].sub",
"$.firstArray[*].target",
"{\"firstArray\":[{\"target\":[{\"name\":\"item 1\"},{\"name\":\"item 2\"}],\"secondArray\":[{\"id\":\"item1\",\"sub\":{\"name\":\"item 1\"}},{\"id\":\"item2\",\"sub\":{\"name\":\"item 2\"}}]},{\"target\":[{\"name\":\"item 3\"},{\"name\":\"item 4\"}],\"secondArray\":[{\"id\":\"item3\",\"sub\":{\"name\":\"item 3\"}},{\"id\":\"item4\",\"sub\":{\"name\":\"item 4\"}}]}]}"
)]
public void CanCopyPropertiesInAnLayeredArray(string startobject, string copyFrom, string copyTo, string expectedValue)
{
var startObject = startobject;
var result =
new Copy(copyFrom, copyTo).Execute(
JToken.Parse(startObject), executeOptions);
Assert.IsTrue(JToken.DeepEquals(result.Data,
JToken.Parse(
expectedValue)));
}

[Test]
public void CanCopyMovePropertiesInAnArray()
{
Expand Down

0 comments on commit ccbe244

Please sign in to comment.