You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2018/10/01 20:20:30 UTC

[3/5] tinkerpop git commit: TINKERPOP-2041 Fixed .NET tests around TP predicates

TINKERPOP-2041 Fixed .NET tests around TP predicates


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

Branch: refs/heads/TINKERPOP-2041
Commit: 441cf6aa4769805215045e460e1daad8b46a1cfb
Parents: 1a0ca3a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Sep 28 08:27:25 2018 -0400
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Mon Oct 1 07:13:23 2018 -0700

----------------------------------------------------------------------
 .../src/Gremlin.Net/Process/Traversal/TP.cs     |  2 +-
 .../Gherkin/TraversalEvaluation/TPParameter.cs  | 97 ++++++++++++++++++++
 .../TraversalEvaluation/TraversalParser.cs      |  4 +
 3 files changed, 102 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/441cf6aa/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TP.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TP.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TP.cs
index ac6415d..abebd1e 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TP.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TP.cs
@@ -39,7 +39,7 @@ namespace Gremlin.Net.Process.Traversal
     public class TP : P
     {
         /// <summary>
-        ///     Initializes a new instance of the <see cref="P" /> class.
+        ///     Initializes a new instance of the <see cref="TP" /> class.
         /// </summary>
         /// <param name="operatorName">The name of the predicate.</param>
         /// <param name="value">The value of the predicate.</param>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/441cf6aa/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TPParameter.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TPParameter.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TPParameter.cs
new file mode 100644
index 0000000..9100c6f
--- /dev/null
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TPParameter.cs
@@ -0,0 +1,97 @@
+#region License
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Dynamic;
+using System.Linq;
+using System.Reflection;
+using Gremlin.Net.Process.Traversal;
+
+namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
+{
+    /// <summary>
+    /// Represents a parameter for a traversal predicate (ie: TP.contains())
+    /// </summary>
+    internal class TPParameter : ITokenParameter, IEquatable<TPParameter>
+    {
+        private IDictionary<string, object> _contextParameterValues;
+        public IList<Token> Tokens { get; }
+        
+        public TPParameter(IList<Token> tokens)
+        {
+            Tokens = tokens;
+        }
+
+        public bool Equals(TPParameter other)
+        {
+            return Tokens.SequenceEqual(other.Tokens);
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (ReferenceEquals(null, obj)) return false;
+            if (ReferenceEquals(this, obj)) return true;
+            if (obj.GetType() != GetType()) return false;
+            return Equals((TPParameter) obj);
+        }
+
+        public override int GetHashCode()
+        {
+            return Tokens != null ? Tokens.GetHashCode() : 0;
+        }
+
+        public object GetValue()
+        {
+            var type = typeof(TP);
+            object instance = null;
+            for (var i = 1; i < Tokens.Count; i++)
+            {
+                var token = Tokens[i];
+                token.SetContextParameterValues(_contextParameterValues);
+                var method = type.GetMethod(TraversalParser.GetCsharpName(token.Name),
+                    BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);
+                if (method == null)
+                {
+                    throw new InvalidOperationException($"Predicate (TP) method '{token}' not found for testing");
+                }
+                
+                var parameters = method.IsStatic
+                    ? new object[] {token.Parameters.Select(p => p.GetValue().ToString()).First()}
+                    : token.Parameters.Select(p => p.GetValue()).ToArray();
+                instance = method.Invoke(instance, parameters);
+            }
+            return instance;
+        }
+
+        public Type GetParameterType()
+        {
+            return typeof(TP);
+        }
+
+        public void SetContextParameterValues(IDictionary<string, object> parameterValues)
+        {
+            _contextParameterValues = parameterValues;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/441cf6aa/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 f8e4095..1065780 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
@@ -406,6 +406,10 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                 var tokens = ParseTokens(text, ref i);
                 return new StaticTraversalParameter(tokens, text.Substring(startIndex, i - startIndex));
             }
+            if (text.Length >= i + 3 && text.Substring(i, 3) == "TP.")
+            {
+                return new TPParameter(ParseTokens(text, ref i));
+            }
             if (text.Substring(i, 2).StartsWith("P."))
             {
                 return new PParameter(ParseTokens(text, ref i));