tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jorg...@apache.org
Subject [38/50] tinkerpop git commit: Parse maps, lists and sets
Date Thu, 23 Nov 2017 08:16:13 GMT
Parse maps, lists and sets


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

Branch: refs/heads/TINKERPOP-1827
Commit: c606903c4f1f63ac7d2c40052a7195ca18885d6d
Parents: 47402de
Author: Jorge Bay Gondra <jorgebaygondra@gmail.com>
Authored: Tue Nov 7 10:51:25 2017 +0100
Committer: Jorge Bay Gondra <jorgebaygondra@gmail.com>
Committed: Thu Nov 23 09:08:07 2017 +0100

----------------------------------------------------------------------
 .../Gherkin/CommonSteps.cs                      | 15 ++++++-----
 .../ModernGraphTypeInformation.cs               |  1 +
 .../Gherkin/TraversalEvaluation/Token.cs        |  2 +-
 .../TraversalEvaluationTests.cs                 |  8 ++++--
 .../TraversalEvaluation/TraversalParser.cs      | 27 ++++++++++++--------
 5 files changed, 33 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c606903c/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 8b27567..4a4d18e 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
@@ -31,6 +31,8 @@ using Gremlin.Net.IntegrationTest.Gherkin.Attributes;
 using Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation;
 using Gremlin.Net.Process.Traversal;
 using Gremlin.Net.Structure;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
 using Xunit;
 
 namespace Gremlin.Net.IntegrationTest.Gherkin
@@ -162,19 +164,20 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             return result;
         }
 
-        private static IDictionary ToMap(string arg)
+        private static IDictionary ToMap(string stringMap)
         {
-            throw new NotImplementedException();
+            var jsonMap = JObject.Parse(stringMap);
+            return (IDictionary) jsonMap.ToObject<IDictionary<string, object>>();
         }
 
-        private static ICollection ToSet(string arg)
+        private static ISet<object> ToSet(string stringSet)
         {
-            throw new NotImplementedException();
+            return new HashSet<object>(ToList(stringSet));
         }
 
-        private static IList ToList(string arg)
+        private static IList<object> ToList(string stringList)
         {
-            throw new NotImplementedException();
+            return stringList.Split(',').Select(ParseValue).ToArray();
         }
 
         private static Vertex ToVertex(string name)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c606903c/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 7e2bee1..10d316d 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
@@ -57,6 +57,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                     }
                     return typeof(object);
                 case nameof(GraphTraversal<object,object>.ValueMap):
+                case nameof(GraphTraversal<object,object>.Select):
                     // Use IDictionary<string, object> for value maps
                     return typeof(object);
                 case nameof(GraphTraversal<object,object>.Limit):

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c606903c/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/Token.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/Token.cs
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/Token.cs
index e0acf4b..67c2af1 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/Token.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/Token.cs
@@ -68,7 +68,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
             
         public Token(string name, IList<ITokenParameter> parameters = null)
         {
-            Name = name;
+            Name = name.Trim();
             Parameters = parameters ?? EmptyParameters;
         }
             

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c606903c/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 aaca93f..ade895c 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
@@ -60,7 +60,10 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                         new TraversalPredicateParameter(
                             new[] { new Token("P"), new Token("gt", LiteralParameter.Create(27))
}) })}),
                 Tuple.Create("g.V().count(Scope.local)", 
-                    new[] { new Token("count", new TraversalEnumParameter("Scope.local"))})
+                    new[] { new Token("count", new TraversalEnumParameter("Scope.local"))}),
+                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")}),
             };
             foreach (var item in items)
             {
@@ -82,7 +85,8 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                 Tuple.Create("g.V().where(__.in(\"created\").count().is(1)).values(\"name\")",
3),
                 Tuple.Create("g.V().count(Scope.local)", 2),
                 Tuple.Create("g.V().values(\"age\").is(P.lte(30))", 3),
-                Tuple.Create("g.V().optional(__.out().optional(__.out())).path().limit(1)",
4)
+                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)
             };
             var g = new Graph().Traversal();
             foreach (var tuple in traversalTexts)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c606903c/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 b5efb8d..1f17ec8 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
@@ -124,8 +124,14 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
             foreach (var method in ordered)
             {
                 lastMethod = method;
-                var parameters = method.GetParameters();
-                if (tokenParameters.Count < parameters.Length)
+                var methodParameters = method.GetParameters();
+                var requiredParameters = methodParameters.Length;
+                if (requiredParameters > 0 && IsParamsArray(methodParameters.Last()))
+                {
+                    // Params array can be not provided
+                    requiredParameters--;
+                }
+                if (tokenParameters.Count < requiredParameters)
                 {
                     continue;
                 }
@@ -133,13 +139,13 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                 var exactMatches = 0;
                 for (var i = 0; i < tokenParameters.Count; i++)
                 {
-                    if (parameters.Length <= i)
+                    if (methodParameters.Length <= i)
                     {
                         // The method contains less parameters (and no params array) than
provided
                         matched = false;
                         break;
                     }
-                    var methodParameter = parameters[i];
+                    var methodParameter = methodParameters[i];
                     var tokenParameterType = tokenParameters[i].GetParameterType();
                     // Match either the same parameter type
                     matched = methodParameter.ParameterType == tokenParameterType;
@@ -324,14 +330,9 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                         parameters.Add(param);
                         break;
                     }
-                    case ',' when text[i+1] != ' ':
-                    case ' ' when text[i+1] != ' ' && text[i+1] != ')':
+                    case ',' when text[i+1] != ' ' && parsing == ParsingPart.StartParameters:
+                    case ' ' when text[i+1] != ' ' && text[i+1] != ')' &&
parsing == ParsingPart.StartParameters:
                     {
-                        if (parsing != ParsingPart.StartParameters)
-                        {
-                            throw new InvalidOperationException(
-                                "Can not parse space or comma chars outside parameters");
-                        }
                         i++;
                         var param = ParseParameter(text, ref i);
                         if (param == null)
@@ -370,6 +371,10 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
         private static ITokenParameter ParseParameter(string text, ref int i)
         {
             var firstChar = text[i];
+            while (char.IsWhiteSpace(firstChar))
+            {
+                firstChar = text[++i];
+            }
             if (firstChar == ')')
             {
                 return null;


Mime
View raw message