public void Examples(Token keyword, Token name)
 {
     listeners.ForEach(_ => _.Examples(keyword, name));
 }
Esempio n. 2
0
 public void Feature(Token keyword, Token title, Token narrative)
 {
     events.Add(new GherkinParseEvent(GherkinTokenType.Feature, keyword, title, narrative));
 }
Esempio n. 3
0
 public void Step(Token keyword, Token name)
 {
     events.Add(new GherkinParseEvent(GherkinTokenType.Step, keyword, name));
 }
Esempio n. 4
0
 public void Background(Token keyword, Token name)
 {
     events.Add(new GherkinParseEvent(GherkinTokenType.Background, keyword, name));
 }
Esempio n. 5
0
 public void DocString(Token docString)
 {
     events.Add(new GherkinParseEvent(GherkinTokenType.DocString, docString));
 }
Esempio n. 6
0
 public void Step(Token keyword, Token name)
 {
     string stepText = string.Format("{0} {1}", keyword.Content, name.Content);
     var stringStep = new StringStep(stepText, file, keyword.LineInFile.Line);
     events.Enqueue(new StepEvent(stepText, e => StepEvent.Invoke(this, new EventArgs<StringStep>(stringStep))));
 }
Esempio n. 7
0
 public void Background(Token keyword, Token name)
 {
     var scenario = new Scenario(name.Content, file, currentFeature, keyword.LineInFile.Line);
     currentScenario = scenario;
     events.Enqueue(new BackgroundEvent(currentScenario, e => BackgroundEvent.Invoke(this, new EventArgs<Scenario>(scenario))));
 }
Esempio n. 8
0
        private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTitle(SnapshotSpan span, Token token, GherkinTokenType tokenType)
        {
            var spanText = span.GetText();
            var tokenText = token.Content.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(_ => _.Trim(WhiteSpaces.Chars)).ToList();
            foreach (var row in tokenText)
            {
                var idx = spanText.IndexOf(row, StringComparison.CurrentCulture);
                if (idx == -1)
                    continue;
                ITextSnapshotLine containingLine = span.Start.GetContainingLine();
                var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, row.Length));
                var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType));
                yield return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);

            }
        }
Esempio n. 9
0
 private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> HandleType(SnapshotSpan span, Token token, GherkinTokenType tokenType)
 {
     var text = span.GetText();
     if (text.TrimStart(WhiteSpaces.Chars).StartsWith(token.Content))
     {
         var idx = text.IndexOf(token.Content, StringComparison.Ordinal);
         ITextSnapshotLine containingLine = span.Start.GetContainingLine();
         var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, token.Content.Length));
         var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType));
         return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);
     }
     return null;
 }
 public void Tag(Token name)
 {
     listeners.ForEach(_ => _.Tag(name));
 }
Esempio n. 11
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleComment(SnapshotSpan span, GherkinParseEvent evt)
 {
     var text = span.GetText();
     var isLanguage = new Regex(@"\s*#\s*language\s*(:|\s)\s*(?<language>[a-zA-Z\-]+)");
     var match = isLanguage.Match(text);
     if (match.Success)
     {
         foreach (var commentTag in TagLanguageComment(span, evt, match, text))
             yield return commentTag;
     }
     else
     {
         var r = new Regex(string.Format(@"^\s*#\s*{0}\s*$", evt.Tokens[0].Content));
         if (r.IsMatch(text))
         {
             var t = new Token(text, evt.Tokens[0].LineInFile);
             var tag = CreateTag(t, span, evt);
             if (tag != null)
                 yield return tag;
         }
     }
 }
 public void Step(Token keyword, Token name)
 {
     listeners.ForEach(_ => _.Step(keyword, name));
 }
 public void Scenario(Token keyword, Token title)
 {
     listeners.ForEach(_ => _.Scenario(keyword, title));
 }
 public void Feature(Token keyword, Token title, Token narrative)
 {
     listeners.ForEach(_ => _.Feature(keyword, title, narrative));
 }
Esempio n. 15
0
 public void Feature(Token keyword, Token title, Token narrative)
 {
     CreateFeature(title.Content, narrative.Content, keyword.LineInFile.Line);
 }
Esempio n. 16
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> SyntaxError(SnapshotSpan span, GherkinParseEvent evt)
 {
     var text = span.GetText();
     var token = new Token(text, new LineInFile(-1));
     var tag = CreateTag(token, span, GherkinTokenType.SyntaxError, text);
     if (tag != null)
         yield return tag;
 }
Esempio n. 17
0
 public void Scenario(Token keyword, Token title)
 {
     var scenario = new Scenario(title.Content, file, currentFeature, keyword.LineInFile.Line);
     currentScenario = scenario;
     events.Enqueue(new ScenarioEvent(currentScenario, e =>
         {
             scenario.AddTags(e.Tags);
             ScenarioEvent.Invoke(this, new EventArgs<Scenario>(scenario));
         }));
 }
Esempio n. 18
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> TagLanguageComment(SnapshotSpan span, GherkinParseEvent evt, Match match, string text)
 {
     var i = text.IndexOf("language");
     var t1 = new Token(text.Substring(0, i), evt.Tokens[0].LineInFile);
     var comment = CreateTag(t1, span, evt);
     if (comment != null)
         yield return comment;
     var t2 = new Token(match.Value.Substring(i), evt.Tokens[0].LineInFile);
     var lang = CreateTag(t2, span, new GherkinParseEvent(GherkinTokenType.Tag, evt.Tokens.ToArray()));
     if (lang != null)
         yield return lang;
     var t3 = new Token(text.Substring(i + t2.Content.Length).TrimEnd(WhiteSpaces.Chars), evt.Tokens[0].LineInFile);
     if (t3.Content != "")
     {
         var end = CreateTag(t3, span, evt);
         if (end != null)
             yield return end;
     }
 }
Esempio n. 19
0
 public void Tag(Token tag)
 {
     events.Enqueue(new TagEvent(tag.Content, e => TagEvent.Invoke(this, new EventArgs<string>(tag.Content))));
 }
Esempio n. 20
0
 private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> CreateTag(Token token, SnapshotSpan span, GherkinParseEvent evt)
 {
     var text = span.GetText();
     return CreateTag(token, span, evt.GherkinTokenType, text);
 }
Esempio n. 21
0
 private Tuple<List<GherkinParseEvent>, List<Feature>> Parse(string content)
 {
     var features = new List<Feature>();
     var nBehaveConfiguration = NBehaveConfiguration.New.DontIsolateInAppDomain().SetDryRun(true);
     var gherkinScenarioParser = new GherkinScenarioParser(nBehaveConfiguration);
     gherkinScenarioParser.FeatureEvent += (s, e) => features.Add(e.EventInfo);
     var gherkinEventListener = new GherkinEventListener();
     IListener listener = new CompositeGherkinListener(gherkinEventListener, gherkinScenarioParser);
     var newEvents = new List<GherkinParseEvent>();
     var parser = new Parser(listener);
     try
     {
         parser.Scan(content);
     }
     catch (Exception e)
     {
         var match = new Regex(@"^Line: (?<lineNumber>\d+). (\w+\s*)+ '(?<lineText>.*)'$").Match(e.Message);
         if (match.Success && (e is ParseException))
         {
             var line = int.Parse(match.Groups["lineNumber"].Value);
             var lineInFile = new LineInFile(line - 1);
             var text = match.Groups["lineText"].Value;
             var token = new Token(text, lineInFile);
             var error = new Token(e.Message, lineInFile);
             newEvents.Add(new GherkinParseEvent(GherkinTokenType.SyntaxError, token, error));
         }
     }
     finally
     {
         newEvents.AddRange(ToZeroBasedLines(gherkinEventListener).ToList());
     }
     return new Tuple<List<GherkinParseEvent>, List<Feature>>(newEvents, features);
 }
Esempio n. 22
0
 private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> CreateTag(Token token, SnapshotSpan span, GherkinTokenType tokenType, string text)
 {
     foreach (var row in token.Content.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
     {
         string rowText = row.Trim(WhiteSpaces.Chars);
         var idx = text.IndexOf(rowText, StringComparison.Ordinal);
         if (idx == -1)
             continue;
         ITextSnapshotLine containingLine = span.Start.GetContainingLine();
         var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, rowText.Length));
         var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType));
         return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);
     }
     return null;
 }
Esempio n. 23
0
 public void Comment(Token comment)
 {
     events.Add(new GherkinParseEvent(GherkinTokenType.Comment, comment));
 }
Esempio n. 24
0
 public void Comment(Token comment)
 {
 }
Esempio n. 25
0
 public void Examples(Token keyword, Token name)
 {
     events.Add(new GherkinParseEvent(GherkinTokenType.Examples, keyword, name));
 }
Esempio n. 26
0
 public void DocString(Token docString)
 {
     var docStringText = docString.Content;
     events.Enqueue(new DocStringEvent(docStringText, e => DocStringEvent.Invoke(this, new EventArgs<string>(docStringText))));
 }
Esempio n. 27
0
 public void Scenario(Token keyword, Token title)
 {
     events.Add(new GherkinParseEvent(GherkinTokenType.Scenario, keyword, title));
 }
Esempio n. 28
0
 public void Examples(Token keyword, Token name)
 {
     events.Enqueue(new ExamplesEvent(e => ExamplesEvent.Invoke(this, new EventArgs())));
 }
Esempio n. 29
0
 public void Tag(Token tag)
 {
     if (tag.Content != "@") //bug in gherkin parser?
     {
         var previous = events.LastOrDefault() ?? new GherkinParseEvent(GherkinTokenType.SyntaxError);
         if (previous.GherkinTokenType == GherkinTokenType.Tag && tag.LineInFile.Line == previous.Tokens[0].LineInFile.Line)
             previous.Tokens.Add(tag);
         else
             events.Add(new GherkinParseEvent(GherkinTokenType.Tag, tag));
     }
 }
 public void DocString(Token docString)
 {
     listeners.ForEach(_ => _.DocString(docString));
 }