Exemplo n.º 1
0
        public void Examples(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
        {
            var editorLine = headerSpan.StartPosition.Line;

            OnCloseLevel2Outlinings(CalculateRegionEndLine(editorLine));

            RegisterKeyword(keyword, headerSpan);
            ColorizeSpan(descriptionSpan, classifications.Description);

            ScenarioOutlineExampleSet exampleSet = new ScenarioOutlineExampleSet(keyword, name,
                                                                                 editorLine - CurrentFileBlockBuilder.KeywordLine);

            CurrentFileBlockBuilder.ExampleSets.Add(exampleSet);
            currentStep = null;

            CloseLevel2Outlinings += regionEndLine =>
            {
                if (regionEndLine > editorLine)
                {
                    AddOutline(
                        editorLine,
                        regionEndLine,
                        exampleSet.FullTitle());
                }
            };
        }
        private static GherkinStep GetSubstitutedStep(GherkinStep step, IDictionary <string, string> exampleDictionary)
        {
            var replacedText    = ReplaceExamplesInText(step.Text, exampleDictionary);
            var substitutedStep = new GherkinStep(step.StepDefinitionType, step.StepDefinitionKeyword, replacedText, step.StepContext, step.Keyword, step.BlockRelativeLine);

            substitutedStep.MultilineTextArgument = step.MultilineTextArgument == null ? null: ReplaceExamplesInText(step.MultilineTextArgument, exampleDictionary);
            substitutedStep.TableArgument         = CreateSubstitutedTable(step.TableArgument, exampleDictionary);
            return(substitutedStep);
        }
Exemplo n.º 3
0
        public virtual void Background(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
        {
            NewBlock(headerSpan.StartPosition.Line);
            CurrentFileBlockBuilder.SetMainData(typeof(IBackgroundBlock), headerSpan.StartPosition.Line, keyword, name);
            currentStep = null;

            RegisterKeyword(keyword, headerSpan);
            ColorizeSpan(descriptionSpan, classifications.Description);
        }
Exemplo n.º 4
0
 private void EnsureNewScenario(int editorLine)
 {
     if (CurrentFileBlockBuilder.IsComplete)
     {
         CloseBlock(editorLine);
         OnScenarioBlockCreating(editorLine);
         CreateBlock(editorLine);
         currentStep = null;
     }
 }
        public static GherkinStep GetSubstitutedStep(this GherkinStep step, IScenarioOutlineBlock scenarioOutlineBlock)
        {
            var firstNonEmptyExampleSet = scenarioOutlineBlock.ExampleSets.FirstOrDefault(es => es.ExamplesTable != null && es.ExamplesTable.RowCount > 0);

            if (firstNonEmptyExampleSet == null)
            {
                return(step);
            }

            return(GetSubstitutedStep(step, firstNonEmptyExampleSet.ExamplesTable.Rows.First()));
        }
 public static string FullTitle(this GherkinStep keywordLine)
 {
     return(keywordLine.Keyword + keywordLine.Text);
 }
Exemplo n.º 7
0
        public void Step(string keyword, StepKeyword stepKeyword, Parser.Gherkin.ScenarioBlock scenarioBlock, string text, GherkinBufferSpan stepSpan)
        {
            var editorLine  = stepSpan.StartPosition.Line;
            var tags        = FeatureTags.Concat(CurrentFileBlockBuilder.Tags).Distinct();
            var stepContext = new StepContext(FeatureTitle, CurrentFileBlockBuilder.BlockType == typeof(IBackgroundBlock) ? null : CurrentFileBlockBuilder.Title, tags.ToArray(), gherkinFileScope.GherkinDialect.CultureInfo);

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

            var bindingMatchService = projectScope.BindingMatchService;

            if (enableStepMatchColoring && bindingMatchService != null && bindingMatchService.Ready)
            {
                List <BindingMatch>           candidatingMatches;
                StepDefinitionAmbiguityReason ambiguityReason;
                CultureInfo bindingCulture = projectScope.SpecFlowConfiguration.BindingCulture ?? currentStep.StepContext.Language;
                var         match          = bindingMatchService.GetBestMatch(currentStep, bindingCulture, out ambiguityReason, out candidatingMatches);

                if (match.Success)
                {
                    ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);

                    var regexMatch = match.StepBinding.Regex.Match(text);
                    if (regexMatch.Success)
                    {
                        var textStart = KeywordAndWhitespaceLength(keyword, stepSpan, editorLine);
                        foreach (Group matchGroup in regexMatch.Groups.Cast <Group>().Skip(1))
                        {
                            var captures    = matchGroup.Captures;
                            var lastCapture = captures[captures.Count - 1];
                            var partStart   = textStart + captures[0].Index;
                            var partEnd     = textStart + lastCapture.Index + lastCapture.Length;
                            ColorizeLinePart(partStart, partEnd, stepSpan, classifications.StepArgument);
                        }
                    }
                    else
                    {
                        // this should never happen
                    }
                }
                else if (CurrentFileBlockBuilder.BlockType == typeof(IScenarioOutlineBlock) && placeholderRe.Match(text).Success)
                {
                    ColorizeKeywordLine(keyword, stepSpan, classifications.StepText); // we do not show binding errors in placeholdered scenario outline steps
                    //TODO: check match based on the scenario examples - unfortunately the steps are parsed earlier than the examples, so we would need to delay the colorization somehow
                }
                else
                {
                    ColorizeKeywordLine(keyword, stepSpan, classifications.UnboundStepText);
                }
            }
            else
            {
                ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);
            }

            if (CurrentFileBlockBuilder.BlockType == typeof(IScenarioOutlineBlock))
            {
                var matches   = placeholderRe.Matches(text);
                var textStart = KeywordAndWhitespaceLength(keyword, stepSpan, editorLine);
                foreach (Match match in matches)
                {
                    var capture = match.Groups[0].Captures[0];
                    var start   = textStart + capture.Index;
                    ColorizeLinePart(start, start + capture.Length, stepSpan, classifications.Placeholder);
                }
            }
        }