changeset 52626:203842868220 concise-method-declarations

adding more smoke tests
author vromero
date Thu, 27 Sep 2018 10:25:27 -0700
parents 839a4787b5be
children ee90c2676409
files test/langtools/tools/javac/concise_methods/ConciseMethodsNegTest01.java test/langtools/tools/javac/concise_methods/ConciseMethodsNegTest01.out test/langtools/tools/javac/concise_methods/ConciseMethodsPosTest01.java
diffstat 3 files changed, 58 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/concise_methods/ConciseMethodsNegTest01.java	Thu Sep 27 10:25:27 2018 -0700
@@ -0,0 +1,9 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary smoke test for the concise method feature
+ * @compile/fail/ref=ConciseMethodsNegTest01.out -XDrawDiagnostics ConciseMethodsNegTest01.java
+ */
+
+class ConciseMethodsNegTest01 {
+    int length(String s) = s::length;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/concise_methods/ConciseMethodsNegTest01.out	Thu Sep 27 10:25:27 2018 -0700
@@ -0,0 +1,2 @@
+ConciseMethodsNegTest01.java:8:28: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, length, compiler.misc.no.args, java.lang.String, kindname.class, java.lang.String, (compiler.misc.arg.length.mismatch)))
+1 error
--- a/test/langtools/tools/javac/concise_methods/ConciseMethodsPosTest01.java	Thu Sep 27 08:37:15 2018 -0700
+++ b/test/langtools/tools/javac/concise_methods/ConciseMethodsPosTest01.java	Thu Sep 27 10:25:27 2018 -0700
@@ -24,10 +24,55 @@
 /*
  * @test
  * @summary smoke test for concise methods
- * @compile ConciseMethodsPosTest01.java
+ * @modules jdk.compiler/com.sun.tools.javac.util
  */
 
-class ConciseMethodsPosTest01 {
+import com.sun.tools.javac.util.Assert;
+
+public class ConciseMethodsPosTest01 {
+    String hello = "hello";
+
     int length(String s) -> s.length();
     void printLength(String s) -> System.out.println(s.length());
+
+    int length2(String s) = String::length;
+
+    String dowahoo(int x) = this::wahoo;
+
+    String wahoo(int x) {
+        return "wahoo " + x;
+    }
+
+    static ConciseMethodsPosTest01 make() = ConciseMethodsPosTest01::new;
+
+    class TT {
+        int i;
+        public TT(int i) {
+            this.i = i;
+        }
+    }
+
+    TT makeTT(int i) = TT::new;
+
+    int[] intArray(int i) = int[]::new;
+
+    public static void main(String... args) {
+        ConciseMethodsPosTest01 t = new ConciseMethodsPosTest01();
+        Assert.check(t.length("hey") == 3);
+        Assert.check(t.length2("hey") == 3);
+
+        Assert.check(t.dowahoo(1).equals("wahoo 1"));
+
+        ConciseMethodsPosTest01 t2 = ConciseMethodsPosTest01.make();
+        Assert.check(t2.hello.equals("hello"));
+
+        TT tt = t.makeTT(5);
+        Assert.check(tt.i == 5);
+
+        int[] arr = t.intArray(2);
+        for (int i = 0; i < 2; i++) {
+            arr[i] = i;
+            Assert.check(arr[i] == i);
+        }
+    }
 }