Ejemplo n.º 1
0
        public void step(string keyword, string text, int line)
        {
            FlushDelayedCalls();

            ResetStepArguments();

            var stepSpan = ProcessSimpleLanguageElement(line);

            StepKeyword   stepKeyword   = gherkinDialect.TryParseStepKeyword(keyword) ?? StepKeyword.And; // if we dont find it, we suppose an "and"
            ScenarioBlock scenarioBlock = CalculateScenarioBlock(stepKeyword);

            gherkinListener.Step(keyword, stepKeyword, scenarioBlock, text, stepSpan);
        }
Ejemplo n.º 2
0
        private BindingType?GetCurrentBindingType(SnapshotPoint triggerPoint, out string parsedKeyword)
        {
            parsedKeyword = null;
            var fileScope = languageService.GetFileScope(waitForParsingSnapshot: triggerPoint.Snapshot);

            if (fileScope == null)
            {
                return(null);
            }

            var triggerLineNumber = triggerPoint.Snapshot.GetLineNumberFromPosition(triggerPoint.Position);
            var step = fileScope.GetStepAtPosition(triggerLineNumber);

            if (step != null)
            {
                parsedKeyword = step.Keyword.TrimEnd();
                return(step.BindingType);
            }

            if (!IsStepLine(triggerPoint, languageService))
            {
                return(null);
            }

            // this is a step line that just started. we need to calculate the binding type from
            // the keyword and the context
            var keywordCandidate = GetFirstWord(triggerPoint);

            if (keywordCandidate == null)
            {
                return(null);
            }

            GherkinDialect dialect     = GetDialect(languageService);
            var            stepKeyword = dialect.TryParseStepKeyword(keywordCandidate);

            if (stepKeyword == null)
            {
                keywordCandidate = GetFirstTwoWords(triggerPoint);
                if (keywordCandidate != null)
                {
                    stepKeyword = dialect.TryParseStepKeyword(keywordCandidate);
                }

                if (stepKeyword == null)
                {
                    return(null);
                }
            }

            parsedKeyword = keywordCandidate;

            if (stepKeyword == StepKeyword.Given)
            {
                return(BindingType.Given);
            }
            if (stepKeyword == StepKeyword.When)
            {
                return(BindingType.When);
            }
            if (stepKeyword == StepKeyword.Then)
            {
                return(BindingType.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);
        }