Skip to content

Commit

Permalink
regactor IBindingMethod and StepScope
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed May 16, 2012
1 parent 626c0ca commit cc6dad6
Show file tree
Hide file tree
Showing 50 changed files with 346 additions and 209 deletions.
Expand Up @@ -213,7 +213,7 @@ private static void ForwardWhile(ref SnapshotPoint point, SnapshotPoint triggerP
point += 1;
}

private BindingType? GetCurrentBindingType(SnapshotPoint triggerPoint, out string parsedKeyword)
private StepDefinitionType? GetCurrentBindingType(SnapshotPoint triggerPoint, out string parsedKeyword)
{
parsedKeyword = null;
var fileScope = languageService.GetFileScope(waitForParsingSnapshot: triggerPoint.Snapshot);
Expand All @@ -225,7 +225,7 @@ private static void ForwardWhile(ref SnapshotPoint point, SnapshotPoint triggerP
if (step != null)
{
parsedKeyword = step.Keyword.TrimEnd();
return step.BindingType;
return step.StepDefinitionType;
}

if (!IsStepLine(triggerPoint, languageService))
Expand Down Expand Up @@ -254,22 +254,22 @@ private static void ForwardWhile(ref SnapshotPoint point, SnapshotPoint triggerP
parsedKeyword = keywordCandidate;

if (stepKeyword == StepKeyword.Given)
return BindingType.Given;
return StepDefinitionType.Given;
if (stepKeyword == StepKeyword.When)
return BindingType.When;
return StepDefinitionType.When;
if (stepKeyword == StepKeyword.Then)
return BindingType.Then;
return StepDefinitionType.Then;

parsedKeyword = null;
// now we need the context
var stepBlock = fileScope.GetStepBlockFromStepPosition(triggerLineNumber);
var lastStep = stepBlock.Steps.LastOrDefault(s => s.BlockRelativeLine + stepBlock.KeywordLine < triggerLineNumber);
if (lastStep == null)
return BindingType.Given;
return lastStep.BindingType;
return StepDefinitionType.Given;
return lastStep.StepDefinitionType;
}

private void GetCompletionsForBindingType(BindingType bindingType, out IEnumerable<Completion> completions, out IEnumerable<Completion> completionBuilders)
private void GetCompletionsForBindingType(StepDefinitionType stepDefinitionType, out IEnumerable<Completion> completions, out IEnumerable<Completion> completionBuilders)
{
completionBuilders = null;

Expand All @@ -291,7 +291,7 @@ private void GetCompletionsForBindingType(BindingType bindingType, out IEnumerab

try
{
completions = suggestionProvider.GetNativeSuggestionItems(bindingType);
completions = suggestionProvider.GetNativeSuggestionItems(stepDefinitionType);
}
catch(Exception)
{
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected string GetStepText(StepInstance stepInstance)
stepInstance.StepDefinitionKeyword == StepDefinitionKeyword.Then)
keyword = stepInstance.Keyword;
else
keyword = gherkinDialect.GetStepKeywords((StepKeyword) stepInstance.BindingType).FirstOrDefault(k => !k.StartsWith("*")) ?? "";
keyword = gherkinDialect.GetStepKeywords((StepKeyword) stepInstance.StepDefinitionType).FirstOrDefault(k => !k.StartsWith("*")) ?? "";

return keyword + stepInstance.Text;
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ public override string GetStepDefinitionSkeleton(StepInstance stepInstance)
{{
ScenarioContext.Current.Pending();
}}",
stepInstance.BindingType,
stepInstance.StepDefinitionType,
EscapeRegex(stepInstance.Text),
GetStepText(stepInstance).ToIdentifier(),
string.Join(", ", extraArgs.ToArray())
Expand Down
Expand Up @@ -25,7 +25,7 @@ public override string GetStepDefinitionSkeleton(StepInstance stepInstance)

// in VB "When" and "Then" are language keywords - use the fully qualified namespace
string namespaceAddition = "TechTalk.SpecFlow.";
if (stepInstance.BindingType == BindingType.Given)
if (stepInstance.StepDefinitionType == StepDefinitionType.Given)
{
namespaceAddition = "";
}
Expand All @@ -34,7 +34,7 @@ public override string GetStepDefinitionSkeleton(StepInstance stepInstance)
Public Sub {2}({3})
ScenarioContext.Current.Pending()
End Sub",
stepInstance.BindingType,
stepInstance.StepDefinitionType,
EscapeRegex(stepInstance.Text),
GetStepText(stepInstance).ToIdentifier(),
string.Join(", ", extraArgs.ToArray()),
Expand Down
Expand Up @@ -35,11 +35,11 @@ public BindingMatchNew Match(StepBindingNew stepBinding, StepInstance stepInstan
if (useRegexMatching && stepBinding.Regex != null && !(match = stepBinding.Regex.Match(stepInstance.Text)).Success)
return BindingMatchNew.NonMatching;

if (stepBinding.BindingType != stepInstance.BindingType)
if (stepBinding.StepDefinitionType != stepInstance.StepDefinitionType)
return BindingMatchNew.NonMatching;

int scopeMatches = 0;
if (useScopeMatching && stepBinding.IsScoped && stepInstance.StepScope != null && !stepBinding.BindingScope.Match(stepInstance.StepScope, out scopeMatches))
if (useScopeMatching && stepBinding.IsScoped && stepInstance.StepContext != null && !stepBinding.BindingScope.Match(stepInstance.StepContext, out scopeMatches))
return BindingMatchNew.NonMatching;

if (useParamMatching)
Expand Down
12 changes: 6 additions & 6 deletions IdeIntegration/Vs2010Integration/Bindings/BindingScope.cs
Expand Up @@ -24,17 +24,17 @@ private string RemoveLeadingAt(string tag)
return tag.Substring(1); // remove leading "@"
}

public bool Match(StepScopeNew stepScope)
public bool Match(StepContext stepContext)
{
int dummy;
return Match(stepScope, out dummy);
return Match(stepContext, out dummy);
}

private readonly string[] emptyTagList = new string[0];
public bool Match(StepScopeNew stepScope, out int scopeMatches)
public bool Match(StepContext stepContext, out int scopeMatches)
{
scopeMatches = 0;
var tags = stepScope.Tags ?? emptyTagList;
var tags = stepContext.Tags ?? emptyTagList;
if (Tag != null)
{
if (!tags.Contains(Tag))
Expand All @@ -44,14 +44,14 @@ public bool Match(StepScopeNew stepScope, out int scopeMatches)
}
if (FeatureTitle != null)
{
if (!string.Equals(FeatureTitle, stepScope.FeatureTitle, StringComparison.CurrentCultureIgnoreCase))
if (!string.Equals(FeatureTitle, stepContext.FeatureTitle, StringComparison.CurrentCultureIgnoreCase))
return false;

scopeMatches++;
}
if (ScenarioTitle != null)
{
if (!string.Equals(ScenarioTitle, stepScope.ScenarioTitle, StringComparison.CurrentCultureIgnoreCase))
if (!string.Equals(ScenarioTitle, stepContext.ScenarioTitle, StringComparison.CurrentCultureIgnoreCase))
return false;

scopeMatches++;
Expand Down
6 changes: 3 additions & 3 deletions IdeIntegration/Vs2010Integration/Bindings/StepBinding.cs
Expand Up @@ -8,16 +8,16 @@ namespace TechTalk.SpecFlow.Bindings
public class StepBindingNew
{
public IBindingMethod Method { get; private set; }
public BindingType BindingType { get; private set; }
public StepDefinitionType StepDefinitionType { get; private set; }
public Regex Regex { get; private set; }

public BindingScopeNew BindingScope { get; private set; }
public bool IsScoped { get { return BindingScope != null; } }

public StepBindingNew(IBindingMethod method, BindingType bindingType, Regex regex, BindingScopeNew bindingScope)
public StepBindingNew(IBindingMethod method, StepDefinitionType stepDefinitionType, Regex regex, BindingScopeNew bindingScope)
{
Method = method;
BindingType = bindingType;
StepDefinitionType = stepDefinitionType;
Regex = regex;
BindingScope = bindingScope;
}
Expand Down
10 changes: 5 additions & 5 deletions IdeIntegration/Vs2010Integration/Bindings/StepInstance.cs
Expand Up @@ -7,21 +7,21 @@ namespace TechTalk.SpecFlow.Bindings
{
public class StepInstance
{
public BindingType BindingType { get; private set; }
public StepDefinitionType StepDefinitionType { get; private set; }
public StepDefinitionKeyword StepDefinitionKeyword { get; private set; }
public string Keyword { get; private set; }
public string Text { get; private set; }
public StepScopeNew StepScope { get; private set; }
public StepContext StepContext { get; private set; }
public string MultilineTextArgument { get; set; }
public Table TableArgument { get; set; }

public StepInstance(BindingType bindingType, StepDefinitionKeyword stepDefinitionKeyword, string keyword, string stepText, StepScopeNew stepScope)
public StepInstance(StepDefinitionType stepDefinitionType, StepDefinitionKeyword stepDefinitionKeyword, string keyword, string stepText, StepContext stepContext)
{
BindingType = bindingType;
StepDefinitionType = stepDefinitionType;
StepDefinitionKeyword = stepDefinitionKeyword;
Keyword = keyword;
Text = stepText;
StepScope = stepScope;
StepContext = stepContext;
}
}
}
18 changes: 0 additions & 18 deletions IdeIntegration/Vs2010Integration/Bindings/StepScope.cs

This file was deleted.

Expand Up @@ -33,8 +33,8 @@ public class GherkinStep : StepInstance, IKeywordLine
public int BlockRelativeLine { get; set; }
public BindingStatus BindingStatus { get; set; }

public GherkinStep(BindingType bindingType, StepDefinitionKeyword stepDefinitionKeyword, string stepText, StepScopeNew stepScope, string keyword, int blockRelativeLine)
: base(bindingType, stepDefinitionKeyword, keyword, stepText, stepScope)
public GherkinStep(StepDefinitionType stepDefinitionType, StepDefinitionKeyword stepDefinitionKeyword, string stepText, StepContext stepContext, string keyword, int blockRelativeLine)
: base(stepDefinitionType, stepDefinitionKeyword, keyword, stepText, stepContext)
{
BlockRelativeLine = blockRelativeLine;
BindingStatus = BindingStatus.UnknownBindingStatus;
Expand Down
Expand Up @@ -336,9 +336,9 @@ public void Step(string keyword, StepKeyword stepKeyword, Parser.Gherkin.Scenari

var editorLine = stepSpan.StartPosition.Line;
var tags = FeatureTags.Concat(CurrentFileBlockBuilder.Tags).Distinct();
var stepScope = new StepScopeNew(FeatureTitle, CurrentFileBlockBuilder.BlockType == typeof(IBackgroundBlock) ? null : CurrentFileBlockBuilder.Title, tags.ToArray());
var stepContext = new StepContext(FeatureTitle, CurrentFileBlockBuilder.BlockType == typeof(IBackgroundBlock) ? null : CurrentFileBlockBuilder.Title, tags.ToArray(), gherkinFileScope.GherkinDialect.CultureInfo);

currentStep = new GherkinStep((BindingType)scenarioBlock, (StepDefinitionKeyword)stepKeyword, text, stepScope, keyword, editorLine - CurrentFileBlockBuilder.KeywordLine);
currentStep = new GherkinStep((StepDefinitionType)scenarioBlock, (StepDefinitionKeyword)stepKeyword, text, stepContext, keyword, editorLine - CurrentFileBlockBuilder.KeywordLine);
CurrentFileBlockBuilder.Steps.Add(currentStep);
}

Expand Down
Expand Up @@ -137,9 +137,9 @@ private bool IsScopeAttribute(CodeAttribute2 codeAttribute)
private IEnumerable<StepBindingNew> GetStepDefinitionsFromAttribute(CodeAttribute2 codeAttribute, CodeFunction codeFunction, BindingScopeNew bindingScope)
{
var normalStepDefinition =
GetBingingFromAttribute(codeAttribute, codeFunction, BindingType.Given, bindingScope) ??
GetBingingFromAttribute(codeAttribute, codeFunction, BindingType.When, bindingScope) ??
GetBingingFromAttribute(codeAttribute, codeFunction, BindingType.Then, bindingScope);
GetBingingFromAttribute(codeAttribute, codeFunction, StepDefinitionType.Given, bindingScope) ??
GetBingingFromAttribute(codeAttribute, codeFunction, StepDefinitionType.When, bindingScope) ??
GetBingingFromAttribute(codeAttribute, codeFunction, StepDefinitionType.Then, bindingScope);
if (normalStepDefinition != null)
{
yield return normalStepDefinition;
Expand All @@ -148,18 +148,18 @@ private IEnumerable<StepBindingNew> GetStepDefinitionsFromAttribute(CodeAttribut

if (IsGeneralStepDefinition(codeAttribute))
{
yield return CreateStepBinding(codeAttribute, codeFunction, BindingType.Given, bindingScope);
yield return CreateStepBinding(codeAttribute, codeFunction, BindingType.When, bindingScope);
yield return CreateStepBinding(codeAttribute, codeFunction, BindingType.Then, bindingScope);
yield return CreateStepBinding(codeAttribute, codeFunction, StepDefinitionType.Given, bindingScope);
yield return CreateStepBinding(codeAttribute, codeFunction, StepDefinitionType.When, bindingScope);
yield return CreateStepBinding(codeAttribute, codeFunction, StepDefinitionType.Then, bindingScope);
}
}

private StepBindingNew GetBingingFromAttribute(CodeAttribute2 codeAttribute, CodeFunction codeFunction, BindingType bindingType, BindingScopeNew bindingScope)
private StepBindingNew GetBingingFromAttribute(CodeAttribute2 codeAttribute, CodeFunction codeFunction, StepDefinitionType stepDefinitionType, BindingScopeNew bindingScope)
{
try
{
if (codeAttribute.FullName.Equals(string.Format("TechTalk.SpecFlow.{0}Attribute", bindingType)))
return CreateStepBinding(codeAttribute, codeFunction, bindingType, bindingScope);
if (codeAttribute.FullName.Equals(string.Format("TechTalk.SpecFlow.{0}Attribute", stepDefinitionType)))
return CreateStepBinding(codeAttribute, codeFunction, stepDefinitionType, bindingScope);
return null;
}
catch(Exception)
Expand All @@ -180,7 +180,7 @@ private bool IsGeneralStepDefinition(CodeAttribute2 codeAttribute)
}
}

private StepBindingNew CreateStepBinding(CodeAttribute2 attr, CodeFunction codeFunction, BindingType bindingType, BindingScopeNew bindingScope)
private StepBindingNew CreateStepBinding(CodeAttribute2 attr, CodeFunction codeFunction, StepDefinitionType stepDefinitionType, BindingScopeNew bindingScope)
{
try
{
Expand All @@ -193,7 +193,7 @@ private StepBindingNew CreateStepBinding(CodeAttribute2 attr, CodeFunction codeF
var regexString = VsxHelper.ParseCodeStringValue(regexArg.Value, regexArg.Language);
var regex = new Regex("^" + regexString + "$", RegexOptions.Compiled | RegexOptions.CultureInvariant);

return new StepBindingNew(bindingMethod, bindingType, regex, bindingScope);
return new StepBindingNew(bindingMethod, stepDefinitionType, regex, bindingScope);
}
catch(Exception)
{
Expand Down
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Media;
Expand Down Expand Up @@ -136,20 +137,26 @@ public void Initialize()
vsProjectScope.BindingFilesTracker.FileRemoved += BindingFilesTrackerOnFileRemoved;
}

private static StepScopeNew CreateStepScope(Feature feature, Scenario scenario)
private StepContext CreateStepScope(Feature feature, Scenario scenario)
{
var tags =
(feature.Tags.AsEnumerable() ?? Enumerable.Empty<Tag>())
.Concat(scenario.Tags.AsEnumerable() ?? Enumerable.Empty<Tag>())
.Select(t => t.Name).Distinct();
return new StepScopeNew(feature.Title, scenario.Title, tags.ToArray());
return new StepContext(feature.Title, scenario.Title, tags.ToArray(), GetLanguage(feature));
}

private static StepScopeNew CreateStepScope(Feature feature)
private StepContext CreateStepScope(Feature feature)
{
var tags = (feature.Tags.AsEnumerable() ?? Enumerable.Empty<Tag>())
.Select(t => t.Name).Distinct();
return new StepScopeNew(feature.Title, null, tags.ToArray());
return new StepContext(feature.Title, null, tags.ToArray(), GetLanguage(feature));
}

private CultureInfo GetLanguage(Feature feature)
{
var language = this.vsProjectScope.GherkinDialectServices.GetGherkinDialect(feature).CultureInfo;
return language;
}

private IEnumerable<IStepSuggestion<Completion>> GetStepSuggestions(Feature feature)
Expand Down
Expand Up @@ -20,12 +20,12 @@ public class BoundStepSuggestions<TNativeSuggestionItem> : IStepSuggestion<TNati
public TNativeSuggestionItem NativeSuggestionItem { get; private set; }

public StepBindingNew StepBinding { get; private set; }
public BindingType BindingType { get; set; }
public StepDefinitionType StepDefinitionType { get; set; }

public BoundStepSuggestions(BindingType bindingType, INativeSuggestionItemFactory<TNativeSuggestionItem> nativeSuggestionItemFactory)
public BoundStepSuggestions(StepDefinitionType stepDefinitionType, INativeSuggestionItemFactory<TNativeSuggestionItem> nativeSuggestionItemFactory)
{
StepBinding = null;
BindingType = bindingType;
StepDefinitionType = stepDefinitionType;
NativeSuggestionItem = nativeSuggestionItemFactory.Create("[unbound steps]", "...", 0, "nb", this);
suggestions = new StepSuggestionList<TNativeSuggestionItem>(nativeSuggestionItemFactory);
}
Expand All @@ -35,9 +35,9 @@ public BoundStepSuggestions(StepBindingNew stepBinding, INativeSuggestionItemFac
if (stepBinding == null) throw new ArgumentNullException("stepBinding");

StepBinding = stepBinding;
BindingType = stepBinding.BindingType;
StepDefinitionType = stepBinding.StepDefinitionType;
string suggestionText = GetSuggestionText(stepBinding);
NativeSuggestionItem = nativeSuggestionItemFactory.Create(suggestionText, GetInsertionText(StepBinding), 0, BindingType.ToString().Substring(0, 1) + "-b", this);
NativeSuggestionItem = nativeSuggestionItemFactory.Create(suggestionText, GetInsertionText(StepBinding), 0, StepDefinitionType.ToString().Substring(0, 1) + "-b", this);
suggestions = new StepSuggestionList<TNativeSuggestionItem>(nativeSuggestionItemFactory);
}

Expand Down
Expand Up @@ -6,7 +6,7 @@ namespace TechTalk.SpecFlow.Vs2010Integration.StepSuggestions
public interface IStepSuggestion<out TNativeSuggestionItem>
{
TNativeSuggestionItem NativeSuggestionItem { get; }
BindingType BindingType { get; }
StepDefinitionType StepDefinitionType { get; }
}

public interface IBoundStepSuggestion<TNativeSuggestionItem> : IStepSuggestion<TNativeSuggestionItem>
Expand Down

0 comments on commit cc6dad6

Please sign in to comment.