Skip to content

Commit

Permalink
Fix in() Fix conditional with unexpected values. (hbz/lobid-resourc…
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Sep 13, 2023
1 parent 1895fd1 commit 6810484
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ public boolean test(final Metafix metafix, final Record record, final List<Strin
return value1 != null && value2 != null && value1.<Boolean>extractType((m, c) -> m
.ifArray(a1 -> value2.matchType()
.ifArray(a2 -> c.accept(a1.equals(a2)))
.orElse(v -> c.accept(false))
)
.ifHash(h1 -> value2.matchType()
.ifHash(h2 -> c.accept(h1.equals(h2)))
.orElse(v -> c.accept(false))
)
.ifString(s1 -> value2.matchType()
.ifArray(a2 -> c.accept(a2.stream().anyMatch(value1::equals)))
Expand Down
83 changes: 83 additions & 0 deletions metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,89 @@ public void shouldContainHashInHash() {
);
}

@Test
public void shouldNotContainArrayInString() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"unless in(bar,foo)",
" add_field(test,ok)",
"end"
),
i -> {
i.startRecord("1");
i.literal("foo", "1");
i.literal("bar", "1");
i.literal("bar", "2");
i.literal("bar", "3");
i.endRecord();
i.startRecord("2");
i.literal("foo", "42");
i.literal("bar", "1");
i.literal("bar", "2");
i.literal("bar", "3");
i.endRecord();
},
o -> {
o.get().startRecord("1");
o.get().literal("foo", "1");
o.get().literal("bar", "1");
o.get().literal("bar", "2");
o.get().literal("bar", "3");
o.get().literal("test", "ok");
o.get().endRecord();
o.get().startRecord("2");
o.get().literal("foo", "42");
o.get().literal("bar", "1");
o.get().literal("bar", "2");
o.get().literal("bar", "3");
o.get().literal("test", "ok");
o.get().endRecord();
}
);
}

@Test
public void shouldNotContainHashInString() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"unless in(bar,foo)",
" add_field(test,ok)",
"end"
),
i -> {
i.startRecord("1");
i.literal("foo", "name");
i.startEntity("bar");
i.literal("name", "Patrick");
i.endEntity();
i.endRecord();
i.startRecord("2");
i.literal("foo", "name");
i.startEntity("bar");
i.startEntity("deep");
i.literal("name", "Nicolas");
i.endEntity();
i.endEntity();
i.endRecord();
},
(o, f) -> {
o.get().startRecord("1");
o.get().literal("foo", "name");
o.get().startEntity("bar");
o.get().literal("name", "Patrick");
o.get().endEntity();
o.get().literal("test", "ok");
o.get().endRecord();
o.get().startRecord("2");
o.get().literal("foo", "name");
o.get().startEntity("bar");
o.get().startEntity("deep");
o.get().literal("name", "Nicolas");
f.apply(2).endEntity();
o.get().literal("test", "ok");
o.get().endRecord();
}
);
}

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

0 comments on commit 6810484

Please sign in to comment.