You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/10/01 20:18:46 UTC
[4/4] 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/8f07a510
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8f07a510
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8f07a510
Branch: refs/heads/TINKERPOP-2041
Commit: 8f07a510b634c63d1eb82408c4b28793534b7114
Parents: 6245880
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Sep 28 08:27:25 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Sep 28 08:27:25 2018 -0400
----------------------------------------------------------------------
.../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/8f07a510/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/8f07a510/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/8f07a510/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));