You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by cc...@apache.org on 2015/10/07 21:26:27 UTC

[07/37] incubator-groovy git commit: more "macro" usage examples in SimpleMacroTest

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/ff1d4a0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/ff1d4a0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/ff1d4a0e

Branch: refs/heads/master
Commit: ff1d4a0e73fb724816d9b9bf07e585888c42c7ba
Parents: 546868a
Author: Sergey Egorov <bs...@gmail.com>
Authored: Thu Jul 3 22:21:15 2014 +0300
Committer: Sergei Egorov <bs...@gmail.com>
Committed: Mon Sep 28 14:32:04 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/ff1d4a0e/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() {