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: GROOVY-9317: record field expression value for assert
Date Sun, 24 Nov 2019 01:50:47 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 9d75b17  GROOVY-9317: record field expression value for assert
9d75b17 is described below

commit 9d75b171be28d3f33033ac3fa13b1296d5028cb0
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Sat Nov 23 19:50:08 2019 -0600

    GROOVY-9317: record field expression value for assert
---
 .../groovy/classgen/AsmClassGenerator.java         |  33 +--
 src/spec/test/semantics/PowerAssertTest.groovy     |  24 +-
 .../powerassert/AssertionRenderingTest.groovy      | 290 +++++++++++++--------
 .../runtime/powerassert/ValueRenderingTest.groovy  | 121 +++++----
 4 files changed, 291 insertions(+), 177 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index bcc140f..2c688f8 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -962,18 +962,17 @@ public class AsmClassGenerator extends ClassGenerator {
                             && controller.isStaticContext()) {
                         // GROOVY-6183
                         ClassNode current = classNode.getSuperClass();
-                        while (field==null && current!=null) {
+                        while (field == null && current != null) {
                             field = current.getDeclaredField(name);
                             current = current.getSuperClass();
                         }
-                        if (field!=null && (field.isProtected() || field.isPublic()))
{
+                        if (field != null && (field.isProtected() || field.isPublic()))
{
                             visitFieldExpression(new FieldExpression(field));
                             return;
                         }
                     }
                 }
-                if (field != null && !privateSuperField) {
-                    // GROOVY-4497: don't visit super field if it is private
+                if (field != null && !privateSuperField) { // GROOVY-4497: don't
visit super field if it is private
                     visitFieldExpression(new FieldExpression(field));
                     return;
                 }
@@ -1157,9 +1156,9 @@ public class AsmClassGenerator extends ClassGenerator {
             if (name != null) {
                 FieldNode field = getDeclaredFieldOfCurrentClassOrAccessibleFieldOfSuper(classNode,
classNode, name, isSuperExpression(objectExpression));
                 if (field != null) {
-                    FieldExpression exp = new FieldExpression(field);
-                    exp.setSourcePosition(expression);
-                    visitFieldExpression(exp);
+                    FieldExpression fldExp = new FieldExpression(field);
+                    fldExp.setSourcePosition(expression.getProperty());
+                    visitFieldExpression(fldExp);
                     return;
                 }
             }
@@ -1178,17 +1177,17 @@ public class AsmClassGenerator extends ClassGenerator {
             if (usesSuper(expression)) adapter = getFieldOnSuper;
         }
         visitAttributeOrProperty(expression, adapter);
-        if (!controller.getCompileStack().isLHS()) {
-            controller.getAssertionWriter().record(expression.getProperty());
-        } else {
+        if (controller.getCompileStack().isLHS()) {
             operandStack.remove(operandStack.getStackLength() - mark);
+        } else {
+            controller.getAssertionWriter().record(expression.getProperty());
         }
     }
 
     private static boolean usesSuper(PropertyExpression pe) {
-        Expression expression = pe.getObjectExpression();
-        if (expression instanceof VariableExpression) {
-            VariableExpression varExp = (VariableExpression) expression;
+        Expression objExp = pe.getObjectExpression();
+        if (objExp instanceof VariableExpression) {
+            VariableExpression varExp = (VariableExpression) objExp;
             String variable = varExp.getName();
             return variable.equals("super");
         }
@@ -1211,7 +1210,9 @@ public class AsmClassGenerator extends ClassGenerator {
                 loadInstanceField(expression);
             }
         }
-        if (controller.getCompileStack().isLHS()) controller.getAssertionWriter().record(expression);
+        if (!controller.getCompileStack().isLHS()) {
+            controller.getAssertionWriter().record(expression);
+        }
     }
 
     public void loadStaticField(FieldExpression fldExp) {
@@ -1348,7 +1349,9 @@ public class AsmClassGenerator extends ClassGenerator {
         } else {
             controller.getOperandStack().loadOrStoreVariable(variable, expression.isUseReferenceDirectly());
         }
-        if (!controller.getCompileStack().isLHS()) controller.getAssertionWriter().record(expression);
+        if (!controller.getCompileStack().isLHS()) {
+            controller.getAssertionWriter().record(expression);
+        }
     }
 
     private void loadThis(VariableExpression thisExpression) {
diff --git a/src/spec/test/semantics/PowerAssertTest.groovy b/src/spec/test/semantics/PowerAssertTest.groovy
index 5e42027..85d5b6c 100644
--- a/src/spec/test/semantics/PowerAssertTest.groovy
+++ b/src/spec/test/semantics/PowerAssertTest.groovy
@@ -18,17 +18,21 @@
  */
 package semantics
 
-import asciidoctor.Utils
-import groovy.test.GroovyTestCase
+import org.junit.Test
 
-class PowerAssertTest extends GroovyTestCase {
+import static asciidoctor.Utils.stripAsciidocMarkup
+import static groovy.test.GroovyAssert.shouldFail
+
+final class PowerAssertTest {
+
+    @Test
     void testPowerAssert() {
-        def msg = shouldFail {
+        def err = shouldFail {
             //tag::assert_code_1[]
             assert 1+1 == 3
             //end::assert_code_1[]
         }
-        assert msg == Utils.stripAsciidocMarkup('''
+        assert err.message == stripAsciidocMarkup('''
 //tag::assert_error_1[]
 assert 1+1 == 3
         |  |
@@ -37,8 +41,9 @@ assert 1+1 == 3
 ''')
     }
 
+    @Test
     void testPowerAssert2() {
-        def msg = shouldFail {
+        def err = shouldFail {
             //tag::assert_code_2[]
             def x = 2
             def y = 7
@@ -47,7 +52,7 @@ assert 1+1 == 3
             assert calc(x,y) == [x,z].sum()
             //end::assert_code_2[]
         }
-        assert msg == Utils.stripAsciidocMarkup('''
+        assert err.message == stripAsciidocMarkup('''
 //tag::assert_error_2[]
 assert calc(x,y) == [x,z].sum()
        |    | |  |   | |  |
@@ -57,8 +62,9 @@ assert calc(x,y) == [x,z].sum()
 ''')
     }
 
+    @Test
     void testCustomAssertMessage() {
-        def msg = shouldFail {
+        def err = shouldFail {
             //tag::assert_code_3[]
             def x = 2
             def y = 7
@@ -67,7 +73,7 @@ assert calc(x,y) == [x,z].sum()
             assert calc(x,y) == z*z : 'Incorrect computation result'
             //end::assert_code_3[]
         }
-        assert msg == Utils.stripAsciidocMarkup('''
+        assert err.message == stripAsciidocMarkup('''
 //tag::assert_error_3[]
 Incorrect computation result. Expression: (calc.call(x, y) == (z * z)). Values: z = 5, z
= 5
 //end::assert_error_3[]
diff --git a/src/test/org/codehaus/groovy/runtime/powerassert/AssertionRenderingTest.groovy
b/src/test/org/codehaus/groovy/runtime/powerassert/AssertionRenderingTest.groovy
index 9ce3a7c..f34d762 100644
--- a/src/test/org/codehaus/groovy/runtime/powerassert/AssertionRenderingTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/powerassert/AssertionRenderingTest.groovy
@@ -18,34 +18,42 @@
  */
 package org.codehaus.groovy.runtime.powerassert
 
-import groovy.test.GroovyTestCase
+import org.junit.Test
 
-import static AssertionTestUtil.*
 import static java.lang.Math.min
+import static org.codehaus.groovy.runtime.powerassert.AssertionTestUtil.isRendered
 
 /**
  * Tests rendering of whole assertions.
  */
+final class AssertionRenderingTest {
 
-class AssertionRenderingTest extends GroovyTestCase {
+    private one(x) { 0 }
+
+    private two(a, b) { 0 }
+
+    private three(a, b, c) { 0 }
+
+    @Test
     void testSimpleAssertion() {
-        isRendered """
+        isRendered '''
 assert x == 1
        | |
        2 false
-        """, {
+        ''', { ->
             def x = 2
             assert x == 1
         }
     }
 
+    @Test
     void testMultiLineAssertion() {
-        isRendered """
+        isRendered '''
 assert 1 + 2 == 4 - 2
          |   |    |
          3   |    2
              false
-        """, {
+        ''', { ->
             assert 1 +
                 2 ==
 
@@ -58,118 +66,125 @@ assert 1 + 2 == 4 - 2
         }
     }
 
-    private one(x) { 0 }
-
+    @Test
     void testMethodCallExpressionWithImplicitTarget() {
-        isRendered """
+        isRendered '''
 assert one(a)
        |   |
        0   1
-        """, {
+        ''', { ->
             def a = 1
             assert one(a)
         }
     }
 
+    @Test
     void testMethodCallExpressionWithExplicitTarget() {
-        isRendered """
+        isRendered '''
 assert a.get(b) == null
        | |   |  |
        | 1   0  false
        [1]
-        """, {
+        ''', { ->
             def a = [1]
             def b = 0
             assert a.get(b) == null
         }
     }
 
+    @Test
     void testMethodCallExpressionWithGStringMethod() {
-        isRendered """
+        isRendered '''
 assert [1]."\$x"(0) == null
            | |     |
            1 'get' false
-        """, {
+        ''', { ->
             def x = "get"
             assert [1]."$x"(0) == null
         }
     }
 
+    @Test
     void testMethodCallExpressionCallingStaticMethod() {
-        isRendered """
+        isRendered '''
 assert Math.max(a,b) == null
             |   | |  |
             2   1 2  false
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             assert Math.max(a,b) == null
         }
     }
 
+    @Test
     void testMethodCallExpressionSpreadDot() {
-        isRendered """
+        isRendered '''
 assert ["1", "22"]*.size() == null
                     |      |
                     [1, 2] false
-        """, {
+        ''', { ->
             assert ["1", "22"]*.size() == null
         }
     }
 
+    @Test
     void testMethodCallExpressionSafe() {
-        isRendered """
+        isRendered '''
 assert a?.foo()
        |  |
        |  null
        null
-        """, {
+        ''', { ->
             def a = null
             assert a?.foo()
         }
     }
 
+    @Test
     void testStaticMethodCallExpression() {
-        isRendered """
+        isRendered '''
 assert min(a,b) == null
        |   | |  |
        1   1 2  false
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             assert min(a,b) == null
         }
     }
 
+    @Test
     void testConstructorCallExpression() {
-        isRendered """
+        isRendered '''
 assert new ArrayList(a) == null
        |             |  |
        []            1  false
-        """, {
+        ''', { ->
             def a = 1
             assert new ArrayList(a) == null
         }
 
     }
 
+    @Test
     void testTernaryExpression() {
-        isRendered """
+        isRendered '''
 assert a ? b : c
        |   |
        1   0
-        """, {
+        ''', { ->
             def a = 1
             def b = 0
             def c = 1
             assert a ? b : c
         }
 
-        isRendered """
+        isRendered '''
 assert a ? b : c
        |       |
        0       0
-        """, {
+        ''', { ->
             def a = 0
             def b = 1
             def c = 0
@@ -177,126 +192,134 @@ assert a ? b : c
         }
     }
 
+    @Test
     void testShortTernaryExpression() {
-        isRendered """
+        isRendered '''
 assert (a ?: b) == null
         |       |
         1       false
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             assert (a ?: b) == null
         }
 
-        isRendered """
+        isRendered '''
 assert a ?: b
        |    |
        0    0
-        """, {
+        ''', { ->
             def a = 0
             def b = 0
             assert a ?: b
         }
     }
 
+    @Test
     void testBinaryExpression() {
-        isRendered """
+        isRendered '''
 assert a * b
        | | |
        0 0 1
-        """, {
+        ''', { ->
             def a = 0
             def b = 1
             assert a * b
         }
 
-        isRendered """
+        isRendered '''
 assert a[b]
        |||
        ||0
        |false
        [false]
-        """, {
+        ''', { ->
             def a = [false]
             def b = 0
             assert a[b]
         }
     }
 
+    @Test
     void testPrefixExpression() {
-        isRendered """
+        isRendered '''
 assert ++x == null
        | | |
        1 0 false
-        """, {
+        ''', { ->
             def x = 0
             assert ++x == null
         }
     }
 
+    @Test
     void testPostfixExpression() {
-        isRendered """
+        isRendered '''
 assert x++ == null
        ||  |
        |0  false
        0
-        """, {
+        ''', { ->
             def x = 0
             assert x++ == null
         }
     }
 
+    @Test
     void testBooleanExpression() {
-        isRendered """
+        isRendered '''
 assert a
        |
        null
-        """, {
+        ''', { ->
             def a = null
             assert a
         }
     }
 
+    @Test
     void testClosureExpression() {
-        isRendered """
+        isRendered '''
 assert { 1 + 2 } == null
                  |
                  false
-        """, {
+        ''', { ->
             assert { 1 + 2 } == null
         }
     }
 
+    @Test
     void testTupleExpression() {
         // TupleExpression is only used on LHS of (multi-)assignment,
         // but LHS of assignment is not rewritten
-        isRendered """
+        isRendered '''
 assert ((a,b) = [1,2]) && false
               |        |
               [1, 2]   false
-        """, {
+        ''', { ->
           def a
           def b
           assert ((a,b) = [1,2]) && false
         }
     }
 
+    @Test
     void testMapExpression() {
-        isRendered """
+        isRendered '''
 assert [a:b, c:d] == null
           |    |  |
           2    4  false
-        """, {
+        ''', { ->
             def b = 2
             def d = 4
             assert [a:b, c:d] == null
         }
 
-        isRendered """
+        isRendered '''
 assert [(a):b, (c):d] == null
         |   |  |   |  |
         1   2  3   4  false
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             def c = 3
@@ -305,12 +328,13 @@ assert [(a):b, (c):d] == null
         }
     }
 
+    @Test
     void testListExpression() {
-        isRendered """
+        isRendered '''
 assert [a,b,c] == null
         | | |  |
         1 2 3  false
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             def c = 3
@@ -318,111 +342,165 @@ assert [a,b,c] == null
         }
     }
 
+    @Test
     void testRangeExpression() {
-        isRendered """
+        isRendered '''
 assert (a..b) == null
         |  |  |
         1  2  false
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             assert (a..b) == null
         }
 
-        isRendered """
+        isRendered '''
 assert (a..<b) == null
         |   |  |
         1   2  false
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             assert (a..<b) == null
         }
     }
 
+    @Test
     void testPropertyExpression() {
-        isRendered """
+        isRendered '''
 assert a.bytes == null
        | |     |
        | [65]  false
        'A'
-
-        """, {
+        ''', { ->
             def a = 'A'
             assert a.bytes == null
         }
 
-        isRendered """
+        isRendered '''
 assert Integer.MIN_VALUE == null
                |         |
                |         false
                -2147483648
-        """, {
+        ''', { ->
             assert Integer.MIN_VALUE == null
         }
     }
 
+    @Test
     void testAttributeExpression() {
-        isRendered """
+        isRendered '''
 assert holder.@x
        |       |
        h       0
-        """, {
+        ''', { ->
             def holder = new Holder()
             assert holder.@x
         }
+
+        isRendered '''
+assert holder.@x != 0
+       |       | |
+       h       0 false
+        ''', { ->
+            def holder = new Holder()
+            assert holder.@x != 0
+        }
+
+        isRendered '''
+assert 0 != holder.@x
+         |  |       |
+         |  h       0
+         false
+        ''', { ->
+            def holder = new Holder()
+            assert 0 != holder.@x
+        }
+
+        isRendered '''
+assert this.@field == 0
+             |     |
+             1     false
+        ''', { ->
+            new Runnable() {
+                private int field = 1
+                @Override
+                public void run() {
+                    assert this.@field == 0
+                }
+            }.run()
+        }
+
+        isRendered '''
+assert 0 == this.@field
+         |        |
+         false    1
+        ''', { ->
+            new Runnable() {
+                private int field = 1
+                @Override
+                public void run() {
+                    assert 0 == this.@field
+                }
+            }.run()
+        }
     }
 
+    @Test
     void testMethodPointerExpression() {
-        isRendered """
+        isRendered '''
 assert a.&"\$b" == null
        |    |  |
        []   |  false
             'get'
-        """, {
+        ''', { ->
             def a = []
             def b = "get"
             assert a.&"$b" == null
         }
     }
 
+    @Test
     void testConstantExpression() {
-        isRendered """
+        isRendered '''
 assert 1 == "abc"
          |
          false
-        """, {
+        ''', { ->
             assert 1 == "abc"
         }
     }
 
+    @Test
     void testClassExpression() {
-        isRendered """
+        isRendered '''
 assert List == String
             |
             false
-        """, {
+        ''', { ->
             assert List == String
         }
     }
 
+    @Test
     void testVariableExpression() {
-        isRendered """
+        isRendered '''
 assert x
        |
        0
-        """, {
+        ''', { ->
             def x = 0
             assert x
         }
     }
 
+    @Test
     void testGStringExpression() {
         isRendered '''
 assert "$a and ${b + c}" == null
          |       | | |   |
          1       2 5 3   false
-        ''', {
+        ''', { ->
             def a = 1
             def b = 2
             def c = 3
@@ -430,138 +508,143 @@ assert "$a and ${b + c}" == null
         }
     }
 
+    @Test
     void testArrayExpression() {
-        isRendered """
+        isRendered '''
 assert new int[a][b] == null
                |  |  |
                1  2  false
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             assert new int[a][b] == null
         }
     }
 
-    private two(a, b) { 0 }
-
+    @Test
     void testSpreadExpression() {
-        isRendered """
+        isRendered '''
 assert two(*a)
        |    |
        0    [1, 2]
-        """, {
+        ''', { ->
             def a = [1, 2]
             assert two(*a)
         }
 
-        isRendered """
+        isRendered '''
 assert [1, *a] == null
             |  |
             |  false
             [2, 3]
-        """, {
+        ''', { ->
             def a = [2, 3]
             assert [1, *a] == null
         }
     }
 
+    @Test
     void testSpreadMapExpression() {
-        isRendered """
+        isRendered '''
 assert one(*:m)
        |     |
        0     ['a':1, 'b':2]
-        """, {
+        ''', { ->
             def m = [a:1, b:2]
             assert one(*:m)
         }
 
-        isRendered """
+        isRendered '''
 assert [a:1, *:m] == null
                |  |
                |  false
                ['b':2, 'c':3]
-        """, {
+        ''', { ->
             def m = [b:2, c:3]
             assert [a:1, *:m] == null
         }
     }
 
+    @Test
     void testNotExpression() {
-        isRendered """
+        isRendered '''
 assert !a
        ||
        |true
        false
-        """, {
+        ''', { ->
             def a = true
             assert !a
         }
     }
 
+    @Test
     void testUnaryMinusExpression() {
-        isRendered """
+        isRendered '''
 assert -a == null
        || |
        |1 false
        -1
-        """, {
+        ''', { ->
             def a = 1
             assert -a == null
         }
     }
 
+    @Test
     void testUnaryPlusExpression() {
-        isRendered """
+        isRendered '''
 assert +a == null
        || |
        |1 false
        1
-        """, {
+        ''', { ->
             def a = 1
             assert +a == null
         }
     }
 
+    @Test
     void testBitwiseNegationExpression() {
-        isRendered """
+        isRendered '''
 assert ~a == null
        || |
        |1 false
        -2
-        """, {
+        ''', { ->
             def a = 1
             assert ~a == null
         }
     }
 
+    @Test
     void testCastExpression() {
-        isRendered """
+        isRendered '''
 assert (List)a
              |
              null
-        """, {
+        ''', { ->
             def a = null
             assert (List)a
         }
 
-        isRendered """
+        isRendered '''
 assert a as int[]
        |
        null
-        """, {
+        ''', { ->
             def a = null
             assert a as int[]
         }
     }
 
-    private three(a,b,c) { 0 }
-
+    @Test
     void testArgumentListExpression() {
-        isRendered """
+        isRendered '''
 assert three(a, b,c)
        |     |  | |
        0     1  2 3
-        """, {
+        ''', { ->
             def a = 1
             def b = 2
             def c = 3
@@ -569,6 +652,7 @@ assert three(a, b,c)
         }
     }
 
+    @Test
     void testExplicitClosureCall() {
         def func = { it }
 
@@ -577,7 +661,7 @@ assert func.call(42) == null
        |    |        |
        |    42       false
        ${func.toString()}
-        """, {
+        """, { ->
             assert func.call(42) == null
         }
     }
@@ -612,5 +696,5 @@ assert func.call(42) == null
 @groovy.transform.PackageScope class Holder {
     public x = 0
     def getX() { 9 }
-    String toString() { "h" }
+    String toString() { 'h' }
 }
diff --git a/src/test/org/codehaus/groovy/runtime/powerassert/ValueRenderingTest.groovy b/src/test/org/codehaus/groovy/runtime/powerassert/ValueRenderingTest.groovy
index 3c69d96..7f08416 100644
--- a/src/test/org/codehaus/groovy/runtime/powerassert/ValueRenderingTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/powerassert/ValueRenderingTest.groovy
@@ -18,85 +18,92 @@
  */
 package org.codehaus.groovy.runtime.powerassert
 
-import groovy.test.GroovyTestCase
+import org.junit.Test
 
-import static AssertionTestUtil.*
+import static org.codehaus.groovy.runtime.powerassert.AssertionTestUtil.isRendered
 
 /**
  * Tests rendering of individual values.
  */
+final class ValueRenderingTest {
 
-class ValueRenderingTest extends GroovyTestCase {
+    @Test
     void testNullValue() {
-        isRendered """
+        isRendered '''
 assert x
        |
        null
-        """, {
+        ''', { ->
             def x = null
             assert x
         }
     }
 
+    @Test
     void testCharValue() {
-        isRendered """
+        isRendered '''
 assert x == null
        | |
        c false
-        """, {
+        ''', { ->
             def x = "c" as char
             assert x == null
         }
     }
 
+    @Test
     void testStringValue() {
-        isRendered """
+        isRendered '''
 assert x == null
        | |
        | false
        'foo'
-        """, {
+        ''', { ->
             def x = "foo"
             assert x == null
         }
     }
 
+    @Test
     void testMultiLineStringValue() {
-        isRendered """
+        isRendered '''
 assert null == x
             |  |
             |  'one\\ntwo\\rthree\\r\\nfour'
             false
-        """, {
+        ''', { ->
             def x = "one\ntwo\rthree\r\nfour"
             assert null == x
         }
     }
 
+    @Test
     void testPrimitiveArrayValue() {
-        isRendered """
+        isRendered '''
 assert x == null
        | |
        | false
        [1, 2]
-        """, {
+        ''', { ->
             def x = [1, 2] as int[]
             assert x == null
         }
     }
 
+    @Test
     void testObjectArrayValue() {
-        isRendered """
+        isRendered '''
 assert x == null
        | |
        | false
        ['one', 'two']
-        """, {
+        ''', { ->
             def x = ["one", "two"] as String[]
             assert x == null
         }
     }
 
+    @Test
     void testEmptyStringValue() {
         def x = new String()
 
@@ -105,11 +112,12 @@ assert x == null
        | |
        | false
        ''
-        ''', {
+        ''', { ->
             assert x == null
         }
     }
 
+    @Test
     void testEmptyStringBuilderValue() {
         def x = new StringBuilder()
 
@@ -118,11 +126,12 @@ assert x == null
        | |
        | false
        ""
-        ''', {
+        ''', { ->
             assert x == null
         }
     }
 
+    @Test
     void testEmptyStringBufferValue() {
         def x = new StringBuffer()
 
@@ -131,37 +140,40 @@ assert x == null
        | |
        | false
        ""
-        ''', {
+        ''', { ->
             assert x == null
         }
     }
 
+    @Test
     void testSingleLineToString() {
-        isRendered """
+        isRendered '''
 assert x == null
        | |
        | false
        single line
-        """, {
+        ''', { ->
             def x = new SingleLineToString()
             assert x == null
         }
     }
 
+    @Test
     void testMultiLineToString() {
-        isRendered """
+        isRendered '''
 assert x == null
        | |
        | false
        mul
        tiple
           lines
-        """, {
+        ''', { ->
             def x = new MultiLineToString()
             assert x == null
         }
     }
 
+    @Test
     void testNullToString() {
         def x = new NullToString()
 
@@ -170,11 +182,12 @@ assert x == null
        | |
        | false
        ${x.objectToString()} (toString() == null)
-        """, {
+        """, { ->
             assert x == null
         }
     }
 
+    @Test
     void testEmptyToString() {
         def x = new EmptyToString()
 
@@ -183,11 +196,12 @@ assert x == null
        | |
        | false
        ${x.objectToString()} (toString() == \"\")
-        """, {
+        """, { ->
             assert x == null
         }
     }
 
+    @Test
     void testThrowingToString() {
         def x = new ThrowingToString()
 
@@ -196,46 +210,53 @@ assert x == null
        | |
        | false
        ${x.objectToString()} (toString() threw java.lang.UnsupportedOperationException)
-        """, {
+        """, { ->
             assert x == null
         }
     }
-}
 
-@groovy.transform.PackageScope class SingleLineToString {
-    String toString() {
-        "single line"
-    }
-}
+    //--------------------------------------------------------------------------
 
-@groovy.transform.PackageScope class MultiLineToString {
-    String toString() {
-        "mul\ntiple\n   lines"
+    private static class SingleLineToString {
+        @Override
+        String toString() {
+            'single line'
+        }
     }
-}
 
-@groovy.transform.PackageScope class NullToString {
-    String objectToString() {
-        super.toString()
+    private static class MultiLineToString {
+        @Override
+        String toString() {
+            'mul\ntiple\n   lines'
+        }
     }
 
-    String toString() { null }
-}
+    private static class NullToString {
+        String objectToString() {
+            super.toString()
+        }
 
-@groovy.transform.PackageScope class EmptyToString {
-    String objectToString() {
-        super.toString()
+        @Override
+        String toString() { null }
     }
 
-    String toString() { "" }
-}
+    private static class EmptyToString {
+        String objectToString() {
+            super.toString()
+        }
 
-@groovy.transform.PackageScope class ThrowingToString {
-    String objectToString() {
-        super.toString()
+        @Override
+        String toString() { '' }
     }
 
-    String toString() {
-        throw new UnsupportedOperationException()
+    private static class ThrowingToString {
+        String objectToString() {
+            super.toString()
+        }
+
+        @Override
+        String toString() {
+            throw new UnsupportedOperationException()
+        }
     }
 }


Mime
View raw message