Skip to content

Commit

Permalink
- F transformTo(A,B)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsEckart committed Feb 26, 2024
1 parent 1da0c86 commit 2a1419c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void testSimpleString()
b -> B
""";
ParseInput.from(expected).verifyAll(String::toUpperCase);
Approvals.verifyAll(ParseInput.from(expected).getInputs(), s -> s + " -> " + s.toUpperCase(),
new Options().inline(expected));
}
@Test
void testWithTypesTransformersAndBoth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ void testWithTypesTransformersAndBoth()
1,3.3 -> 3.3
""";
ParseInput.from(expected).withTypes(Integer.class, Double.class).verifyAll(t -> t.getFirst() * t.getSecond());
// TODO: continue here
// ParseInput.from(expected).transformTo(Integer::parseInt).verifyAll(Integer::toBinaryString);
// ParseInput.from(expected).withTypes(String.class).transformTo(Integer::parseInt).verifyAll(Integer::toBinaryString);
ParseInput.from(expected).transformTo(Integer::parseInt, Double::parseDouble).verifyAll(t -> t.getFirst() * t.getSecond());
// ParseInput.from(expected).withTypes(String.class).transformTo(Integer::parseInt)
// .verifyAll(Integer::toBinaryString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public <T1, T2> ParseInputWith2Parameters<T1, T2, Tuple<T1, T2>> withTypes(Class
{
return ParseInputWith2Parameters.create(expected, type1, type2);
}
public <T1, T2> ParseInputWith2Parameters<T1, T2, Tuple<T1, T2>> transformTo(Function1<String, T1> transformer1, Function1<String, T2> transformer2)
{
return ParseInputWith2Parameters.create(expected, transformer1, transformer2);

}
public ParseInput<OUT> multiline()
{
this.multiline = true;
Expand All @@ -107,4 +112,8 @@ public <OUT> ParseInputWith1Parameters<OUT> transformTo(Function1<String, OUT> t
{
return new ParseInputWith1Parameters<>(expected, transformer);
}
public Queryable<OUT> getInputs()
{
return parse().select(Tuple::getSecond);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public static <IN1, IN2> ParseInputWith2Parameters<IN1, IN2, Tuple<IN1, IN2>> cr
{
Function1<String, IN1> t1 = getTransformerForClass(type1);
Function1<String, IN2> t2 = getTransformerForClass(type2);
return create(expected, t1, t2);
}
public static <IN1, IN2> ParseInputWith2Parameters<IN1, IN2, Tuple<IN1, IN2>> create(String expected,
Function1<String, IN1> t1, Function1<String, IN2> t2)
{
Function1<String, Tuple<IN1, IN2>> f = s -> {
var temp = Queryable.as(s.split(",")).select(String::trim);
IN1 v1 = t1.call(temp.get(0));
Expand Down

0 comments on commit 2a1419c

Please sign in to comment.