You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/03/03 13:24:52 UTC

[1/2] groovy git commit: GROOVY-7530 and GROOVY-7602: intersect and disjoint broken for non-Comparable objects (closes #276)

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 730df4f1f -> bf1a2386c


GROOVY-7530 and GROOVY-7602: intersect and disjoint broken for non-Comparable objects (closes #276)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: f4c49d1b1aef94f3b436d5c78938dc3a14679c98
Parents: 730df4f
Author: paulk <pa...@asert.com.au>
Authored: Wed Mar 2 21:37:07 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Mar 3 22:16:06 2016 +1000

----------------------------------------------------------------------
 .../groovy/runtime/NumberAwareComparator.java   |  1 +
 src/test/groovy/GroovyMethodsTest.groovy        | 49 ++++++++++++++++++++
 2 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f4c49d1b/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java b/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java
index 1d780af..c85cd04 100644
--- a/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java
+++ b/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java
@@ -48,6 +48,7 @@ public class NumberAwareComparator<T> implements Comparator<T> {
         // may mean the removal of x or y in a sorting operation, which we don't want.
         int x1 = o1.hashCode();
         int x2 = o2.hashCode();
+        if (x1 == x2 && o1.equals(o2)) return 0;
         if (x1 > x2) return 1;
         return -1;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/f4c49d1b/src/test/groovy/GroovyMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/GroovyMethodsTest.groovy b/src/test/groovy/GroovyMethodsTest.groovy
index b32db93..1e16f93 100644
--- a/src/test/groovy/GroovyMethodsTest.groovy
+++ b/src/test/groovy/GroovyMethodsTest.groovy
@@ -1564,6 +1564,55 @@ class GroovyMethodsTest extends GroovyTestCase {
         assert [4, 5] == iterableA.intersect(iterableB)
     }
 
+    // GROOVY-7602
+    void testIntersectForMaps() {
+        def list1 = [[language: 'Java'], [language: 'Groovy'], [language: 'Scala']]
+        def list2 = [[language: 'Groovy'], [language: 'JRuby'], [language: 'Java']]
+        def intersection = list1.intersect(list2)
+        assert intersection == [[language: 'Groovy'], [language: 'Java']]
+    }
+
+    // GROOVY-7602
+    void testIntersectForURL() {
+        def c1 = []
+        def c2 = []
+        c1 << new URL("http://sample.com/")
+        c2 << new URL("http://sample.com/")
+        assert c1.intersect(c2)
+    }
+
+    // GROOVY-7530
+    void testDisjointForMaps() {
+        def list1 = [[language: 'Java'], [language: 'Groovy'], [language: 'Scala']]
+        def list2 = [[language: 'Groovy'], [language: 'JRuby'], [language: 'Java']]
+        assert !list1.disjoint(list2)
+    }
+
+    class Foo {
+        private String name
+
+        Foo(String name) {
+            this.name = name
+        }
+
+        boolean equals(Object o) {
+            if (this.is(o)) return true
+            if (o == null || getClass() != o.getClass()) return false
+            name == o.name
+        }
+
+        int hashCode() {
+            return 13 + 7 * name.hashCode()
+        }
+    }
+
+    // GROOVY-7530
+    void testDisjointForFoo() {
+        def a = [new Foo("foo")]
+        def b = [new Foo("foo")]
+        assert !a.disjoint(b)
+    }
+
     void testDisjointForLists() {
         assert [].disjoint([])
         assert [].disjoint([4, 5, 6, 7, 8])


[2/2] groovy git commit: GROOVY-7775: JavadocAssertionTestBuilder should handle escapes needed for HTML within javadoc, e.g. @ for @ and {@code ...}

Posted by pa...@apache.org.
GROOVY-7775: JavadocAssertionTestBuilder should handle escapes needed for HTML within javadoc, e.g. &#64; for @ and {@code ...}


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

Branch: refs/heads/GROOVY_2_4_X
Commit: bf1a2386c587c2ade7f56fe325b928bd767f56ad
Parents: f4c49d1
Author: paulk <pa...@asert.com.au>
Authored: Thu Mar 3 22:23:32 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Mar 3 22:24:23 2016 +1000

----------------------------------------------------------------------
 src/main/groovy/transform/AnnotationCollector.java    | 14 ++++++++------
 .../groovy/util/JavadocAssertionTestBuilder.groovy    |  7 ++++---
 2 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/bf1a2386/src/main/groovy/transform/AnnotationCollector.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/AnnotationCollector.java b/src/main/groovy/transform/AnnotationCollector.java
index 89b3014..f6be712 100644
--- a/src/main/groovy/transform/AnnotationCollector.java
+++ b/src/main/groovy/transform/AnnotationCollector.java
@@ -34,7 +34,7 @@ import java.lang.annotation.Target;
  * arguments and error will be given. Is this not wished or if you want a 
  * different mapping a custom processor has to be used. There are two ways of 
  * using the alias. The first way is by providing the annotations as list/array:
- * <pre>
+ * <pre class="groovyTestCase">
  *          import groovy.transform.*
  *          &#64;AnnotationCollector([ToString, EqualsAndHashCode, Immutable])
  *          &#64;interface Alias {}
@@ -50,7 +50,7 @@ import java.lang.annotation.Target;
  * excludes which will be mapped to ToString and EqualsAndHashCode. Immutable 
  * doesn't have excludes, thus nothing will be done there.<br>
  * The other way is to add annotations to the alias:
- * <pre>
+ * <pre class="groovyTestCase">
  * import groovy.transform.*
  * &#64;ToString(excludes=["a"])
  * &#64;EqualsAndHashCode
@@ -74,8 +74,9 @@ import java.lang.annotation.Target;
  * If both ways are combined, then the list overwrites annotation usage.
  * NOTE: The aliasing does not support aliasing of aliased annotations. 
  * <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
  * //--------------------------------------------------------------------------
+ * import groovy.transform.*
  * &#64;AnnotationCollector([EqualsAndHashCode, ToString])
  * &#64;interface Simple {}
  *
@@ -95,7 +96,7 @@ import java.lang.annotation.Target;
  *
  * // We can use the attributes from the 
  * // grouped annotations.
- * &#64;Simple(excludes = 'street') 
+ * &#64;Simple(excludes = 'street')
  * class Address {
  *     String street, town
  * }
@@ -103,7 +104,7 @@ import java.lang.annotation.Target;
  * def address = new Address(street: 'Evergreen Terrace', town: 'Springfield') 
  * assert address.toString() == 'Address(Springfield)'
  * </pre>
- * <pre>
+ * <pre class="groovyTestCase">
  * //--------------------------------------------------------------------------
  * // Use a custom processor to handle attributes.
  * import org.codehaus.groovy.transform.*
@@ -149,10 +150,11 @@ import java.lang.annotation.Target;
  * assert user.toString() == 'User(mrhaki)'
  * '''
  * </pre>
- * <pre>
+ * <pre class="groovyTestCase">
  * //--------------------------------------------------------------------------
  * // Use AnnotationCollector as last annotation to group the
  * // previous annotations.
+ * import groovy.transform.*
  * &#64;EqualsAndHashCode
  * &#64;ToString
  * &#64;AnnotationCollector

http://git-wip-us.apache.org/repos/asf/groovy/blob/bf1a2386/subprojects/groovy-test/src/main/groovy/groovy/util/JavadocAssertionTestBuilder.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-test/src/main/groovy/groovy/util/JavadocAssertionTestBuilder.groovy b/subprojects/groovy-test/src/main/groovy/groovy/util/JavadocAssertionTestBuilder.groovy
index c77f1cf..176afcc 100644
--- a/subprojects/groovy-test/src/main/groovy/groovy/util/JavadocAssertionTestBuilder.groovy
+++ b/subprojects/groovy-test/src/main/groovy/groovy/util/JavadocAssertionTestBuilder.groovy
@@ -28,8 +28,8 @@ import java.util.regex.Pattern
  *
  * @author Merlyn Albery-Speyer
  */
-
 class JavadocAssertionTestBuilder {
+    // TODO write tests for this classes functionality
     private static final Pattern javadocPattern =
         Pattern.compile( /(?ims)\/\*\*.*?\*\// )
     private static final Pattern assertionPattern =
@@ -92,10 +92,11 @@ class JavadocAssertionTestBuilder {
         String htmlAssertion = tagInner.replaceAll("(?m)^\\s*\\*", "")
         String assertion = htmlAssertion
         // TODO improve on this
-        [nbsp:' ', gt:'>', lt:'<', quot:'"', apos:"'", at:'@', ndash:'-', amp:'&'].each { key, value ->
+        [nbsp:' ', gt:'>', lt:'<', quot:'"', apos:"'", at:'@', '#64':'@', ndash:'-', amp:'&'].each { key, value ->
             assertion = assertion.replaceAll("(?i)&$key;", value)
         }
-        
+        assertion = assertion.replaceAll(/(?i)\{@code ([^}]*)\}/, '$1')
+
         return assertion
     }