tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From florianhockm...@apache.org
Subject [1/4] tinkerpop git commit: TINKERPOP-1962 GroovyTranslator handles empty maps properly now. [Forced Update!]
Date Sat, 19 May 2018 10:24:24 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1836 2fe4352ab -> 29e768dff (forced update)


TINKERPOP-1962 GroovyTranslator handles empty maps properly now.


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

Branch: refs/heads/TINKERPOP-1836
Commit: 4e8b4cff058298d0cb43be1402a14d77f22a53ac
Parents: 288b455
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed May 9 09:16:45 2018 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Sun May 13 11:24:02 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                  |  1 +
 .../gremlin/groovy/jsr223/GroovyTranslatorTest.java | 16 +++++++++++++---
 .../gremlin/groovy/jsr223/GroovyTranslator.java     |  6 +++++-
 3 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4e8b4cff/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 41d83c4..c7717d7 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-2-10]]
 === TinkerPop 3.2.10 (Release Date: NOT OFFICIALLY RELEASED YET)
 
+* Fixed bug in `GroovyTranslator` that didn't properly handle empty `Map` objects.
 
 [[release-3-2-9]]
 === TinkerPop 3.2.9 (Release Date: May 8, 2018)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4e8b4cff/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
index 08451a4..56f9699 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
@@ -38,9 +38,11 @@ import javax.script.Bindings;
 import javax.script.SimpleBindings;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.function.Function;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -119,12 +121,20 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
     @Test
     @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
     public void shouldHandleMaps() {
-        GraphTraversalSource g = graph.traversal();
-        String script = GroovyTranslator.of("g").translate(g.V().id().is(new LinkedHashMap()
{{
+        final GraphTraversalSource g = graph.traversal();
+        final String script = GroovyTranslator.of("g").translate(g.V().id().is(new LinkedHashMap<Object,Object>()
{{
             put(3, "32");
             put(Arrays.asList(1, 2, 3.1d), 4);
         }}).asAdmin().getBytecode());
-        assertEquals(script, "g.V().id().is([((int) 3):(\"32\"),([(int) 1, (int) 2, 3.1d]):((int)
4)])");
+        assertEquals("g.V().id().is([((int) 3):(\"32\"),([(int) 1, (int) 2, 3.1d]):((int)
4)])", script);
+    }
+
+    @Test
+    public void shouldHandleEmptyMaps() {
+        final Function identity = new Lambda.OneArgLambda("it.get()", "gremlin-groovy");
+        final GraphTraversalSource g = graph.traversal();
+        final String script = GroovyTranslator.of("g").translate(g.inject(Collections.emptyMap()).map(identity).asAdmin().getBytecode());
+        assertEquals("g.inject([]).map({it.get()})", script);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4e8b4cff/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
index b6410ec..6e86ce9 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
@@ -137,7 +137,11 @@ public final class GroovyTranslator implements Translator.ScriptTranslator
{
                         append(convertToString(entry.getValue())).
                         append("),");
             }
-            map.deleteCharAt(map.length() - 1);
+
+            // only need to remove this last bit if entries were added
+            if (!((Map<?, ?>) object).isEmpty())
+                map.deleteCharAt(map.length() - 1);
+
             return map.append("]").toString();
         } else if (object instanceof Long)
             return object + "L";


Mime
View raw message