tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jorg...@apache.org
Subject [12/18] tinkerpop git commit: Parser fixes and unordered comparison
Date Tue, 21 Nov 2017 11:06:41 GMT
Parser fixes and unordered comparison


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

Branch: refs/heads/TINKERPOP-1827
Commit: 670ec462a7d4e00ae736f085134f1698db5ba016
Parents: 51a614b
Author: Jorge Bay Gondra <jorgebaygondra@gmail.com>
Authored: Thu Nov 16 18:20:54 2017 +0100
Committer: Jorge Bay Gondra <jorgebaygondra@gmail.com>
Committed: Tue Nov 21 11:46:19 2017 +0100

----------------------------------------------------------------------
 .../Gherkin/CommonSteps.cs                      | 32 +++++++++++++++++---
 .../Gherkin/GherkinTestRunner.cs                |  6 ++--
 .../ModernGraphTypeInformation.cs               | 18 ++++++-----
 .../TraversalEvaluationTests.cs                 | 14 +++++++--
 .../TraversalEvaluation/TraversalParser.cs      |  1 +
 5 files changed, 54 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/670ec462/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
index 1ccf01d..1c2c8fa 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
@@ -151,9 +151,12 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
                     }
                     else
                     {
-                        var expectedArray = expected.OrderBy(x => x).ToArray();
-                        var resultArray = _result.OrderBy(x => x).ToArray();
-                        Assert.Equal(expectedArray, resultArray);
+                        var expectedArray = expected.ToArray();
+                        foreach (var resultItem in _result)
+                        {
+                            Assert.Contains(resultItem, expectedArray);
+                        }
+                        Assert.Equal(expectedArray.Length, _result.Length);
                     }
                     break;
                 default:
@@ -191,8 +194,27 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
 
         private static IDictionary ToMap(string stringMap, string graphName)
         {
-            var jsonMap = JObject.Parse(stringMap);
-            return (IDictionary) jsonMap.ToObject<IDictionary<string, object>>();
+            IDictionary<string, JToken> jsonMap = JObject.Parse(stringMap);
+            return jsonMap.ToDictionary(kv => kv.Key, kv => ParseMapValue(kv.Value,
graphName));
+        }
+
+        private static object ParseMapValue(JToken value, string graphName)
+        {
+            if (value.Type == JTokenType.Array)
+            {
+                return value.Select(v => ParseMapValue(v, graphName)).ToArray();
+            }
+            var objValue = value.ToObject<object>();
+            if (objValue is long longValue)
+            {
+                // JSON Numeric values converted to int64 by default
+                return Convert.ToInt32(longValue);
+            }
+            if (objValue is string stringValue)
+            {
+                return ParseValue(stringValue, graphName);
+            }
+            return objValue;
         }
 
         private static ISet<object> ToSet(string stringSet, string graphName)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/670ec462/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
index fdee536..5527705 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
@@ -22,7 +22,6 @@
 #endregion
 
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
@@ -329,7 +328,10 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             {
                 "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Sum.feature",
 //                "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Coalesce.feature",
-                "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/AddEdge.feature"
+                "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/AddEdge.feature",
+                "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/AddVertex.feature",
+                "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/ValueMap.feature",
+                "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Select.feature",
             };
 //            var files = new [] {"/Users/jorge/workspace/temp/count.feature"};
 //            var files = Directory.GetFiles(path, "*.feature", SearchOption.AllDirectories);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/670ec462/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
index a467519..f96b9bf 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
@@ -41,12 +41,13 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
         };
         
         /// <summary>
-        /// Gets the type argument information based on the modern graph.
+        /// Gets the type argument information based on the modern graph information.
         /// </summary>s
         public static Type GetTypeArguments(MethodInfo method, object[] parameterValues,
int genericTypeIndex)
         {
             switch (method.Name)
             {
+                case nameof(GraphTraversal<object,object>.Properties):
                 case nameof(GraphTraversal<object,object>.Values) when parameterValues.Length
== 1:
                     // The parameter contains the element property names
                     var properties = ((IEnumerable) parameterValues[parameterValues.Length
- 1]).Cast<string>();
@@ -59,18 +60,21 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                 case nameof(GraphTraversal<object,object>.Group) when genericTypeIndex
== 0:
                     // Use IDictionary<string, object> for Group
                     return typeof(string);
-                case nameof(GraphTraversal<object,object>.ValueMap):
-                case nameof(GraphTraversal<object,object>.Select):
-                case nameof(GraphTraversal<object,object>.Group):
-                case nameof(GraphTraversal<object,object>.Unfold):
-                    // default to object for this methods
-                    return typeof(object);
                 case nameof(GraphTraversal<object,object>.Limit):
                 case nameof(GraphTraversal<object,object>.Optional):
                 case nameof(GraphTraversal<object,object>.Sum):
                 case nameof(GraphTraversal<object,object>.Coalesce):
                     // Maintain the same type
                     return method.DeclaringType.GetGenericArguments()[1];
+                case nameof(GraphTraversal<object,object>.ValueMap):
+                case nameof(GraphTraversal<object,object>.Select):
+                case nameof(GraphTraversal<object,object>.Group):
+                case nameof(GraphTraversal<object,object>.GroupCount):
+                case nameof(GraphTraversal<object,object>.Unfold):
+                case nameof(GraphTraversal<object,object>.Choose):
+                case nameof(GraphTraversal<object,object>.Union):
+                    // default to object for this methods
+                    return typeof(object);
             }
             return null;
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/670ec462/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
index a2dd888..3907dd2 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
@@ -23,10 +23,8 @@
 
 using System;
 using System.Linq;
-using Gremlin.Net.Process.Traversal;
 using Gremlin.Net.Structure;
 using Xunit;
-using Xunit.Abstractions;
 
 namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
 {
@@ -64,6 +62,14 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                 Tuple.Create("g.V().\n  count()", new[] { new Token("count")}),
                 Tuple.Create("g.V().\n has ( \"a\" ) \n.  \ncount()",
                     new[] {new Token("has", new StringParameter("a")), new Token("count")}),
+                Tuple.Create("g.V().choose(__.outE(),__.as(\"a\"))", new []
+                {
+                    new Token("choose", new ITokenParameter[] { 
+                        new StaticTraversalParameter(new[] {new Token("__"), new Token("outE")},
"__.outE()"),
+                        new StaticTraversalParameter(
+                            new[] {new Token("__"), new Token("as", new StringParameter("a"))},
"__.as(\"a\")")
+                    })
+                })
             };
             foreach (var item in items)
             {
@@ -88,7 +94,9 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                 Tuple.Create("g.V().optional(__.out().optional(__.out())).path().limit(1)",
4),
                 Tuple.Create("g.V(1).as(\"a\").out(\"knows\").as(\"b\").\n  select(\"a\",
\"b\").by(\"name\")", 6),
                 Tuple.Create(
-                    "g.V().hasLabel(\"software\").group().by(\"name\").by(__.bothE().values(\"weight\").sum())",
5)
+                    "g.V().hasLabel(\"software\").group().by(\"name\").by(__.bothE().values(\"weight\").sum())",
5),
+                Tuple.Create("g.V().choose(__.outE().count().is(0L),__.as(\"a\"),__.as(\"b\"))"
+
+                                  "\n.choose(__.select(\"a\"),__.select(\"a\"),__.select(\"b\"))",
3)
             };
             var g = new Graph().Traversal();
             foreach (var tuple in traversalTexts)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/670ec462/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
index d557c49..66aae70 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
@@ -346,6 +346,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                         parameters.Add(param);
                         break;
                     }
+                    case ',' when parsing != ParsingPart.StartParameters:
                     case ')' when parsing != ParsingPart.StartParameters:
                         // The current nested object already ended
                         if (parsing == ParsingPart.Name)


Mime
View raw message