groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cchamp...@apache.org
Subject [11/37] incubator-groovy git commit: more "macro" usage examples in SimpleMacroTest
Date Wed, 07 Oct 2015 19:26:31 GMT
more "macro" usage examples in SimpleMacroTest


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/01805ce6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/01805ce6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/01805ce6

Branch: refs/heads/master
Commit: 01805ce63fdc261489817fd694ec2ad6d806104c
Parents: df5fa06
Author: Sergey Egorov <bsideup@gmail.com>
Authored: Thu Jul 3 22:21:15 2014 +0300
Committer: Sergei Egorov <bsideup@gmail.com>
Committed: Mon Sep 28 14:32:05 2015 +0300

----------------------------------------------------------------------
 .../src/test/groovy/groovy/SimpleMacroTest.groovy           | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/01805ce6/subprojects/groovy-macro/src/test/groovy/groovy/SimpleMacroTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-macro/src/test/groovy/groovy/SimpleMacroTest.groovy b/subprojects/groovy-macro/src/test/groovy/groovy/SimpleMacroTest.groovy
index df46802..64bb1bf 100644
--- a/subprojects/groovy-macro/src/test/groovy/groovy/SimpleMacroTest.groovy
+++ b/subprojects/groovy-macro/src/test/groovy/groovy/SimpleMacroTest.groovy
@@ -30,6 +30,9 @@ import static org.codehaus.groovy.ast.expr.VariableExpression.*;
  */
 @CompileStatic
 class SimpleMacroTest extends GroovyShellTestCase {
+    
+    static final String TO_LOWER_CASE_METHOD_NAME = macro { "".toLowerCase() }.getMethodAsString()
+    
     public void testMethod() {
 
         def someVariable = new VariableExpression("someVariable");
@@ -65,6 +68,12 @@ class SimpleMacroTest extends GroovyShellTestCase {
 
         assertSyntaxTree(expected, result);
     }
+    
+    public void testMethodName() {
+        // Very useful when you don't want to hardcode method or variable names
+        assertEquals("toLowerCase", TO_LOWER_CASE_METHOD_NAME)
+        assertEquals("valueOf", macro { String.valueOf() }.getMethodAsString())
+    }
 
     public void testBlock() {
 


Mime
View raw message