From commits-return-32462-archive-asf-public=cust-asf.ponee.io@tinkerpop.apache.org Mon Oct 1 16:13:34 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 A791518077A for ; Mon, 1 Oct 2018 16:13:33 +0200 (CEST) Received: (qmail 23027 invoked by uid 500); 1 Oct 2018 14:13:32 -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 23008 invoked by uid 99); 1 Oct 2018 14:13:32 -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; Mon, 01 Oct 2018 14:13:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 01D8CE0954; Mon, 1 Oct 2018 14:13:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: dkuppitz@apache.org To: commits@tinkerpop.apache.org Date: Mon, 01 Oct 2018 14:13:33 -0000 Message-Id: <0049ea073b4b4495a496ee217d16d06f@git.apache.org> In-Reply-To: <425320859381427ca5bafaad9d47fd8c@git.apache.org> References: <425320859381427ca5bafaad9d47fd8c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/3] 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 Authored: Fri Sep 28 08:27:25 2018 -0400 Committer: Daniel Kuppitz 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 { /// - /// 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/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 +{ + /// + /// 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/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));