This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch TINKERPOP-2235 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit c6cff4e4b5954e77310c0e339791d1141d11db23 Author: Jorge Bay Gondra <jorgebaygon...@gmail.com> AuthorDate: Tue Nov 5 12:26:58 2019 +0100 TINKERPOP-2235 Fix C# gherkin test harness Fix C# gherkin test harness for method with params and generic type parameters. Add null as token. --- .../Gherkin/CommonSteps.cs | 3 ++- .../Gherkin/TraversalEvaluation/LiteralParameter.cs | 11 ++++++++--- .../Gherkin/TraversalEvaluation/TraversalParser.cs | 19 +++++++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs index d4b2aab..504f7a9 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs @@ -63,7 +63,8 @@ namespace Gremlin.Net.IntegrationTest.Gherkin {@"s\[(.*)\]", ToSet}, {@"m\[(.+)\]", ToMap}, {@"c\[(.+)\]", ToLambda}, - {@"t\[(.+)\]", ToT} + {@"t\[(.+)\]", ToT}, + {"null", (_, __) => null} }.ToDictionary(kv => new Regex("^" + kv.Key + "$", RegexOptions.Compiled), kv => kv.Value); private static readonly IDictionary<char, Func<string, object>> NumericParsers = diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/LiteralParameter.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/LiteralParameter.cs index da0ac24..10a88a2 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/LiteralParameter.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/LiteralParameter.cs @@ -29,10 +29,15 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation /// <summary> /// Represents a literal (number / boolean) that is allowed as a gremlin parameter. /// </summary> - public class LiteralParameter<T> : ITokenParameter, IEquatable<LiteralParameter<T>> where T : struct + public class LiteralParameter<T> : ITokenParameter, IEquatable<LiteralParameter<T>> { public bool Equals(LiteralParameter<T> other) { + if (Value == null) + { + return other.Value == null; + } + return Value.Equals(other.Value); } @@ -46,7 +51,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation public override int GetHashCode() { - return Value.GetHashCode(); + return Value?.GetHashCode() ?? 0; } public T Value { get; } @@ -79,7 +84,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation internal static class LiteralParameter { - public static LiteralParameter<TType> Create<TType>(TType value) where TType : struct + public static LiteralParameter<TType> Create<TType>(TType value) { return new LiteralParameter<TType>(value); } 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 105932f..fb84fdd 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs @@ -233,6 +233,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation var paramsInfo = method.GetParameters(); var parameters = new object[paramsInfo.Length]; genericParameterTypes = new Dictionary<string, Type>(); + for (var i = 0; i < paramsInfo.Length; i++) { var info = paramsInfo[i]; @@ -246,15 +247,18 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation // We've provided a value for parameter of a generic type, we can infer the // type of the generic argument based on the parameter. // For example, in the case of `Constant<E2>(E2 value)` - // if we have the type of value we have the type of E2. + // if we have the type of value we have the type of E2. genericParameterTypes.Add(info.ParameterType.Name, tokenParameter.GetParameterType()); } else if (IsParamsArray(info) && info.ParameterType.GetElementType().IsGenericParameter) { // Its a method where the type parameter comes from an params Array // e.g., Inject<S>(params S[] value) - genericParameterTypes.Add(info.ParameterType.GetElementType().Name, - tokenParameter.GetParameterType()); + var type = tokenParameter.GetParameterType(); + genericParameterTypes.Add(info.ParameterType.GetElementType().Name, type); + + // Use a placeholder value + value = type.IsValueType ? Activator.CreateInstance(type) : new object(); } if (info.ParameterType != tokenParameter.GetParameterType() && IsNumeric(info.ParameterType) && @@ -270,7 +274,6 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation // For `params type[] value` we should provide an empty array if (value == null) { - // An empty array value = Array.CreateInstance(info.ParameterType.GetElementType(), 0); } else if (!value.GetType().IsArray) @@ -286,8 +289,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation } var arr = Array.CreateInstance(elementType, token.Parameters.Count - i); - arr.SetValue(value, 0); - for (var j = 1; j < token.Parameters.Count - i; j++) + for (var j = 0; j < token.Parameters.Count - i; j++) { arr.SetValue(token.Parameters[i + j].GetValue(), j); } @@ -449,6 +451,11 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation i += parameterText.Length - 1; return LiteralParameter.Create(Convert.ToBoolean(parameterText)); } + if (parameterText == "null") + { + i += parameterText.Length - 1; + return LiteralParameter.Create<object>(null); + } if (RegexIO.IsMatch(parameterText)) { i += parameterText.Length - 1;