-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36b7aa5
commit 9e088cb
Showing
3 changed files
with
61 additions
and
18 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.approvaltests; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class Parse2InputTest | ||
{ | ||
@Test | ||
void testWithTypesTransformersAndBoth() | ||
{ | ||
var expected = """ | ||
1,2.2 -> 2.2 | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.approvaltests; | ||
|
||
import com.spun.util.Tuple; | ||
import org.lambda.functions.Function1; | ||
import org.lambda.query.Queryable; | ||
|
||
import static org.approvaltests.ParseInput.getTransformerForClass; | ||
|
||
public class ParseInputWith2Parameters<IN1, IN2, OUT> | ||
{ | ||
private final String expected; | ||
private final Function1<String, OUT> transformer; | ||
public ParseInputWith2Parameters(String expected, Function1<String, OUT> transformer) | ||
{ | ||
this.expected = expected; | ||
this.transformer = transformer; | ||
} | ||
public static <IN1, IN2> ParseInputWith2Parameters<IN1, IN2, Tuple<IN1, IN2>> create(String expected, | ||
Class<IN1> type1, Class<IN2> type2) | ||
{ | ||
Function1<String, IN1> t1 = getTransformerForClass(type1); | ||
Function1<String, IN2> t2 = getTransformerForClass(type2); | ||
Function1<String, Tuple<IN1, IN2>> f = s -> { | ||
var temp = Queryable.as(s.split(",")).select(String::trim); | ||
IN1 v1 = t1.call(temp.get(0)); | ||
IN2 v2 = t2.call(temp.get(1)); | ||
return new Tuple<>(v1, v2); | ||
}; | ||
return new ParseInputWith2Parameters<>(expected, f); | ||
} | ||
// public <OUT2> ParseInputWith2Parameters<OUT2> transformTo(Function1<IN1, OUT2> transformer1) | ||
// { | ||
// Function1<String, OUT2> transformer2 = (String t) -> transformer1.call(transformer.call(t)); | ||
// return new ParseInputWith2Parameters<>(expected, transformer2); | ||
// } | ||
public void verifyAll(Function1<OUT, Object> transform) | ||
{ | ||
ParseInput.from(expected, transformer).verifyAll(transform); | ||
} | ||
} |