public void Should_be_equal_if_all_tokens_are_equal()
        {
            var e1 = new GherkinParseEvent(GherkinTokenType.Feature, new Token("aaa", new LineInFile(1)), new Token("bbb", new LineInFile(2)));
            var e2 = new GherkinParseEvent(GherkinTokenType.Feature, new Token("aaa", new LineInFile(1)), new Token("bbb", new LineInFile(2)));

            Assert.AreEqual(e1, e2);
        }
        public void Should_not_be_equal_if_all_tokens_differ_by_text()
        {
            var e1 = new GherkinParseEvent(GherkinTokenType.Feature, new Token("aaa", new LineInFile(1)));
            var e2 = new GherkinParseEvent(GherkinTokenType.Feature, new Token("bbb", new LineInFile(1)));

            Assert.AreNotEqual(e1, e2);
        }
        public void Should_be_equal_if_same_evt_and_no_tags()
        {
            var e1 = new GherkinParseEvent(GherkinTokenType.Feature);
            var e2 = new GherkinParseEvent(GherkinTokenType.Feature);

            Assert.AreEqual(e1, e2);
        }
        public void Should_not_be_equal_if_differnet_number_of_tokens()
        {
            var e1 = new GherkinParseEvent(GherkinTokenType.Feature);
            var e2 = new GherkinParseEvent(GherkinTokenType.Feature, new Token("x", new LineInFile(1)));

            Assert.AreNotEqual(e1, e2);
        }
Beispiel #5
0
        private void NotifyChanges(ITextSnapshot textSnapshot, IEnumerable <GherkinParseEvent> newAndChanged)
        {
            var linesChanged = newAndChanged
                               .Where(_ => _.Tokens.Any())
                               .Select(_ => _.Tokens[0].LineInFile.Line)
                               .Distinct().ToArray();

            if (!linesChanged.Any())
            {
                return;
            }
            int from          = linesChanged.Min();
            int to            = linesChanged.Max();
            var previousEvent = new GherkinParseEvent(GherkinTokenType.Feature, new Token("", new LineInFile(0)));

            for (int i = from; i <= to; i++)
            {
                ITextSnapshotLine line = textSnapshot.GetLineFromLineNumber(i);
                var s = new SnapshotSpan(textSnapshot, line.Start, line.Length);
                GherkinParseEvent evt = newAndChanged.FirstOrDefault(_ => _.Tokens.Any() && _.Tokens[0].LineInFile.Line == i) ??
                                        new GherkinParseEvent(previousEvent.GherkinTokenType, new Token("", new LineInFile(i)));
                TokenParserEvent.Invoke(this, new TokenParserEventArgs(evt, s));
                previousEvent = evt;
            }
            var lastLine = textSnapshot.GetLineFromLineNumber(to);

            TokenParserEvent.Invoke(this, new TokenParserEventArgs(new GherkinParseEvent(GherkinTokenType.Eof), new SnapshotSpan(textSnapshot, lastLine.Start, 0)));
        }
        public bool Equals(GherkinParseEvent obj)
        {
            if (obj == null)
                return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != GetType()) return false;

            return obj.GherkinTokenType == GherkinTokenType
                &&  TokensAreEqual(obj);
        }
 private bool TokensAreEqual(GherkinParseEvent other)
 {
     if (other.Tokens.Count != Tokens.Count)
         return false;
     for (int i = 0; i < Tokens.Count; i++)
     {
         if (Tokens[i] != other.Tokens[i])
             return false;
     }
     return true;
 }
        public void Should_tag_scenario_with_title_spanning_multiple_lines()
        {
            var gherkinStepTagger = new GherkinStepTagger();
            var line = new LineInFile(0);
            var evt = new GherkinParseEvent(GherkinTokenType.Scenario, new Token("Scenario", line), new Token("title\n\tbar", line));

            ITextSnapshot snapshot = new MockTextSnapshot("bar");
            var span = new SnapshotSpan(snapshot, 0, snapshot.Length);
            var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();
            Assert.AreEqual(GherkinTokenType.ScenarioTitle, tags[0].Tag.Type);
            Assert.AreEqual("bar", tags[0].Span.GetText());
        }
        public void Should_tag_feature_narrative_spanning_multiple_lines()
        {
            var gherkinStepTagger = new GherkinStepTagger();
            var line = new LineInFile(0);
            var evt = new GherkinParseEvent(GherkinTokenType.Feature,
                new Token("Feature", line), new Token("title", line), new Token("foo\r\n\tbar", line));

            ITextSnapshot snapshot = new MockTextSnapshot("\tbar\r\n");
            var span = new SnapshotSpan(snapshot, 0, snapshot.Length);
            var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();
            Assert.AreEqual(GherkinTokenType.FeatureDescription, tags[0].Tag.Type);
            Assert.AreEqual("bar", tags[0].Span.GetText());
        }
Beispiel #10
0
 private bool TokensAreEqual(GherkinParseEvent other)
 {
     if (other.Tokens.Count != Tokens.Count)
     {
         return(false);
     }
     for (int i = 0; i < Tokens.Count; i++)
     {
         if (Tokens[i] != other.Tokens[i])
         {
             return(false);
         }
     }
     return(true);
 }
        public void Should_tag_feature_with_title()
        {
            var gherkinStepTagger = new GherkinStepTagger();
            var line = new LineInFile(0);
            var evt = new GherkinParseEvent(GherkinTokenType.Feature,
                new Token("Feature", line), new Token("title", line), new Token("foo", line));

            ITextSnapshot snapshot = new MockTextSnapshot("Feature: title");
            var span = new SnapshotSpan(snapshot, 0, snapshot.Length);
            var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();
            Assert.AreEqual(GherkinTokenType.Feature, tags[0].Tag.Type);
            Assert.AreEqual("Feature", tags[0].Span.GetText());
            Assert.AreEqual(GherkinTokenType.FeatureTitle, tags[1].Tag.Type);
            Assert.AreEqual("title", tags[1].Span.GetText());
        }
Beispiel #12
0
        public bool Equals(GherkinParseEvent obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (obj.GetType() != GetType())
            {
                return(false);
            }

            return(obj.GherkinTokenType == GherkinTokenType &&
                   TokensAreEqual(obj));
        }
Beispiel #13
0
        private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleDocString(SnapshotSpan span, GherkinParseEvent evt)
        {
            var text = span.GetText().Trim(WhiteSpaces.Chars);

            if (text == "\"\"\"")
            {
                return(HandleText(span, GherkinTokenType.Tag, "\""));
            }

            //TODO: dont color the spaces that will be removed
            ITextSnapshotLine containingLine = span.Start.GetContainingLine();
            var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position, containingLine.Length));
            var tagSpan   = new TagSpan <GherkinTokenTag>(tokenSpan, new GherkinTokenTag(evt.GherkinTokenType));

            return(new[] { new Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> >(tokenSpan, tagSpan) });
        }
Beispiel #14
0
 private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleTableHeader(SnapshotSpan span, GherkinParseEvent evt)
 {
     cellToggle = false;
     return(TableItem(span, evt.GherkinTokenType));
 }
Beispiel #15
0
        private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleTableCell(SnapshotSpan span, GherkinParseEvent evt)
        {
            var tokenType = cellToggle ? GherkinTokenType.TableCell : GherkinTokenType.TableCellAlt;

            cellToggle = !cellToggle;
            return(TableItem(span, tokenType));
        }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTableHeader(SnapshotSpan span, GherkinParseEvent evt)
 {
     cellToggle = false;
     return TableItem(span, evt.GherkinTokenType);
 }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTableCell(SnapshotSpan span, GherkinParseEvent evt)
 {
     var tokenType = cellToggle ? GherkinTokenType.TableCell : GherkinTokenType.TableCellAlt;
     cellToggle = !cellToggle;
     return TableItem(span, tokenType);
 }
Beispiel #18
0
        private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleSpan(SnapshotSpan span, GherkinParseEvent evt)
        {
            ITextSnapshotLine containingLine = span.Start.GetContainingLine();
            var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position, containingLine.Length));
            var tagSpan   = new TagSpan <GherkinTokenTag>(tokenSpan, new GherkinTokenTag(evt.GherkinTokenType));

            yield return(new Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> >(tokenSpan, tagSpan));
        }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTag(SnapshotSpan span, GherkinParseEvent evt, GherkinTokenType tokenType, GherkinTokenType tokenTitleType)
 {
     if (!evt.Tokens.Any())
         yield break;
     var t1 = HandleType(span, evt.Tokens.First(), tokenType);
     if (t1 != null) yield return t1;
     if (evt.Tokens.Count >= 2)
     {
         var t2 = HandleTitle(span, evt.Tokens[1], tokenTitleType);
         foreach (var tuple in t2)
             yield return tuple;
     }
 }
Beispiel #20
0
 private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleBackground(SnapshotSpan span, GherkinParseEvent evt)
 {
     return(HandleTag(span, evt, GherkinTokenType.Background, GherkinTokenType.BackgroundTitle));
 }
 public TokenParserEventArgs(GherkinParseEvent evt, SnapshotSpan snapshotSpan)
 {
     Event = evt;
     SnapshotSpan = snapshotSpan;
 }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleSpan(SnapshotSpan span, GherkinParseEvent evt)
 {
     ITextSnapshotLine containingLine = span.Start.GetContainingLine();
     var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position, containingLine.Length));
     var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(evt.GherkinTokenType));
     yield return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);
 }
Beispiel #23
0
 private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleScenario(SnapshotSpan span, GherkinParseEvent evt)
 {
     return(HandleTag(span, evt, GherkinTokenType.Scenario, GherkinTokenType.ScenarioTitle));
 }
 private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> CreateTag(Token token, SnapshotSpan span, GherkinParseEvent evt)
 {
     var text = span.GetText();
     return CreateTag(token, span, evt.GherkinTokenType, text);
 }
 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;
     }
 }
 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;
 }
Beispiel #27
0
        private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleTag(SnapshotSpan span, GherkinParseEvent evt, GherkinTokenType tokenType, GherkinTokenType tokenTitleType)
        {
            if (!evt.Tokens.Any())
            {
                yield break;
            }
            var t1 = HandleType(span, evt.Tokens.First(), tokenType);

            if (t1 != null)
            {
                yield return(t1);
            }
            if (evt.Tokens.Count >= 2)
            {
                var t2 = HandleTitle(span, evt.Tokens[1], tokenTitleType);
                foreach (var tuple in t2)
                {
                    yield return(tuple);
                }
            }
        }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleFeature(SnapshotSpan span, GherkinParseEvent evt)
 {
     if (!evt.Tokens.Any())
         yield break;
     var t1 = HandleType(span, evt.Tokens.First(), GherkinTokenType.Feature);
     if (t1 != null) yield return t1;
     if (evt.Tokens.Count >= 2)
     {
         var t2 = HandleTitle(span, evt.Tokens[1], GherkinTokenType.FeatureTitle);
         foreach (var tuple in t2)
             yield return tuple;
     }
     if (evt.Tokens.Count == 3)
     {
         var t3 = HandleTitle(span, evt.Tokens[2], GherkinTokenType.FeatureDescription);
         foreach (var tuple in t3)
             yield return tuple;
     }
 }
Beispiel #29
0
        private Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > CreateTag(Token token, SnapshotSpan span, GherkinParseEvent evt)
        {
            var text = span.GetText();

            return(CreateTag(token, span, evt.GherkinTokenType, text));
        }
 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;
         }
     }
 }
Beispiel #31
0
        private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleFeature(SnapshotSpan span, GherkinParseEvent evt)
        {
            if (!evt.Tokens.Any())
            {
                yield break;
            }
            var t1 = HandleType(span, evt.Tokens.First(), GherkinTokenType.Feature);

            if (t1 != null)
            {
                yield return(t1);
            }
            if (evt.Tokens.Count >= 2)
            {
                var t2 = HandleTitle(span, evt.Tokens[1], GherkinTokenType.FeatureTitle);
                foreach (var tuple in t2)
                {
                    yield return(tuple);
                }
            }
            if (evt.Tokens.Count == 3)
            {
                var t3 = HandleTitle(span, evt.Tokens[2], GherkinTokenType.FeatureDescription);
                foreach (var tuple in t3)
                {
                    yield return(tuple);
                }
            }
        }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTag(SnapshotSpan span, GherkinParseEvent evt)
 {
     var tags = new List<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>>();
     foreach (var token in evt.Tokens)
         tags.AddRange(HandleTitle(span, token, GherkinTokenType.Tag));
     return tags;
 }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleScenario(SnapshotSpan span, GherkinParseEvent evt)
 {
     return HandleTag(span, evt, GherkinTokenType.Scenario, GherkinTokenType.ScenarioTitle);
 }
        public void Should_tag_tags()
        {
            var gherkinStepTagger = new GherkinStepTagger();
            var line = new LineInFile(0);
            var evt = new GherkinParseEvent(GherkinTokenType.Tag, new Token("Tag", line), new Token("@foo", line), new Token("@bar", line), new Token("@baz", line));

            ITextSnapshot snapshot = new MockTextSnapshot("@foo @bar @baz");
            var span = new SnapshotSpan(snapshot, 0, snapshot.Length);
            var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();
            Assert.AreEqual(GherkinTokenType.Tag, tags[0].Tag.Type);
            Assert.AreEqual("@foo", tags[0].Span.GetText());
            Assert.AreEqual(GherkinTokenType.Tag, tags[1].Tag.Type);
            Assert.AreEqual("@bar", tags[1].Span.GetText());
            Assert.AreEqual(GherkinTokenType.Tag, tags[2].Tag.Type);
            Assert.AreEqual("@baz", tags[2].Span.GetText());
        }
        private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleDocString(SnapshotSpan span, GherkinParseEvent evt)
        {
            var text = span.GetText().Trim(WhiteSpaces.Chars);
            if (text == "\"\"\"")
                return HandleText(span, GherkinTokenType.Tag, "\"");

            //TODO: dont color the spaces that will be removed
            ITextSnapshotLine containingLine = span.Start.GetContainingLine();
            var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position, containingLine.Length));
            var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(evt.GherkinTokenType));
            return new[] { new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan) };
        }
Beispiel #36
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);
                }
            }
        }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleBackground(SnapshotSpan span, GherkinParseEvent evt)
 {
     return HandleTag(span, evt, GherkinTokenType.Background, GherkinTokenType.BackgroundTitle);
 }
Beispiel #38
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);
            }
        }
Beispiel #39
0
 private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleStep(SnapshotSpan span, GherkinParseEvent evt)
 {
     return(HandleTag(span, evt, GherkinTokenType.Step, GherkinTokenType.StepText));
 }
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleStep(SnapshotSpan span, GherkinParseEvent evt)
 {
     return HandleTag(span, evt, GherkinTokenType.Step, GherkinTokenType.StepText);
 }
Beispiel #41
0
        private IEnumerable <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > > HandleTag(SnapshotSpan span, GherkinParseEvent evt)
        {
            var tags = new List <Tuple <SnapshotSpan, TagSpan <GherkinTokenTag> > >();

            foreach (var token in evt.Tokens)
            {
                tags.AddRange(HandleTitle(span, token, GherkinTokenType.Tag));
            }
            return(tags);
        }
Beispiel #42
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);
                    }
                }
            }
        }
Beispiel #43
0
 private void NotifyChanges(ITextSnapshot textSnapshot, IEnumerable<GherkinParseEvent> newAndChanged)
 {
     var linesChanged = newAndChanged
         .Where(_ => _.Tokens.Any())
         .Select(_ => _.Tokens[0].LineInFile.Line)
         .Distinct().ToArray();
     int from = linesChanged.Min();
     int to = linesChanged.Max();
     var previousEvent = new GherkinParseEvent(GherkinTokenType.Feature, new Token("", new LineInFile(0)));
     for (int i = from; i <= to; i++)
     {
         ITextSnapshotLine line = textSnapshot.GetLineFromLineNumber(i);
         var s = new SnapshotSpan(textSnapshot, line.Start, line.Length);
         GherkinParseEvent evt = newAndChanged.FirstOrDefault(_ => _.Tokens.Any() && _.Tokens[0].LineInFile.Line == i) ??
             new GherkinParseEvent(previousEvent.GherkinTokenType, new Token("", new LineInFile(i)));
         TokenParserEvent.Invoke(this, new TokenParserEventArgs(evt, s));
         previousEvent = evt;
     }
     var lastLine = textSnapshot.GetLineFromLineNumber(to);
     TokenParserEvent.Invoke(this, new TokenParserEventArgs(new GherkinParseEvent(GherkinTokenType.Eof), new SnapshotSpan(textSnapshot, lastLine.Start, 0)));
 }
 public TokenParserEventArgs(GherkinParseEvent evt, SnapshotSpan snapshotSpan)
 {
     Event        = evt;
     SnapshotSpan = snapshotSpan;
 }