Github user mattf-horton commented on a diff in the pull request: https://github.com/apache/incubator-metron/pull/516#discussion_r110294160 --- Diff: metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/StringFunctionsTest.java --- @@ -207,4 +207,78 @@ public void testFormatWithNoArguments() throws Exception { public void testFormatWithMissingArguments() throws Exception { run("FORMAT('missing arg: %d')", Collections.emptyMap()); } + + + /** + * CHOP StringFunction + * @throws Exception + */ + @Test + public void testChop() throws Exception { + Assert.assertEquals("ab", run("CHOP('abc')", new HashedMap())); + Assert.assertEquals(null, run("CHOP(null)", new HashedMap())); + Assert.assertEquals("abc", run("CHOP(msg)", ImmutableMap.of("msg", "abc\r\n"))); + Assert.assertEquals("", run("CHOP(msg)", ImmutableMap.of("msg", "\n"))); + } + + @Test(expected = ParseException.class) + public void testChopWithMissingArguments() throws Exception { + run("CHOP()", Collections.emptyMap()); + } + + /** + * PREPENDIFMISSING StringFunction + * @throws Exception + */ + @Test + public void testPrependIfMissing() throws Exception { + Assert.assertEquals("xyzabc", run("PREPENDIFMISSING('abc', 'xyz')", new HashedMap())); + Assert.assertEquals("xyzXYZabc", run("PREPENDIFMISSING('XYZabc', 'xyz', 'mno')", new HashedMap())); + Assert.assertEquals(null, run("PREPENDIFMISSING(null, null, null)", new HashedMap())); + Assert.assertEquals("xyz", run("PREPENDIFMISSING('', 'xyz', null)", new HashedMap())); + } + + @Test(expected = ParseException.class) + public void testPrependIfMissingWithIncorrectArgs() throws Exception { + run("PREPENDIFMISSING()", Collections.emptyMap()); + run("PREPENDIFMISSING('abc')", Collections.emptyMap()); + run("PREPENDIFMISSING('abc', 'def', 'ghi', 'jkl')", Collections.emptyMap()); + } + + /** + * APPENDIFMISSING StringFunction --- End diff -- Same issues here of course, and in COUNTMATCHES.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---