From 2a1419cb4c118607a51266c869a9cdc24cadb81d Mon Sep 17 00:00:00 2001 From: Lars Eckart Date: Mon, 26 Feb 2024 19:25:05 +0200 Subject: [PATCH] - F transformTo(A,B) --- .../src/test/java/org/approvaltests/Parse1InputTest.java | 2 ++ .../src/test/java/org/approvaltests/Parse2InputTest.java | 6 +++--- .../src/test/java/org/approvaltests/ParseInput.java | 9 +++++++++ .../org/approvaltests/ParseInputWith2Parameters.java | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/approvaltests-tests/src/test/java/org/approvaltests/Parse1InputTest.java b/approvaltests-tests/src/test/java/org/approvaltests/Parse1InputTest.java index 4522c4dc..5b3f3b7c 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/Parse1InputTest.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/Parse1InputTest.java @@ -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() diff --git a/approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java b/approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java index a586e10e..0a5651b6 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/Parse2InputTest.java @@ -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); } } diff --git a/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java b/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java index a801d5c3..d0cd28d7 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java @@ -98,6 +98,11 @@ public ParseInputWith2Parameters> withTypes(Class { return ParseInputWith2Parameters.create(expected, type1, type2); } + public ParseInputWith2Parameters> transformTo(Function1 transformer1, Function1 transformer2) + { + return ParseInputWith2Parameters.create(expected, transformer1, transformer2); + + } public ParseInput multiline() { this.multiline = true; @@ -107,4 +112,8 @@ public ParseInputWith1Parameters transformTo(Function1 t { return new ParseInputWith1Parameters<>(expected, transformer); } + public Queryable getInputs() + { + return parse().select(Tuple::getSecond); + } } diff --git a/approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java b/approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java index 01e45cfe..97a6e8c5 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/ParseInputWith2Parameters.java @@ -20,6 +20,11 @@ public static ParseInputWith2Parameters> cr { Function1 t1 = getTransformerForClass(type1); Function1 t2 = getTransformerForClass(type2); + return create(expected, t1, t2); + } + public static ParseInputWith2Parameters> create(String expected, + Function1 t1, Function1 t2) + { Function1> f = s -> { var temp = Queryable.as(s.split(",")).select(String::trim); IN1 v1 = t1.call(temp.get(0));