tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject tinkerpop git commit: TINKERPOP-1962 GroovyTranslator handles empty maps properly now.
Date Wed, 09 May 2018 13:17:37 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1962 [created] eab48e405


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

Branch: refs/heads/TINKERPOP-1962
Commit: eab48e40560c5ac556619691fca6ac8efe77dd03
Parents: 2f8f74a
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed May 9 09:16:45 2018 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed May 9 09:16:45 2018 -0400

----------------------------------------------------------------------
 .../gremlin/groovy/jsr223/GroovyTranslatorTest.java | 16 +++++++++++++---
 .../gremlin/groovy/jsr223/GroovyTranslator.java     |  6 +++++-
 2 files changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/eab48e40/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/eab48e40/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