Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Fix asterisk handling on insert into array (#113, #121, #130, #156)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed May 3, 2022
1 parent 8ffc9ac commit f278ef2
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
12 changes: 4 additions & 8 deletions metafix/src/main/java/org/metafacture/metafix/FixPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,10 @@ private void removeNestedFrom(final Value value) {
// basic idea: reuse findIn logic here? setIn(findIn(array), newValue)
final String field = path[0];
if (field.equals(ASTERISK)) {
if (path.length == 1) {
for (int i = 0; i < array.size(); ++i) {
mode.apply(array, String.valueOf(i + 1), newValue);
}
}
else {
array.add(Value.newHash(h -> new FixPath(tail(path)).insertInto(h, mode, newValue)));
}
array.forEach(value -> value.matchType()
.ifArray(a -> new FixPath(tail(path)).insertInto(a, mode, newValue))
.ifHash(h -> new FixPath(tail(path)).insertInto(h, mode, newValue))
.orElseThrow());
}
else {
if (path.length == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,6 @@ public void shouldSortFieldAndRemoveDuplicates() {
}

@Test
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldSortArrayFieldWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"sort_field('OTHERS[].*.dnimals[]')"
Expand Down Expand Up @@ -2558,7 +2557,6 @@ public void shouldSplitHashField() {
}

@Test
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/100 and https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldSplitNestedField() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"split_field('others[].*.tools', '--')"
Expand Down Expand Up @@ -2607,7 +2605,6 @@ public void shouldSumNumbers() {
}

@Test
@MetafixToDo("java.lang.IllegalStateException: Expected String, got Array; see https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldSumArrayFieldWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"sum('OTHERS[].*.dumbers[]')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,39 @@ public void setArrayReplaceExisting() {
});
}

@Test
// See https://github.com/metafacture/metafacture-fix/issues/130
public void setArrayInArrayWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('foo[].*.test[]', 'test')"),
i -> {
i.startRecord("1");
i.startEntity("foo[]");
i.startEntity("1");
i.literal("id", "A");
i.endEntity();
i.startEntity("2");
i.literal("id", "B");
i.endEntity();
i.endEntity();
i.endRecord();
}, (o, f) -> {
o.get().startRecord("1");
o.get().startEntity("foo[]");
o.get().startEntity("1");
o.get().literal("id", "A");
o.get().startEntity("test[]");
o.get().literal("1", "test");
f.apply(2).endEntity();
o.get().startEntity("2");
o.get().literal("id", "B");
o.get().startEntity("test[]");
o.get().literal("1", "test");
f.apply(3).endEntity();
o.get().endRecord();
});
}

@Test
public void setHash() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
See issue #132 may also be related to #113
See issue #132

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit f278ef2

Please sign in to comment.