Skip to content

Commit

Permalink
Fix concat with text and number (#738)
Browse files Browse the repository at this point in the history
Co-authored-by: Jost, Michael <michael.jost@sicpa.com>
  • Loading branch information
mijost and mjostscpa committed Nov 4, 2021
1 parent 491dfbc commit 8e8fc14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public static void consume(Class expectedType, EvaluationContext ctx, Collection
} else {
if (value != null && expectedType.isAssignableFrom(value.getClass())) {
collection.add(value);
} else if (value != null && expectedType == String.class) {
collection.add(value.toString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class BaseFunctionTest {
protected static final String NUMBER_SERIES = "{\"empty\": [], \"numbers\" : [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}";
protected static final String TEXT_SERIES = "{\"urls\": [\"http://api.worldbank.org/countries/all/?format=json\", \"http://api.worldbank.org/countries/all/?format=json\"], \"text\" : [ \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ]}";
protected static final String TEXT_AND_NUMBER_SERIES = "{\"text\" : [ \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ], \"numbers\" : [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}";

/**
* Verify the function returns the correct result based on the input expectedValue
Expand All @@ -40,6 +41,10 @@ protected void verifyTextFunction(Configuration conf, String pathExpr, Object ex
verifyFunction(conf, pathExpr, TEXT_SERIES, expectedValue);
}

protected void verifyTextAndNumberFunction(Configuration conf, String pathExpr, Object expectedValue) {
verifyFunction(conf, pathExpr, TEXT_AND_NUMBER_SERIES, expectedValue);
}

protected String getResourceAsText(String resourceName) throws IOException {
return new Scanner(BaseFunctionTest.class.getResourceAsStream(resourceName), "UTF-8").useDelimiter("\\A").next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public void testStringConcat() {
verifyTextFunction(conf, "$.text.concat()", "abcdef");
}

@Test
public void testStringAndNumberConcat() {
verifyTextAndNumberFunction(conf, "$.concat($.text[0], $.numbers[0])", "a1");
}

@Test
public void testStringConcatWithJSONParameter() {
verifyTextFunction(conf, "$.text.concat(\"-\", \"ghijk\")", "abcdef-ghijk");
Expand Down

0 comments on commit 8e8fc14

Please sign in to comment.