You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by jo...@apache.org on 2017/11/23 08:16:18 UTC

[43/50] tinkerpop git commit: Parse numeric values with suffix

Parse numeric values with suffix


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

Branch: refs/heads/TINKERPOP-1827
Commit: f6cddd2877f1029206c20d9305bc7b921fa198ab
Parents: 7980c78
Author: Jorge Bay Gondra <jo...@gmail.com>
Authored: Fri Nov 17 15:48:16 2017 +0100
Committer: Jorge Bay Gondra <jo...@gmail.com>
Committed: Thu Nov 23 09:08:08 2017 +0100

----------------------------------------------------------------------
 .../Gherkin/CommonSteps.cs                      | 32 +++++++++++++++++---
 .../Gherkin/GherkinTestRunner.cs                | 25 +++++----------
 .../ModernGraphTypeInformation.cs               |  3 +-
 3 files changed, 36 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f6cddd28/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 4b99fd8..9bc36a6 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
@@ -47,8 +47,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         private static readonly IDictionary<Regex, Func<string, string, object>> Parsers =
             new Dictionary<string, Func<string, string, object>>
             {
-                {@"d\[(\d+)\]", (x, _) => Convert.ToInt32(x)},
-                {@"d\[(\d+(?:\.\d+)?)\]", (x, _) => Convert.ToDouble(x)},
+                {@"d\[([\d.]+)\]\.([ilfd])", ToNumber},
                 {@"v\[(.+)\]", ToVertex},
                 {@"v\[(.+)\]\.id", (x, graphName) => ToVertex(x, graphName).Id},
                 {@"v\[(.+)\]\.sid", (x, graphName) => ToVertex(x, graphName).Id.ToString()},
@@ -62,6 +61,15 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
                 {@"c\[(.+)\]", ToLambda}
             }.ToDictionary(kv => new Regex("^" + kv.Key + "$", RegexOptions.Compiled), kv => kv.Value);
 
+        private static readonly IDictionary<char, Func<string, object>> NumericParsers =
+            new Dictionary<char, Func<string, object>>
+            {
+                { 'i', s => Convert.ToInt32(s) },
+                { 'l', s => Convert.ToInt64(s) },
+                { 'f', s => Convert.ToSingle(s) },
+                { 'd', s => Convert.ToDouble(s) }
+            };
+
         [Given("the (\\w+) graph")]
         public void ChooseModernGraph(string graphName)
         {
@@ -193,10 +201,9 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             
         }
 
-        private static IDictionary ToMap(string stringMap, string graphName)
+        private static object ToMap(string stringMap, string graphName)
         {
-            IDictionary<string, JToken> jsonMap = JObject.Parse(stringMap);
-            return jsonMap.ToDictionary(kv => kv.Key, kv => ParseMapValue(kv.Value, graphName));
+            return ParseMapValue(JObject.Parse(stringMap), graphName);
         }
 
         private static object ToLambda(string stringLambda, string graphName)
@@ -204,8 +211,19 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             throw new IgnoreException(IgnoreReason.LambdaNotSupported);
         }
 
+        private static object ToNumber(string stringNumber, string graphName)
+        {
+            return NumericParsers[stringNumber[stringNumber.Length - 1]](
+                stringNumber.Substring(0, stringNumber.Length - 1));
+        }
+
         private static object ParseMapValue(JToken value, string graphName)
         {
+            if (value.Type == JTokenType.Object)
+            {
+                IDictionary<string, JToken> jsonMap = (JObject)value; 
+                return jsonMap.ToDictionary(kv => kv.Key, kv => ParseMapValue(kv.Value, graphName));
+            }
             if (value.Type == JTokenType.Array)
             {
                 return value.Select(v => ParseMapValue(v, graphName)).ToArray();
@@ -259,6 +277,10 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
                 {
                     parser = kv.Value;
                     extractedValue = match.Groups[1].Value;
+                    if (match.Groups.Count > 2)
+                    {
+                        extractedValue += match.Groups[2].Value;
+                    }
                     break;
                 }
             }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f6cddd28/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 a3748ee..c5d8631 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
@@ -31,10 +31,7 @@ using Xunit;
 using Gherkin;
 using Gherkin.Ast;
 using Gremlin.Net.IntegrationTest.Gherkin.Attributes;
-using Microsoft.VisualStudio.TestPlatform.Utilities;
-using Newtonsoft.Json.Serialization;
 using Xunit.Abstractions;
-using Xunit.Sdk;
 
 namespace Gremlin.Net.IntegrationTest.Gherkin
 {
@@ -43,26 +40,18 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         private static readonly IDictionary<string, IgnoreReason> IgnoredScenarios =
             new Dictionary<string, IgnoreReason>
             {
-                { "g_V_hasLabelXpersonX_projectXa_bX_byXoutE_countX_byXageX", IgnoreReason.ScenarioDesignMapNumbers },
                 { "g_V_matchXa_knows_b__b_created_cX", IgnoreReason.MapCoersionIssue},
                 { "g_V_valueMap_matchXa_selectXnameX_bX", IgnoreReason.MapCoersionIssue},
                 { "g_V_matchXa_out_bX", IgnoreReason.MapCoersionIssue},
-                { "g_V_outXcreatedX_unionXasXprojectX_inXcreatedX_hasXname_markoX_selectXprojectX__asXprojectX_inXcreatedX_inXknowsX_hasXname_markoX_selectXprojectXX_groupCount_byXnameX",
-                    IgnoreReason.ScenarioDesignMapNumbers},
-                { "g_V_hasLabelXpersonX_asXpX_mapXbothE_label_groupCountX_asXrX_selectXp_rX",
-                    IgnoreReason.ScenarioDesignMapNumbers},
-                { "g_V_label_groupCount_asXxX_selectXxX", IgnoreReason.ScenarioDesignMapNumbers},
-                { "g_V_outXfollowedByX_group_byXsongTypeX_byXbothE_group_byXlabelX_byXweight_sumXX",
-                    IgnoreReason.ScenarioDesignMapNumbers},
-                { "g_V_repeatXbothXfollowedByXX_timesX2X_groupXaX_byXsongTypeX_byXcountX_capXaX",
-                    IgnoreReason.ScenarioDesignMapNumbers},
-                { "g_V_repeatXbothXfollowedByXX_timesX2X_group_byXsongTypeX_byXcountX",
-                    IgnoreReason.ScenarioDesignMapNumbers},
-                { "g_V_repeatXout_groupXaX_byXnameX_byXcountX_timesX2X_capXaX", IgnoreReason.ScenarioDesignMapNumbers},
-                { "g_V_hasXlangX_group_byXlangX_byXcountX", IgnoreReason.ScenarioDesignMapNumbers},
-                { "g_V_hasLabelXsongX_group_byXnameX_byXproperties_groupCount_byXlabelXX", IgnoreReason.MapCoersionIssue},
+                { "g_V_hasLabelXsongX_group_byXnameX_byXproperties_groupCount_byXlabelXX",
+                    IgnoreReason.MapCoersionIssue},
                 { "g_V_hasLabelXsongX_groupXaX_byXnameX_byXproperties_groupCount_byXlabelXX_out_capXaX",
                     IgnoreReason.MapCoersionIssue},
+                { "g_V_outXcreatedX_unionXasXprojectX_inXcreatedX_hasXname_markoX_selectXprojectX__asXprojectX_inXcreatedX_inXknowsX_hasXname_markoX_selectXprojectXX_groupCount_byXnameX",
+                    IgnoreReason.MapCoersionIssue},
+                { "g_withSackX0X_V_outE_sackXsumX_byXweightX_inV_sack_sum", IgnoreReason.ScenarioDesignMapNumbers},
+                { "g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX", IgnoreReason.ScenarioDesignMapNumbers},
+                { "g_V_groupXaX_byXlabelX_byXoutE_weight_sumX_capXaX", IgnoreReason.ScenarioDesignMapNumbers}
             };
         
         private static class Keywords

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f6cddd28/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 abc3f2b..74b5382 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
@@ -60,9 +60,10 @@ 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>.Sum):
+                    return typeof(long);
                 case nameof(GraphTraversal<object,object>.Limit):
                 case nameof(GraphTraversal<object,object>.Optional):
-                case nameof(GraphTraversal<object,object>.Sum):
                 case nameof(GraphTraversal<object,object>.Coalesce):
                 case nameof(GraphTraversal<object,object>.Match):
                     // Maintain the same type