Skip to content

Commit 6810484

Browse files
committed
Fix in() Fix conditional with unexpected values. (hbz/lobid-resources#1889)
1 parent 1895fd1 commit 6810484

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

metafix/src/main/java/org/metafacture/metafix/FixConditional.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ public boolean test(final Metafix metafix, final Record record, final List<Strin
8989
return value1 != null && value2 != null && value1.<Boolean>extractType((m, c) -> m
9090
.ifArray(a1 -> value2.matchType()
9191
.ifArray(a2 -> c.accept(a1.equals(a2)))
92+
.orElse(v -> c.accept(false))
9293
)
9394
.ifHash(h1 -> value2.matchType()
9495
.ifHash(h2 -> c.accept(h1.equals(h2)))
96+
.orElse(v -> c.accept(false))
9597
)
9698
.ifString(s1 -> value2.matchType()
9799
.ifArray(a2 -> c.accept(a2.stream().anyMatch(value1::equals)))

metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,89 @@ public void shouldContainHashInHash() {
14301430
);
14311431
}
14321432

1433+
@Test
1434+
public void shouldNotContainArrayInString() {
1435+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
1436+
"unless in(bar,foo)",
1437+
" add_field(test,ok)",
1438+
"end"
1439+
),
1440+
i -> {
1441+
i.startRecord("1");
1442+
i.literal("foo", "1");
1443+
i.literal("bar", "1");
1444+
i.literal("bar", "2");
1445+
i.literal("bar", "3");
1446+
i.endRecord();
1447+
i.startRecord("2");
1448+
i.literal("foo", "42");
1449+
i.literal("bar", "1");
1450+
i.literal("bar", "2");
1451+
i.literal("bar", "3");
1452+
i.endRecord();
1453+
},
1454+
o -> {
1455+
o.get().startRecord("1");
1456+
o.get().literal("foo", "1");
1457+
o.get().literal("bar", "1");
1458+
o.get().literal("bar", "2");
1459+
o.get().literal("bar", "3");
1460+
o.get().literal("test", "ok");
1461+
o.get().endRecord();
1462+
o.get().startRecord("2");
1463+
o.get().literal("foo", "42");
1464+
o.get().literal("bar", "1");
1465+
o.get().literal("bar", "2");
1466+
o.get().literal("bar", "3");
1467+
o.get().literal("test", "ok");
1468+
o.get().endRecord();
1469+
}
1470+
);
1471+
}
1472+
1473+
@Test
1474+
public void shouldNotContainHashInString() {
1475+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
1476+
"unless in(bar,foo)",
1477+
" add_field(test,ok)",
1478+
"end"
1479+
),
1480+
i -> {
1481+
i.startRecord("1");
1482+
i.literal("foo", "name");
1483+
i.startEntity("bar");
1484+
i.literal("name", "Patrick");
1485+
i.endEntity();
1486+
i.endRecord();
1487+
i.startRecord("2");
1488+
i.literal("foo", "name");
1489+
i.startEntity("bar");
1490+
i.startEntity("deep");
1491+
i.literal("name", "Nicolas");
1492+
i.endEntity();
1493+
i.endEntity();
1494+
i.endRecord();
1495+
},
1496+
(o, f) -> {
1497+
o.get().startRecord("1");
1498+
o.get().literal("foo", "name");
1499+
o.get().startEntity("bar");
1500+
o.get().literal("name", "Patrick");
1501+
o.get().endEntity();
1502+
o.get().literal("test", "ok");
1503+
o.get().endRecord();
1504+
o.get().startRecord("2");
1505+
o.get().literal("foo", "name");
1506+
o.get().startEntity("bar");
1507+
o.get().startEntity("deep");
1508+
o.get().literal("name", "Nicolas");
1509+
f.apply(2).endEntity();
1510+
o.get().literal("test", "ok");
1511+
o.get().endRecord();
1512+
}
1513+
);
1514+
}
1515+
14331516
@Test
14341517
public void shouldReportArrayAsArray() {
14351518
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(

0 commit comments

Comments
 (0)