groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] branch master updated: add test cases and other minor edits
Date Sun, 15 Dec 2019 18:46:55 GMT
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new fee93c2  add test cases and other minor edits
fee93c2 is described below

commit fee93c27c34d3200b23f3e3b306ff29fa2beb825
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Sun Dec 15 12:17:55 2019 -0600

    add test cases and other minor edits
---
 src/test/groovy/transform/stc/LambdaTest.groovy | 210 +++++++++++++-----------
 1 file changed, 110 insertions(+), 100 deletions(-)

diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy
index 9485be3..48cf528 100644
--- a/src/test/groovy/transform/stc/LambdaTest.groovy
+++ b/src/test/groovy/transform/stc/LambdaTest.groovy
@@ -165,18 +165,31 @@ final class LambdaTest {
     @Test
     void testConsumer() {
         assertScript '''
-            import groovy.transform.CompileStatic
-            import java.util.stream.Collectors
-            import java.util.stream.Stream
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static main(args) {
+                    p()
+                }
 
-            @CompileStatic
-            public class Test1 {
-                public static void main(String[] args) {
-                    p();
+                static void p() {
+                    [1, 2, 3].stream().forEach(e -> { System.out.println(e + 1); })
                 }
+            }
+        '''
+    }
 
-                public static void p() {
-                    [1, 2, 3].stream().forEach(e -> { System.out.println(e + 1); });
+    @Test @NotYetImplemented // GROOVY-9340
+    void testConsumerWithSelfType() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static main(args) {
+                    p()
+                }
+
+                static void p() {
+                    java.util.function.Consumer<Test1> c = t -> null
+                    c.accept(this.newInstance())
                 }
             }
         '''
@@ -630,103 +643,106 @@ final class LambdaTest {
     }
 
     @Test
-    void testConsumerCall() {
+    void testConsumer1() {
         assertScript '''
-            import groovy.transform.CompileStatic
-            import java.util.stream.Collectors
-            import java.util.stream.Stream
-            import java.util.function.Consumer
-
-            @CompileStatic
-            public class Test1 {
-                public static void main(String[] args) {
-                    p();
-                }
+            @groovy.transform.CompileStatic
+            void m() {
+                int a = 1
+                java.util.function.Consumer<Integer> c = i -> { a += i }
+                c.accept(2)
+                assert a == 3
+            }
+            m()
+        '''
+    }
 
-                public static void p() {
-                    int r = 1
-                    Consumer<Integer> c = (Integer e) -> { r += e }
-                    c(2)
-                    assert 3 == r
-                }
+    @Test
+    void testConsumer2() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            void m() {
+                int a = 1
+                java.util.function.Consumer<Integer> c = (i) -> { a += i }
+                c.accept(2)
+                assert a == 3
             }
+            m()
         '''
     }
 
     @Test
-    void testConsumerCallWithoutExplicitTypeDef() {
+    void testConsumer3() {
         assertScript '''
-            import groovy.transform.CompileStatic
-            import java.util.stream.Collectors
-            import java.util.stream.Stream
-            import java.util.function.Consumer
+            @groovy.transform.CompileStatic
+            void m() {
+                int a = 1
+                java.util.function.Consumer<Integer> c = (Integer i) -> { a += i
}
+                c.accept(2)
+                assert a == 3
+            }
+            m()
+        '''
+    }
 
-            @CompileStatic
-            public class Test1 {
-                public static void main(String[] args) {
-                    p();
+    @Test
+    void testConsumer4() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static main(args) {
+                    p()
                 }
 
-                public static void p() {
-                    int r = 1
-                    Consumer<Integer> c = e -> { r += e }
-                    c(2)
-                    assert 3 == r
+                static void p() {
+                    int a = 1
+                    java.util.function.Consumer<Integer> c = e -> { a += e }
+                    c.accept(2)
+                    assert a == 3
                 }
             }
         '''
     }
 
     @Test
-    void testConsumerCall2() {
+    void testConsumer5() {
         assertScript '''
-            import groovy.transform.CompileStatic
-            import java.util.stream.Collectors
-            import java.util.stream.Stream
-            import java.util.function.Consumer
-
-            @CompileStatic
-            public class Test1 {
-                public static void main(String[] args) {
-                    new Test1().p();
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static main(args) {
+                    new Test1().p()
                 }
 
-                public void p() {
-                    int r = 1
-                    Consumer<Integer> c = (Integer e) -> { r += e }
-                    c(2)
-                    assert 3 == r
+                void p() {
+                    int a = 1
+                    java.util.function.Consumer<Integer> c = (Integer e) -> { a
+= e }
+                    c.accept(2)
+                    assert a == 3
                 }
             }
         '''
     }
 
     @Test
-    void testConsumerCall3() {
+    void testConsumer6() {
         assertScript '''
-            import groovy.transform.CompileStatic
-            import java.util.stream.Collectors
-            import java.util.stream.Stream
-            import java.util.function.Consumer
-
-            @CompileStatic
-            public class Test1 {
-                public static void main(String[] args) {
-                    p();
+            @groovy.transform.CompileStatic
+            class Test1 {
+                static main(args) {
+                    p()
                 }
 
-                public static void p() {
-                    int r = 1
-                    Consumer<Integer> c = (Integer e) -> { r += e }
-                    c.accept(2)
-                    assert 3 == r
+                static void p() {
+                    int a = 1
+                    java.util.function.Consumer<Integer> c = (Integer e) -> { a
+= e }
+                    c(2)
+                    assert a == 3
                 }
             }
         '''
     }
 
     @Test
-    void testSamCall() {
+    void testFunctionalInterface1() {
         assertScript '''
             import groovy.transform.CompileStatic
             import java.util.stream.Collectors
@@ -752,7 +768,7 @@ final class LambdaTest {
     }
 
     @Test
-    void testSamCallWithoutExplicitTypeDef() {
+    void testFunctionalInterface2() {
         assertScript '''
             import groovy.transform.CompileStatic
             import java.util.stream.Collectors
@@ -778,7 +794,7 @@ final class LambdaTest {
     }
 
     @Test
-    void testSamCall2() {
+    void testFunctionalInterface3() {
         assertScript '''
             import groovy.transform.CompileStatic
             import java.util.stream.Collectors
@@ -1050,18 +1066,15 @@ final class LambdaTest {
         '''
     }
 
-    @Test @NotYetImplemented
+    @Test @NotYetImplemented // GROOVY-9342
     void testStaticInitializeBlocks2() {
         assertScript '''
             @groovy.transform.CompileStatic
             class Test1 {
-                static list
                 static int acc = 1
-                static { list = [1, 2, 3].stream().map(e -> acc += e).toList() }
+                static { [1, 2, 3].forEach(e -> acc += e) }
             }
-
-            assert [2, 4, 7] == Test1.list
-            assert 7 == Test1.acc
+            assert Test1.acc == 7
         '''
     }
 
@@ -1148,13 +1161,12 @@ final class LambdaTest {
             @groovy.transform.CompileStatic
             class Test1 {
                 def p() {
-                        def out = new ByteArrayOutputStream()
-                        out.withObjectOutputStream {
-                            SerializableFunction<Integer, String> f = ((Integer e)
-> 'a' + e)
-                            it.writeObject(f)
-                        }
-
-                        return out.toByteArray()
+                    def out = new ByteArrayOutputStream()
+                    out.withObjectOutputStream {
+                        SerializableFunction<Integer, String> f = ((Integer e) ->
'a' + e)
+                        it.writeObject(f)
+                    }
+                    return out.toByteArray()
                 }
             }
 
@@ -1170,13 +1182,12 @@ final class LambdaTest {
             @groovy.transform.CompileStatic
             class Test1 {
                 def p() {
-                        def out = new ByteArrayOutputStream()
-                        out.withObjectOutputStream {
-                            Function<Integer, String> f = ((Integer e) -> 'a' +
e)
-                            it.writeObject(f)
-                        }
-
-                        return out.toByteArray()
+                    def out = new ByteArrayOutputStream()
+                    out.withObjectOutputStream {
+                        Function<Integer, String> f = ((Integer e) -> 'a' + e)
+                        it.writeObject(f)
+                    }
+                    return out.toByteArray()
                 }
             }
 
@@ -1195,13 +1206,12 @@ final class LambdaTest {
             @groovy.transform.CompileStatic
             class Test1 {
                 byte[] p() {
-                        def out = new ByteArrayOutputStream()
-                        out.withObjectOutputStream {
-                            SerializableFunction<Integer, String> f = ((Integer e)
-> 'a' + e)
-                            it.writeObject(f)
-                        }
-
-                        return out.toByteArray()
+                    def out = new ByteArrayOutputStream()
+                    out.withObjectOutputStream {
+                        SerializableFunction<Integer, String> f = ((Integer e) ->
'a' + e)
+                        it.writeObject(f)
+                    }
+                    return out.toByteArray()
                 }
 
                 static void main(String[] args) {


Mime
View raw message