Skip to content

Commit d84cc94

Browse files
committed
Add tests #333
1 parent 27634d1 commit d84cc94

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ public void shouldLookupInSeparateInternalMap() {
453453
);
454454
}
455455

456+
@Test
457+
public void shouldUseDefaultOptionFromLookupOption() {
458+
assertMap(
459+
"put_map('testMap', Aloha: Alohaeha, 'Moin': 'Moin zäme')",
460+
LOOKUP + " 'testMap', default: 'Tach')"
461+
);
462+
}
463+
456464
@Test
457465
public void shouldLookupInSeparateExternalFileMap() {
458466
assertMap(
@@ -630,6 +638,52 @@ public void shouldUseDefaultValueIfNotFound() {
630638
);
631639
}
632640

641+
@Test
642+
public void shouldUseDefaultOptionValueIfNotFound() {
643+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
644+
"put_map('testMap', Aloha: Alohaeha, 'Moin': 'Moin zäme')",
645+
"lookup('title.*', 'testMap', default: 'Tach')"
646+
),
647+
i -> {
648+
i.startRecord("1");
649+
i.literal("title", "Aloha");
650+
i.literal("title", "Moin");
651+
i.literal("title", "Yo");
652+
i.endRecord();
653+
},
654+
o -> {
655+
o.get().startRecord("1");
656+
o.get().literal("title", "Alohaeha");
657+
o.get().literal("title", "Moin zäme");
658+
o.get().literal("title", "Tach");
659+
o.get().endRecord();
660+
}
661+
);
662+
}
663+
664+
@Test
665+
public void shouldPreferDefaultOptionValueOverDefaultMapValue() {
666+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
667+
"put_map('testMap', Aloha: Alohaeha, 'Moin': 'Moin zäme', __default: Tach)",
668+
"lookup('title.*', 'testMap', default: 'Hi')"
669+
),
670+
i -> {
671+
i.startRecord("1");
672+
i.literal("title", "Aloha");
673+
i.literal("title", "Moin");
674+
i.literal("title", "Yo");
675+
i.endRecord();
676+
},
677+
o -> {
678+
o.get().startRecord("1");
679+
o.get().literal("title", "Alohaeha");
680+
o.get().literal("title", "Moin zäme");
681+
o.get().literal("title", "Hi");
682+
o.get().endRecord();
683+
}
684+
);
685+
}
686+
633687
@Test
634688
// See https://github.com/metafacture/metafacture-fix/issues/149
635689
public void shouldDeleteNonFoundLookupOnDemand() {

0 commit comments

Comments
 (0)