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/79d4a056 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/79d4a056 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/79d4a056 Branch: refs/heads/TINKERPOP-2041 Commit: 79d4a056e311971c765bf1b9bd84b48582df7698 Parents: 68c47af Author: Stephen Mallette <sp...@genoprime.com> Authored: Fri Sep 28 08:27:25 2018 -0400 Committer: Daniel Kuppitz <daniel_kupp...@hotmail.com> Committed: Thu Oct 4 07:45:08 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/79d4a056/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/79d4a056/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/79d4a056/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));