private ParamSearchResult CalculateParamPosition(string stepText, IBindingParameter bindingParameter, int paramIndex) { string paramName = bindingParameter.ParameterName.ToUpper(); int result = IndexOfWithUnderscores(stepText, paramName); if (result >= 0) { return(new ParamSearchResult(result, paramName.Length, paramIndex)); } result = stepText.IndexOf(paramName); if (result >= 0) { return(new ParamSearchResult(result, paramName.Length, paramIndex)); } string paramReference = string.Format("P{0}", paramIndex); result = IndexOfWithUnderscores(stepText, paramReference); if (result >= 0) { return(new ParamSearchResult(result, paramReference.Length, paramIndex)); } return(new ParamSearchResult(-1, 0, paramIndex)); }
private CallerVariable AddCallerVariableForParameterWithObject(IBindingParameter parameter) { var reference = ReferenceToNewParameterContextObject(parameter); var callerVariable = ReferenceGraph.AddCallerVariable(parameter.Symbol); callerVariable.AddReference(reference); return(callerVariable); }
private string CalculateParamRegex(IBindingParameter parameterInfo) { // parameters should match to the following // 1. quoted text: "..." // 2. apostrophed text: '...' // 3. longer text with lazy matching (as few as possible), to avoid "eating" whitespace before/after return(string.Format(@"(?:""(?<{0}>[^""]*)""|'(?<{0}>[^']*)'|(?<{0}>.*?))", parameterInfo.ParameterName)); }
public static bool ParamEquals(this IBindingParameter param1, IBindingParameter param2) { if (ReferenceEquals(param1, param2)) return true; if (param1 == null || param2 == null) return false; return param1.Type.TypeEquals(param2.Type); }
private Reference ReferenceToNewParameterObject(IBindingParameter parameter) { var referenceType = parameter.Symbol.DataType.Known().UnderlyingReferenceType() ?? throw new ArgumentException("Must be a parameter with a reference type", nameof(parameter)); var referenceCapability = referenceType.ReferenceCapability; var ownership = referenceCapability.ToOwnership(); var access = referenceCapability.ToAccess(); var isOriginOfMutability = access == Access.Mutable; return(ReferenceGraph.AddNewObject(ownership, access, parameter, false, isOriginOfMutability)); }
private ParamSearchResult CalculateParamPosition(string methodNamePart, IBindingParameter bindingParameter, int paramIndex) { string paramName = bindingParameter.ParameterName.ToUpper(); var paramRegex = new Regex(string.Format(@"_?{0}_?|_?P{1}_?", paramName, paramIndex)); var match = paramRegex.Match(methodNamePart); if (match.Success) { return(new ParamSearchResult(match.Index, match.Length, paramIndex)); } return(new ParamSearchResult(-1, 0, paramIndex)); }
private string GetParamType(IBindingParameter bindingParameter) { var typeFullName = bindingParameter.Type.FullName; if (TypeShortcuts.FromType.TryGetValue(typeFullName, out var shortcut)) { return(shortcut); } var key = GetKey(_typeNames, typeFullName); return($"#{key}"); }
public static bool ParamEquals(this IBindingParameter param1, IBindingParameter param2) { if (ReferenceEquals(param1, param2)) { return(true); } if (param1 == null || param2 == null) { return(false); } return(param1.Type.TypeEquals(param2.Type)); }
private ParamSearchResult CalculateParamPosition(string stepText, IBindingParameter bindingParameter, int paramIndex) { string paramName = bindingParameter.ParameterName.ToUpper(); int result = IndexOfWithUnderscores(stepText, paramName); if (result >= 0) return new ParamSearchResult(result, paramName.Length, paramIndex); result = stepText.IndexOf(paramName); if (result >= 0) return new ParamSearchResult(result, paramName.Length, paramIndex); string paramReference = string.Format("P{0}", paramIndex); result = IndexOfWithUnderscores(stepText, paramReference); if (result >= 0) return new ParamSearchResult(result, paramReference.Length, paramIndex); return new ParamSearchResult(-1, 0, paramIndex); }
private object ResolveArgument(IObjectContainer container, IBindingParameter parameter) { if (container == null) { throw new ArgumentNullException(nameof(container)); } if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } var runtimeParameterType = parameter.Type as RuntimeBindingType; if (runtimeParameterType == null) { throw new SpecFlowException("Parameters can only be resolved for runtime methods."); } return(_testObjectResolver.ResolveBindingInstance(runtimeParameterType.Type, container)); }
private string CalculateParamRegex(IBindingParameter parameterInfo) { return string.Format(@"(?:['""](?<{0}>.*[^'""])['""]|(?<{0}>.+))", parameterInfo.ParameterName); }
private string CalculateParamRegex(IBindingParameter parameterInfo) { return(string.Format(@"(?:['""](?<{0}>.*[^'""])['""]|(?<{0}>.+))", parameterInfo.ParameterName)); }
/// <returns>The added local variable for the parameter</returns> public Variable?AddParameter(IBindingParameter parameter) { // Non-reference types don't participate in reachability (yet) var referenceType = parameter.Symbol.DataType.Known().UnderlyingReferenceType(); if (referenceType is null) { return(null); } var localVariable = ReferenceGraph.AddVariable(parameter.Symbol); var capability = referenceType.ReferenceCapability; switch (capability) { default: throw ExhaustiveMatch.Failed(capability); case ReferenceCapability.IsolatedMutable: case ReferenceCapability.Isolated: { // Isolated parameters are fully independent of the caller var reference = ReferenceToNewParameterObject(parameter); localVariable.AddReference(reference); } break; case ReferenceCapability.Owned: case ReferenceCapability.OwnedMutable: case ReferenceCapability.Held: case ReferenceCapability.HeldMutable: { var reference = ReferenceToNewParameterObject(parameter); localVariable.AddReference(reference); var referencedObject = reference.Referent; // TODO this context object is needed // Object to represent the bounding of the lifetime //var callerVariable = AddCallerVariableForParameterWithObject(parameter); //referencedObject.ShareFrom(callerVariable); } break; case ReferenceCapability.Borrowed: { var callerVariable = AddCallerVariableForParameterWithObject(parameter); localVariable.BorrowFrom(callerVariable); } break; case ReferenceCapability.Shared: { var callerVariable = AddCallerVariableForParameterWithObject(parameter); localVariable.ShareFrom(callerVariable); } break; case ReferenceCapability.Identity: { var callerVariable = AddCallerVariableForParameterWithObject(parameter); localVariable.IdentityFrom(callerVariable); } break; } return(localVariable); }