How to use InvalidTagException method of Gherkin.InvalidTagException class

Best Gherkin-dotnet code snippet using Gherkin.InvalidTagException.InvalidTagException

Run Gherkin-dotnet automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ParserException.cs

Source: ParserException.cs Github

copy
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Gherkin.Ast;
5
6namespace Gherkin
7{
8    public abstract class ParserException : Exception
9    {
10        public Ast.Location Location { get; private set; }
11
12        protected ParserException(string message, Ast.Location location = null) : base(GetMessage(message, location))
13        {
14            Location = location;
15        }
16
17        private static string GetMessage(string message, Ast.Location location)
18        {
19            if (location == null)
20                return message;
21
22            return string.Format("({0}:{1}): {2}", location.Line, location.Column, message);
23        }
24
25    }
26
27    public class AstBuilderException : ParserException
28    {
29        public AstBuilderException(string message, Ast.Location location) : base(message, location)
30        {
31        }
32
33    }
34
35    public class NoSuchLanguageException : ParserException
36    {
37        public NoSuchLanguageException(string language, Ast.Location location = null) :
38            base("Language not supported: " + language, location)
39        {
40            if (language == null) throw new ArgumentNullException("language");
41        }
42
43    }
44
45    public class InvalidTagException : ParserException
46    {
47        public InvalidTagException(string message, Ast.Location location = null) :
48            base(message, location)
49        {
50        }
51    }
52
53    public abstract class TokenParserException : ParserException
54    {
55        protected TokenParserException(string message, Token receivedToken)
56            : base(message, GetLocation(receivedToken))
57        {
58            if (receivedToken == null) throw new ArgumentNullException("receivedToken");
59        }
60
61        private static Ast.Location GetLocation(Token receivedToken)
62        {
63            return receivedToken.IsEOF || receivedToken.Location.Column > 1
64                ? receivedToken.Location
65                : new Ast.Location(receivedToken.Location.Line, receivedToken.Line.Indent + 1);
66        }
67
68    }
69
70    public class UnexpectedTokenException : TokenParserException
71    {
72        public string StateComment { get; private set; }
73
74        public Token ReceivedToken { get; private set; }
75        public string[] ExpectedTokenTypes { get; private set; }
76
77        public UnexpectedTokenException(Token receivedToken, string[] expectedTokenTypes, string stateComment)
78            : base(GetMessage(receivedToken, expectedTokenTypes), receivedToken)
79        {
80            if (receivedToken == null) throw new ArgumentNullException("receivedToken");
81            if (expectedTokenTypes == null) throw new ArgumentNullException("expectedTokenTypes");
82
83            ReceivedToken = receivedToken;
84            ExpectedTokenTypes = expectedTokenTypes;
85            StateComment = stateComment;
86        }
87
88        private static string GetMessage(Token receivedToken, string[] expectedTokenTypes)
89        {
90            return string.Format("expected: {0}, got '{1}'",
91                string.Join(", ", expectedTokenTypes),
92                receivedToken.GetTokenValue().Trim());
93        }
94
95    }
96
97    public class UnexpectedEOFException : TokenParserException
98    {
99        public string StateComment { get; private set; }
100        public string[] ExpectedTokenTypes { get; private set; }
101        public UnexpectedEOFException(Token receivedToken, string[] expectedTokenTypes, string stateComment)
102            : base(GetMessage(expectedTokenTypes), receivedToken)
103        {
104            if (receivedToken == null) throw new ArgumentNullException("receivedToken");
105            if (expectedTokenTypes == null) throw new ArgumentNullException("expectedTokenTypes");
106
107            ExpectedTokenTypes = expectedTokenTypes;
108            StateComment = stateComment;
109        }
110
111        private static string GetMessage(string[] expectedTokenTypes)
112        {
113            return string.Format("unexpected end of file, expected: {0}",
114                string.Join(", ", expectedTokenTypes));
115        }
116    }
117
118    public class CompositeParserException : ParserException
119    {
120        public IEnumerable<ParserException> Errors { get; private set; }
121
122        public CompositeParserException(ParserException[] errors)
123            : base(GetMessage(errors))
124        {
125            if (errors == null) throw new ArgumentNullException("errors");
126
127            Errors = errors;
128        }
129
130        private static string GetMessage(ParserException[] errors)
131        {
132            return "Parser errors:" + Environment.NewLine + string.Join(Environment.NewLine, errors.Select(e => e.Message));
133        }
134    }
135}
Full Screen

GherkinLine.cs

Source: GherkinLine.cs Github

copy
1using System;
2using System.Text.RegularExpressions;
3using System.Collections.Generic;
4using System.Linq;
5using Gherkin.Ast;
6
7namespace Gherkin
8{
9    public class GherkinLine : IGherkinLine
10    {
11        private static char[] inlineWhitespaceChars = new char[] { ' ', '\t', '\u00A0'};
12
13        private readonly string lineText;
14        private readonly string trimmedLineText;
15        public int LineNumber { get; private set; }
16
17        public GherkinLine(string line, int lineNumber)
18        {
19            this.LineNumber = lineNumber;
20
21            this.lineText = line;
22            this.trimmedLineText = this.lineText.TrimStart();
23        }
24
25        public void Detach()
26        {
27            //nop
28        }
29
30        public int Indent
31        {
32            get { return lineText.Length - trimmedLineText.Length; }
33        }
34
35        public bool IsEmpty()
36        {
37            return trimmedLineText.Length == 0;
38        }
39
40        public bool StartsWith(string text)
41        {
42            return trimmedLineText.StartsWith(text);
43        }
44
45        public bool StartsWithTitleKeyword(string text)
46        {
47            return StringUtils.StartsWith(trimmedLineText, text) &&
48                StartsWithFrom(trimmedLineText, text.Length, GherkinLanguageConstants.TITLE_KEYWORD_SEPARATOR);
49        }
50
51        private static bool StartsWithFrom(string text, int textIndex, string value)
52        {
53            return string.CompareOrdinal(text, textIndex, value, 0, value.Length) == 0;
54        }
55
56        public string GetLineText(int indentToRemove)
57        {
58            if (indentToRemove < 0 || indentToRemove > Indent)
59                return trimmedLineText;
60
61            return lineText.Substring(indentToRemove);
62        }
63
64        public string GetRestTrimmed(int length)
65        {
66            return trimmedLineText.Substring(length).Trim();
67        }
68
69        public IEnumerable<GherkinLineSpan> GetTags()
70        {
71            var uncommentedLine = Regex.Split(trimmedLineText, @"\s" + GherkinLanguageConstants.COMMENT_PREFIX)[0];
72            int position = Indent;
73            foreach (string item in uncommentedLine.Split(GherkinLanguageConstants.TAG_PREFIX[0]))
74            {
75                if (item.Length > 0)
76                {
77                    var tagName = GherkinLanguageConstants.TAG_PREFIX + item.TrimEnd(inlineWhitespaceChars);
78                    if (tagName.Length == 1)
79                        continue;
80
81                    if (tagName.IndexOfAny(inlineWhitespaceChars) >= 0)
82                        throw new InvalidTagException("A tag may not contain whitespace", new Location(LineNumber, position));
83
84                    yield return new GherkinLineSpan(position, tagName);
85                    position += item.Length;
86                }
87                position++; // separator
88            }
89        }
90        
91        public IEnumerable<GherkinLineSpan> GetTableCells()
92        {
93            var items = SplitCells(trimmedLineText).ToList();
94            bool isBeforeFirst = true;
95            foreach (var item in items.Take(items.Count - 1)) // skipping the one after last
96            {
97                if (!isBeforeFirst)
98                {
99                    int trimmedStart;
100                    var cellText = Trim(item.Item1, out trimmedStart);
101                    var cellPosition = item.Item2 + trimmedStart;
102
103                    if (cellText.Length == 0)
104                        cellPosition = item.Item2;
105
106                    yield return new GherkinLineSpan(Indent + cellPosition + 1, cellText);
107                }
108
109                isBeforeFirst = false;
110            }
111        }
112
113        private IEnumerable<Tuple<string, int>> SplitCells(string row)
114        {
115            var rowEnum = row.GetEnumerator();            
116
117            string cell = "";
118            int pos = 0;
119            int startPos = 0;
120            while (rowEnum.MoveNext()) {
121                pos++;
122                char c = rowEnum.Current;
123                if (c.ToString() == GherkinLanguageConstants.TABLE_CELL_SEPARATOR) {
124                    yield return Tuple.Create(cell, startPos);
125                    cell = "";
126                    startPos = pos;
127                } else if (c == GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR) {
128                    rowEnum.MoveNext();
129                    pos++;
130                    c = rowEnum.Current;
131                    if (c == GherkinLanguageConstants.TABLE_CELL_NEWLINE_ESCAPE) {
132                        cell += "\n";
133                    } else {
134                        if (c.ToString() != GherkinLanguageConstants.TABLE_CELL_SEPARATOR && c != GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR) {
135                            cell += GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR;
136                        }
137                        cell += c;
138                    }
139                } else {
140                    cell += c;
141                }
142            }
143            yield return Tuple.Create(cell, startPos);
144        }
145
146        private string Trim(string s, out int trimmedStart)
147        {
148            trimmedStart = 0;
149            while (trimmedStart < s.Length && inlineWhitespaceChars.Contains(s[trimmedStart]))
150                trimmedStart++;
151
152            return s.Trim(inlineWhitespaceChars);
153        }
154    }
155}
156
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger InvalidTagException code on LambdaTest Cloud Grid

Execute automation tests with InvalidTagException on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)