You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/12/20 06:22:41 UTC
[groovy] branch master updated: Trivial tweak `isIdentical` further
and add a test
This is an automated email from the ASF dual-hosted git repository.
sunlan 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 a3d2c77 Trivial tweak `isIdentical` further and add a test
a3d2c77 is described below
commit a3d2c77dff598a8fae19bcbae96f817cf5d35ce5
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Dec 20 14:22:02 2020 +0800
Trivial tweak `isIdentical` further and add a test
---
.../collection/runtime/QueryableHelper.groovy | 5 +--
.../collection/runtime/QueryableHelperTest.groovy | 39 ++++++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelper.groovy b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelper.groovy
index 0d09df0..5f198b6 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelper.groovy
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelper.groovy
@@ -87,7 +87,7 @@ class QueryableHelper {
def obj1Size = obj1.size()
if (obj1Size == obj2.size()) {
for (int i = 0; i < obj1Size; i++) {
- if (obj1.get(i) !== obj2.get(i)) {
+ if (!isIdentical(obj1.get(i), obj2.get(i))) {
return false
}
}
@@ -112,6 +112,7 @@ class QueryableHelper {
VAR_HOLDER.get().remove(name)
}
- private static final ThreadLocal<Map<String, Object>> VAR_HOLDER = ThreadLocal.<Map<String, Object>>withInitial(() -> new LinkedHashMap<>())
+ private static final ThreadLocal<Map<String, Object>> VAR_HOLDER = ThreadLocal.<Map<String, Object>> withInitial(() -> new LinkedHashMap<>())
+
private QueryableHelper() {}
}
diff --git a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelperTest.groovy b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelperTest.groovy
new file mode 100644
index 0000000..a8c719d
--- /dev/null
+++ b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelperTest.groovy
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.groovy.ginq.provider.collection.runtime
+
+import org.junit.Test
+
+import static org.apache.groovy.ginq.provider.collection.runtime.QueryableHelper.isIdentical
+
+class QueryableHelperTest {
+ @Test
+ void testIsIdentical() {
+ def n1 = 1
+ def n2 = 2
+ def n3 = 3
+ assert isIdentical(n1, n1)
+ assert !isIdentical(n1, new Integer(1))
+ assert !isIdentical(new Integer(1), n1)
+ assert isIdentical(new NamedTuple([n1, n2], ['n1', 'n2']), new NamedTuple([n1, n2], ['n1', 'n2']))
+ assert !isIdentical(new NamedTuple([new Integer(1), n2], ['n1', 'n2']), new NamedTuple([n1, n2], ['n1', 'n2']))
+ assert isIdentical(new NamedTuple([new NamedTuple([n1, n2], ['n1', 'n2']), n3], ['(n1, n2)', 'n3']), new NamedTuple([new NamedTuple([n1, n2], ['n1', 'n2']), n3], ['(n1, n2)', 'n3']))
+ assert !isIdentical(new NamedTuple([new NamedTuple([new Integer(1), n2], ['n1', 'n2']), n3], ['(n1, n2)', 'n3']), new NamedTuple([new NamedTuple([n1, n2], ['n1', 'n2']), n3], ['(n1, n2)', 'n3']))
+ }
+}