groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: GROOVY-8200 - Shorthand |= results in NPE (closes #555)
Date Sun, 24 Sep 2017 10:12:31 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 63d18cc95 -> a8470e316


GROOVY-8200 - Shorthand |= results in NPE (closes #555)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: a8470e3168bafc86f963821c12a70f99a847081d
Parents: 63d18cc
Author: noamt <noam@10ne.org>
Authored: Wed May 31 20:57:04 2017 +0200
Committer: paulk <paulk@asert.com.au>
Committed: Sun Sep 24 20:12:18 2017 +1000

----------------------------------------------------------------------
 .../groovy/runtime/DefaultGroovyMethods.java    |  8 ++--
 src/spec/test/OperatorsTest.groovy              | 44 +++++++++++++++++++-
 .../runtime/DefaultGroovyMethodsTest.groovy     | 36 ++++++++++++++++
 3 files changed, 83 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a8470e31/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index a96c524..9e3c6f6 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -15842,7 +15842,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
      * @since 1.0
      */
     public static Boolean and(Boolean left, Boolean right) {
-        return left && right;
+        return left && Boolean.TRUE.equals(right);
     }
 
     /**
@@ -15854,7 +15854,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
      * @since 1.0
      */
     public static Boolean or(Boolean left, Boolean right) {
-        return left || right;
+        return left || Boolean.TRUE.equals(right);
     }
 
     /**
@@ -15866,7 +15866,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
      * @since 1.8.3
      */
     public static Boolean implies(Boolean left, Boolean right) {
-        return !left || right;
+        return !left || Boolean.TRUE.equals(right);
     }
 
     /**
@@ -15878,7 +15878,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
      * @since 1.0
      */
     public static Boolean xor(Boolean left, Boolean right) {
-        return left ^ right;
+        return left ^ Boolean.TRUE.equals(right);
     }
 
 //    public static Boolean negate(Boolean left) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/a8470e31/src/spec/test/OperatorsTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/OperatorsTest.groovy b/src/spec/test/OperatorsTest.groovy
index a0eddf3..46b87f7 100644
--- a/src/spec/test/OperatorsTest.groovy
+++ b/src/spec/test/OperatorsTest.groovy
@@ -607,4 +607,46 @@ assert (b1 + 11).size == 15
             assert str1 == str2
             '''
     }
-}
+
+    void testBooleanOr() {
+        assertScript '''
+boolean trueValue1 = true, trueValue2 = true, trueValue3 = true
+boolean falseValue1 = false, falseValue2 = false, falseValue3 = false
+
+assert (trueValue1 |= true)
+assert (trueValue2 |= false)
+assert (trueValue3 |= null)
+assert (falseValue1 |= true)
+assert !(falseValue2 |= false)
+assert !(falseValue3 |= null)
+'''
+    }
+
+    void testBooleanAnd() {
+        assertScript '''
+boolean trueValue1 = true, trueValue2 = true, trueValue3 = true
+boolean falseValue1 = false, falseValue2 = false, falseValue3 = false
+
+assert (trueValue1 &= true)
+assert !(trueValue2 &= false)
+assert !(trueValue3 &= null)
+assert !(falseValue1 &= true)
+assert !(falseValue2 &= false)
+assert !(falseValue3 &= null)
+'''
+    }
+
+    void testBooleanXor() {
+        assertScript '''
+boolean trueValue1 = true, trueValue2 = true, trueValue3 = true
+boolean falseValue1 = false, falseValue2 = false, falseValue3 = false
+
+assert !(trueValue1 ^= true)
+assert (trueValue2 ^= false)
+assert (trueValue3 ^= null)
+assert (falseValue1 ^= true)
+assert !(falseValue2 ^= false)
+assert !(falseValue3 ^= null)
+'''
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/groovy/blob/a8470e31/src/test/org/codehaus/groovy/runtime/DefaultGroovyMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/DefaultGroovyMethodsTest.groovy b/src/test/org/codehaus/groovy/runtime/DefaultGroovyMethodsTest.groovy
index 85cd65b..2c1c0d7 100644
--- a/src/test/org/codehaus/groovy/runtime/DefaultGroovyMethodsTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/DefaultGroovyMethodsTest.groovy
@@ -279,4 +279,40 @@ public class DefaultGroovyMethodsTest extends GroovyTestCase {
             delegate.iterator()
         }
     }
+
+    public void testBooleanOr() {
+        assertTrue(DefaultGroovyMethods.or(true, true))
+        assertTrue(DefaultGroovyMethods.or(true, false))
+        assertTrue(DefaultGroovyMethods.or(false, true))
+        assertFalse(DefaultGroovyMethods.or(false, false))
+        assertFalse(DefaultGroovyMethods.or(false, null))
+        assertTrue(DefaultGroovyMethods.or(true, null))
+    }
+
+    public void testBooleanAnd() {
+        assertTrue(DefaultGroovyMethods.and(true, true))
+        assertFalse(DefaultGroovyMethods.and(true, false))
+        assertFalse(DefaultGroovyMethods.and(false, true))
+        assertFalse(DefaultGroovyMethods.and(false, false))
+        assertFalse(DefaultGroovyMethods.and(false, null))
+        assertFalse(DefaultGroovyMethods.and(true, null))
+    }
+
+    public void testBooleanXor() {
+        assertFalse(DefaultGroovyMethods.xor(true, true))
+        assertTrue(DefaultGroovyMethods.xor(true, false))
+        assertTrue(DefaultGroovyMethods.xor(false, true))
+        assertFalse(DefaultGroovyMethods.xor(false, false))
+        assertFalse(DefaultGroovyMethods.xor(false, null))
+        assertTrue(DefaultGroovyMethods.xor(true, null))
+    }
+
+    public void testBooleanImplication() {
+        assertTrue(DefaultGroovyMethods.implies(true, true))
+        assertFalse(DefaultGroovyMethods.implies(true, false))
+        assertTrue(DefaultGroovyMethods.implies(false, true))
+        assertTrue(DefaultGroovyMethods.implies(false, false))
+        assertTrue(DefaultGroovyMethods.implies(false, null))
+        assertFalse(DefaultGroovyMethods.implies(true, null))
+    }
 }


Mime
View raw message