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:03 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 7c74ff621 -> ef4e30aa7


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

Branch: refs/heads/GROOVY_2_6_X
Commit: ef4e30aa7c7e9966d3fb57f6dd99a14521e6cc8a
Parents: 7c74ff6
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:11:51 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/ef4e30aa/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 f9e7bb6..e77ddb2 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -15929,7 +15929,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);
     }
 
     /**
@@ -15941,7 +15941,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);
     }
 
     /**
@@ -15953,7 +15953,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);
     }
 
     /**
@@ -15965,7 +15965,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/ef4e30aa/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/ef4e30aa/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