From commits-return-32446-archive-asf-public=cust-asf.ponee.io@tinkerpop.apache.org Fri Sep 28 14:27:54 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 42D46180627 for ; Fri, 28 Sep 2018 14:27:54 +0200 (CEST) Received: (qmail 91870 invoked by uid 500); 28 Sep 2018 12:27:53 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 91861 invoked by uid 99); 28 Sep 2018 12:27:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Sep 2018 12:27:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9857DDFE95; Fri, 28 Sep 2018 12:27:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: spmallette@apache.org To: commits@tinkerpop.apache.org Message-Id: <9f3dfded6fa3473fa7f84b0753003daf@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: tinkerpop git commit: TINKERPOP-2041 Fixed .NET tests around TP predicates Date: Fri, 28 Sep 2018 12:27:52 +0000 (UTC) Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-2041 6245880e6 -> 8f07a510b 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 Authored: Fri Sep 28 08:27:25 2018 -0400 Committer: Stephen Mallette 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 { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The name of the predicate. /// The value of the predicate. 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 +{ + /// + /// Represents a parameter for a traversal predicate (ie: TP.contains()) + /// + internal class TPParameter : ITokenParameter, IEquatable + { + private IDictionary _contextParameterValues; + public IList Tokens { get; } + + public TPParameter(IList 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 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));