From 77173380ceb49258c29888b52dfe790ee749784c Mon Sep 17 00:00:00 2001 From: Lars Eckart Date: Mon, 26 Feb 2024 20:11:28 +0200 Subject: [PATCH] . r Parse2Inputs to always return a tuple --- .../org/approvaltests/Parse2InputTest.java | 13 +++++++++ .../java/org/approvaltests/ParseInput.java | 4 +-- .../ParseInputWith2Parameters.java | 27 ++++++++++--------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java b/approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java index 0a5651b6..ef4fd374 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java @@ -12,7 +12,20 @@ void testWithTypesTransformersAndBoth() 1,3.3 -> 3.3 """; ParseInput.from(expected).withTypes(Integer.class, Double.class).verifyAll(t -> t.getFirst() * t.getSecond()); + ParseInput.from(expected).withTypes(Integer.class, Double.class).verifyAll((i,d) -> i * d); 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); } diff --git a/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java b/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java index b5d1a999..54f4f50a 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java @@ -96,12 +96,12 @@ public void verifyAll(Function1 transform) Approvals.verifyAll("", parse(), s -> print(s.getFirst(), transform.call(s.getSecond())), new Options().inline(expected)); } - public ParseInputWith2Parameters> withTypes(Class type1, Class type2) + public ParseInputWith2Parameters withTypes(Class type1, Class type2) { return ParseInputWith2Parameters.create(expected, getTransformerForClass(type1), getTransformerForClass(type2)); } - public ParseInputWith2Parameters> transformTo(Function1 transformer1, + public ParseInputWith2Parameters transformTo(Function1 transformer1, Function1 transformer2) { return ParseInputWith2Parameters.create(expected, transformer1, transformer2); diff --git a/approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java b/approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java index ce4590f0..55300502 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java @@ -2,19 +2,19 @@ import com.spun.util.Tuple; import org.lambda.functions.Function1; +import org.lambda.functions.Function2; import org.lambda.query.Queryable; -public class ParseInputWith2Parameters +public class ParseInputWith2Parameters { private final String expected; - private final Function1 transformer; - public ParseInputWith2Parameters(String expected, Function1 transformer) + private final Function1> transformer; + public ParseInputWith2Parameters(String expected, Function1> transformer) { this.expected = expected; this.transformer = transformer; } - - public static ParseInputWith2Parameters> create(String expected, + public static ParseInputWith2Parameters create(String expected, Function1 t1, Function1 t2) { Function1> f = s -> { @@ -25,13 +25,16 @@ public static ParseInputWith2Parameters> cr }; return new ParseInputWith2Parameters<>(expected, f); } - // public ParseInputWith2Parameters transformTo(Function1 transformer1) - // { - // Function1 transformer2 = (String t) -> transformer1.call(transformer.call(t)); - // return new ParseInputWith2Parameters<>(expected, transformer2); - // } - public void verifyAll(Function1 transform) + public void verifyAll(Function1, Object> transform) + { + getParseInput().verifyAll(transform); + } + public void verifyAll(Function2 transform) + { + getParseInput().verifyAll((t) -> transform.call(t.getFirst(), t.getSecond())); + } + private ParseInput> getParseInput() { - new ParseInput(expected, s -> new Tuple<>(s, transformer.call(s))).verifyAll(transform); + return new ParseInput<>(expected, s -> new Tuple<>(s, transformer.call(s))); } }