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

Commit

Permalink
Add index() Fix function. (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Jan 11, 2022
1 parent 16e8c5c commit 28318fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions metafix/src/main/java/org/metafacture/metafix/FixMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ public void apply(final Metafix metafix, final Record record, final List<String>
});
}
},
index {
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
final String search = params.get(1);
record.transformFields(params, s -> String.valueOf(s.indexOf(search))); // TODO: multiple
}
},
lookup {
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
final Map<String, String> map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,24 @@ public void shouldFilterArrayValuesInverted() {
);
}

@Test
public void shouldGetIndexOfSubstring() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"index(title, 't')"
),
i -> {
i.startRecord("1");
i.literal("title", "metafix");
i.endRecord();
},
o -> {
o.get().startRecord("1");
o.get().literal("title", "2");
o.get().endRecord();
}
);
}

private void assertThrows(final Class<?> expectedClass, final String expectedMessage, final Executable executable) {
final Throwable exception = Assertions.assertThrows(MetafactureException.class, executable).getCause();
Assertions.assertSame(expectedClass, exception.getClass());
Expand Down

0 comments on commit 28318fa

Please sign in to comment.