From be31aa7c347c588f43e263f9b23952f8431e50e0 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Sat, 12 Aug 2023 10:28:07 -0600 Subject: [PATCH] Tests: Add parse test for Java 11 lambda parameter type inference, #53 Just like regular type inference for Java 10, we already accidentally supported this since `var` is the same in both languages. In this case, we cannot make this a full integration test due to some issues noted in the test file comments. --- JavaToCSharp.Tests/IntegrationTests.cs | 1 + .../Resources/Java11LambdaInference.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 JavaToCSharp.Tests/Resources/Java11LambdaInference.java diff --git a/JavaToCSharp.Tests/IntegrationTests.cs b/JavaToCSharp.Tests/IntegrationTests.cs index 817900bb..fc117007 100644 --- a/JavaToCSharp.Tests/IntegrationTests.cs +++ b/JavaToCSharp.Tests/IntegrationTests.cs @@ -18,6 +18,7 @@ public class IntegrationTests [InlineData("Resources/SimilarityBase.java")] [InlineData("Resources/TestNumericDocValuesUpdates.java")] [InlineData("Resources/Java9DiamondOperatorInnerClass.java")] + [InlineData("Resources/Java11LambdaInference.java")] public void GeneralSuccessfulConversionTest(string filePath) { var options = new JavaConversionOptions diff --git a/JavaToCSharp.Tests/Resources/Java11LambdaInference.java b/JavaToCSharp.Tests/Resources/Java11LambdaInference.java new file mode 100644 index 00000000..779ab2f2 --- /dev/null +++ b/JavaToCSharp.Tests/Resources/Java11LambdaInference.java @@ -0,0 +1,14 @@ +// NOTE: this is currently just a successfully-parses test. It does handle `var` successfully through to the C# code, +// but the `import`, `BiFunction`, and `.apply` calls are not successfully translated. Some additional options in the +// conversion process such as skipping incoming imports, BiFunction -> Func, and somehow converting `.Apply` to +// `.Invoke` (without being a global always-on translation) would make this work in the full integration test. +package example; + +import java.util.function.BiFunction; + +public class Java11LambdaParameterTypeInference { + public static void main(String[] args) { + BiFunction add = (var a, var b) -> a + b; + System.out.println(add.apply(1, 2)); + } +}