groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 01/02: GROOVY-7772: Class.&instanceMethod had better to have same meaning of Class::instanceMethod of Java8 (Add test cases - closes #287)
Date Thu, 23 May 2019 05:19:20 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit b1e1c8d975b18bfa2bf42688d45c9bb3d2a7eb1f
Author: UEHARA Junji <uehaj@jggug.org>
AuthorDate: Wed Mar 9 05:00:44 2016 +0900

    GROOVY-7772: Class.&instanceMethod had better to have same meaning of Class::instanceMethod
of Java8 (Add test cases - closes #287)
---
 src/test/groovy/bugs/MethodClosureTest.groovy | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/test/groovy/bugs/MethodClosureTest.groovy b/src/test/groovy/bugs/MethodClosureTest.groovy
index 317ef7f..1ce27fc 100644
--- a/src/test/groovy/bugs/MethodClosureTest.groovy
+++ b/src/test/groovy/bugs/MethodClosureTest.groovy
@@ -29,26 +29,41 @@ class MethodClosureTest extends GroovyTestCase {
     static bb(it) { it}
 
     void testMethodClosure() {
+        def cl2 = String.&toUpperCase // Class.instanceMethod
+        assert cl2 instanceof Closure
+        assert cl2 instanceof MethodClosure
+
+        assert ["xx", "yy"].collect(cl2) == ["XX","YY"]
+
         Class[] c1 = [ Exception.class, Throwable.class ]
         Class[] c2 = [ IllegalStateException.class ]
 
-        def cl = this.&aa
+        def cl = this.&aa // instance.instanceMethod
 
         assert cl instanceof Closure
         assert cl instanceof MethodClosure
 
         assert [c1, c2].collect(cl) == [c1,c2]
+
     }
     
     void testStaticMethodAccess() {
        def list = [1].collect (this.&bb)
        assert list == [1]
-       list = [1].collect (MethodClosureTest.&bb)
+       list = [1].collect (MethodClosureTest.&bb) // Class.staticMethod
        assert list == [1]
        def mct = new MethodClosureTest()
-       list = [1].collect (mct.&bb)
+       list = [1].collect (mct.&bb) // instance.staticMethod
        assert list == [1]
     }
-}
 
 
+    void testShellVariable() {
+        def shell = new GroovyShell()
+        assert shell.evaluate("x = String.&toUpperCase; x('abc')") == "ABC"
+        assert shell.evaluate("x = 'abc'.&toUpperCase; x()") == "ABC"
+        assert shell.evaluate("x = Integer.&parseInt; x('123')") == 123
+        assert shell.evaluate("x = 3.&parseInt; x('123')") == 123
+    }
+}
+


Mime
View raw message