Skip to content

Commit 70378c3

Browse files
committed
- F partial implementation of ParseInput with 3 parameters
1 parent 0febf5e commit 70378c3

File tree

3 files changed

+59
-64
lines changed

3 files changed

+59
-64
lines changed

approvaltests-tests/src/test/java/org/approvaltests/Parse3InputTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ public class Parse3InputTest
1212
void testWithTypesTransformersAndBoth()
1313
{
1414
var expected = """
15-
1,2.2,true -> 2.2
16-
1,3.3,false -> 0.0
17-
""";
15+
1,2.2,true -> 2.2
16+
1,3.3,false -> 0.0
17+
""";
18+
ParseInput.from(expected).withTypes(Integer.class, Double.class, Boolean.class)
19+
.verifyAll(t -> t.getFirst() * t.getSecond() * (t.getThird() ? 1 : 0));
1820
ParseInput.from(expected).withTypes(Integer.class, Double.class, Boolean.class)
19-
.verifyAll(t -> t.getFirst() * t.getSecond() * (t.getThird() ? 1 : 0));
20-
// ParseInput.from(expected).withTypes(Integer.class, Double.class).verifyAll((i, d) -> i * d);
21-
// ParseInput.from(expected).transformTo(Integer::parseInt, Double::parseDouble)
22-
// .verifyAll(t -> t.getFirst() * t.getSecond());
23-
// ParseInput.from(expected).withTypes(Integer.class, Double.class).transformTo((i, d) -> i * d)
24-
// .verifyAll(t -> t);
21+
.verifyAll((i, d, b) -> i * d * (b ? 1 : 0));
22+
// ParseInput.from(expected).transformTo(Integer::parseInt, Double::parseDouble)
23+
// .verifyAll(t -> t.getFirst() * t.getSecond());
24+
// ParseInput.from(expected).withTypes(Integer.class, Double.class).transformTo((i, d) -> i * d)
25+
// .verifyAll(t -> t);
2526
}
2627
@Test
2728
void testPersonAge()
@@ -54,4 +55,4 @@ private Double sum(Integer[] integers)
5455
{
5556
return Queryable.of(integers).sum();
5657
}
57-
}
58+
}

approvaltests/src/main/java/org/approvaltests/utils/parseinput/ParseInput.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,12 @@ public <T1, T2> ParseInputWith2Parameters<T1, T2> transformTo(Function1<String,
9292
{
9393
return ParseInputWith2Parameters.create(expected, transformer1, transformer2, options);
9494
}
95-
public <T1, T2, T3> ParseInputWith3Parameters<T1, T2, T3> withTypes(Class<T1> type1, Class<T2> type2, Class<T3> type3) {
96-
return ParseInputWith3Parameters.create(
97-
expected,
98-
getTransformerForClass(type1),
99-
getTransformerForClass(type2),
100-
getTransformerForClass(type3),
101-
options
102-
);
95+
public <T1, T2, T3> ParseInputWith3Parameters<T1, T2, T3> withTypes(Class<T1> type1, Class<T2> type2,
96+
Class<T3> type3)
97+
{
98+
return ParseInputWith3Parameters.create(expected, getTransformerForClass(type1), getTransformerForClass(type2),
99+
getTransformerForClass(type3), options);
103100
}
104-
105101
public static class ParseInputOptions
106102
{
107103
public final boolean multiline;

approvaltests/src/main/java/org/approvaltests/utils/parseinput/ParseInputWith3Parameters.java

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,52 @@
33
import com.spun.util.Tuple;
44
import com.spun.util.Tuple3;
55
import org.lambda.functions.Function1;
6-
import org.lambda.functions.Function2;
76
import org.lambda.functions.Function3;
87
import org.lambda.query.Queryable;
98

109
public class ParseInputWith3Parameters<IN1, IN2, IN3>
1110
{
12-
private final String expected;
13-
private final Function1<String, Tuple3<IN1, IN2, IN3>> transformer;
14-
private final ParseInput.ParseInputOptions options;
15-
16-
public ParseInputWith3Parameters(String expected, Function1<String, Tuple3<IN1, IN2, IN3>> transformer,
17-
ParseInput.ParseInputOptions options)
18-
{
19-
this.expected = expected;
20-
this.transformer = transformer;
21-
this.options = options;
22-
}
23-
24-
public static <IN1, IN2, IN3> ParseInputWith3Parameters<IN1, IN2, IN3> create(String expected,
25-
Function1<String, IN1> t1, Function1<String, IN2> t2, Function1<String, IN3> t3,
26-
ParseInput.ParseInputOptions options)
27-
{
28-
Function1<String, Tuple3<IN1, IN2, IN3>> f = s -> {
29-
Queryable<String> temp = Queryable.as(s.split(",")).select(String::trim);
30-
IN1 v1 = t1.call(temp.get(0));
31-
IN2 v2 = t2.call(temp.get(1));
32-
IN3 v3 = t3.call(temp.get(2));
33-
return new Tuple3<>(v1, v2, v3);
34-
};
35-
return new ParseInputWith3Parameters<>(expected, f, options);
36-
}
37-
38-
private ParseInput<Tuple3<IN1, IN2, IN3>> getParseInput()
39-
{
40-
return new ParseInput<>(expected, s -> new Tuple<>(s, transformer.call(s)), options);
41-
}
42-
43-
// public <OUT> ParseInputWith1Parameters<OUT> transformTo(Function3<Tuple3<IN1, IN2, IN3>, OUT> transform)
44-
// {
45-
// Function1<String, OUT> f1 = (t) -> {
46-
// Tuple3<IN1, IN2, IN3> transformed = transformer.call(t);
47-
// return transform.call(transformed);
48-
// };
49-
// return new ParseInputWith1Parameters<>(expected, f1, options);
50-
// }
51-
52-
public void verifyAll(Function1<Tuple3<IN1, IN2, IN3>, Object> transform)
53-
{
54-
getParseInput().verifyAll(transform);
55-
}
11+
private final String expected;
12+
private final Function1<String, Tuple3<IN1, IN2, IN3>> transformer;
13+
private final ParseInput.ParseInputOptions options;
14+
public ParseInputWith3Parameters(String expected, Function1<String, Tuple3<IN1, IN2, IN3>> transformer,
15+
ParseInput.ParseInputOptions options)
16+
{
17+
this.expected = expected;
18+
this.transformer = transformer;
19+
this.options = options;
20+
}
21+
public static <IN1, IN2, IN3> ParseInputWith3Parameters<IN1, IN2, IN3> create(String expected,
22+
Function1<String, IN1> t1, Function1<String, IN2> t2, Function1<String, IN3> t3,
23+
ParseInput.ParseInputOptions options)
24+
{
25+
Function1<String, Tuple3<IN1, IN2, IN3>> f = s -> {
26+
Queryable<String> temp = Queryable.as(s.split(",")).select(String::trim);
27+
IN1 v1 = t1.call(temp.get(0));
28+
IN2 v2 = t2.call(temp.get(1));
29+
IN3 v3 = t3.call(temp.get(2));
30+
return new Tuple3<>(v1, v2, v3);
31+
};
32+
return new ParseInputWith3Parameters<>(expected, f, options);
33+
}
34+
private ParseInput<Tuple3<IN1, IN2, IN3>> getParseInput()
35+
{
36+
return new ParseInput<>(expected, s -> new Tuple<>(s, transformer.call(s)), options);
37+
}
38+
// public <OUT> ParseInputWith1Parameters<OUT> transformTo(Function3<Tuple3<IN1, IN2, IN3>, OUT> transform)
39+
// {
40+
// Function1<String, OUT> f1 = (t) -> {
41+
// Tuple3<IN1, IN2, IN3> transformed = transformer.call(t);
42+
// return transform.call(transformed);
43+
// };
44+
// return new ParseInputWith1Parameters<>(expected, f1, options);
45+
// }
46+
public void verifyAll(Function1<Tuple3<IN1, IN2, IN3>, Object> transform)
47+
{
48+
getParseInput().verifyAll(transform);
49+
}
50+
public void verifyAll(Function3<IN1, IN2, IN3, Object> transform)
51+
{
52+
getParseInput().verifyAll((t) -> transform.call(t.getFirst(), t.getSecond(), t.getThird()));
53+
}
5654
}

0 commit comments

Comments
 (0)