How to use GherkinLine method of Gherkin.GherkinLine class

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

GherkinParser.cs

Source:GherkinParser.cs Github

copy

Full Screen

...108 mapping = dialect.WhyKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeWhy) });109 foreach (var map in mapping)110 {111 if (current >= lines.Length) yield break;112 var gherkinLine = new GherkinLine(lines[current], current);113 if (gherkinLine.StartsWith(map.Key))114 {115 yield return CreateNarrative(map, gherkinLine.GetRestTrimmed(map.Key.Length).Trim(), lineNumber + current);116 current++;117 hasTopLevel = true;118 break;119 }120 }121 if (hasTopLevel)122 {123 hasTopLevel = false;124 // process And , But125 mapping = dialect.AndStepKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeAndWhy) })126 .Union(dialect.ButStepKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeButWhy) }));127 var gotOne = false;128 while (true)129 {130 foreach (var map in mapping)131 {132 if (current >= lines.Length) yield break;133 var gherkinLine = new GherkinLine(lines[current], current);134 if (gherkinLine.StartsWith(map.Key))135 {136 yield return CreateNarrative(map, gherkinLine.GetRestTrimmed(map.Key.Length), lineNumber + current);137 current++;138 gotOne = true;139 break;140 }141 }142 if (!gotOne) break;143 gotOne = false;144 }145 }146 mapping = dialect.WhoKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeWho) });147 foreach (var map in mapping)148 {149 if (current >= lines.Length) yield break;150 var gherkinLine = new GherkinLine(lines[current], current);151 if (gherkinLine.StartsWith(map.Key))152 {153 yield return CreateNarrative(map, gherkinLine.GetRestTrimmed(map.Key.Length), lineNumber + current);154 current++;155 hasTopLevel = true;156 break;157 }158 }159 if (hasTopLevel)160 {161 hasTopLevel = false;162 // process And , But163 mapping = dialect.AndStepKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeAndWho) })164 .Union(dialect.ButStepKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeButWho) }));165 var gotOne = false;166 while (true)167 {168 foreach (var map in mapping)169 {170 if (current >= lines.Length) yield break;171 var gherkinLine = new GherkinLine(lines[current], current);172 if (gherkinLine.StartsWith(map.Key))173 {174 yield return CreateNarrative(map, gherkinLine.GetRestTrimmed(map.Key.Length), lineNumber + current);175 current++;176 gotOne = true;177 break;178 }179 }180 if (!gotOne) break;181 gotOne = false;182 }183 }184 mapping = dialect.WhereKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeWhere) });185 foreach (var map in mapping)186 {187 if (current >= lines.Length) yield break;188 var gherkinLine = new GherkinLine(lines[current], current);189 if (gherkinLine.StartsWith(map.Key))190 {191 yield return CreateNarrative(map, gherkinLine.GetRestTrimmed(map.Key.Length), lineNumber + current);192 current++;193 hasTopLevel = true;194 break;195 }196 }197 if (hasTopLevel)198 {199 hasTopLevel = false;200 // process And , But201 mapping = dialect.AndStepKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeAndWhere) })202 .Union(dialect.ButStepKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeButWhere) }));203 var gotOne = false;204 while (true)205 {206 foreach (var map in mapping)207 {208 if (current >= lines.Length) yield break;209 var gherkinLine = new GherkinLine(lines[current], current);210 if (gherkinLine.StartsWith(map.Key))211 {212 yield return CreateNarrative(map, gherkinLine.GetRestTrimmed(map.Key.Length), lineNumber + current);213 current++;214 gotOne = true;215 break;216 }217 }218 if (!gotOne) break;219 gotOne = false;220 }221 }222 mapping = dialect.WhatKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeWhat) });223 foreach (var map in mapping)224 {225 if (current >= lines.Length) yield break;226 var gherkinLine = new GherkinLine(lines[current], current);227 if (gherkinLine.StartsWith(map.Key))228 {229 yield return CreateNarrative(map, gherkinLine.GetRestTrimmed(map.Key.Length), lineNumber + current);230 current++;231 hasTopLevel = true;232 break;233 }234 }235 if (hasTopLevel)236 {237 hasTopLevel = false;238 // process And , But239 mapping = dialect.AndStepKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeAndWhat) })240 .Union(dialect.ButStepKeywords.Select(w => new NarrativeMap { Key = w, Type = typeof(NarrativeButWhat) }));241 foreach (var map in mapping)242 {243 if (current >= lines.Length) yield break;244 var gherkinLine = new GherkinLine(lines[current], current);245 if (gherkinLine.StartsWith(map.Key))246 {247 yield return CreateNarrative(map, gherkinLine.GetRestTrimmed(map.Key.Length), lineNumber + current);248 current++;249 break;250 }251 }252 }253 }254 private struct NarrativeMap255 {256 public string Key;257 public Type Type;258 }...

Full Screen

Full Screen

GherkinSimpleParser.cs

Source:GherkinSimpleParser.cs Github

copy

Full Screen

...71 }72 private Token ToToken(string line)73 {74 var location = new Ast.Location(1);75 return new Token(new GherkinLine(line, 1), location);76 }77 public Token ParseToken(string line)78 {79 Token token = ToToken(line);80 if (TokenMatcher.Match_FeatureLine(token) ||81 TokenMatcher.Match_ScenarioLine(token) ||82 TokenMatcher.Match_ScenarioOutlineLine(token) ||83 TokenMatcher.Match_BackgroundLine(token) ||84 TokenMatcher.Match_ExamplesLine(token) ||85 TokenMatcher.Match_StepLine(token) ||86 TokenMatcher.Match_TagLine(token) ||87 TokenMatcher.Match_TableRow(token) ||88 SimpleMatchLanguage(token) ||89 TokenMatcher.Match_DocStringSeparator(token))...

Full Screen

Full Screen

GherkinLine.cs

Source:GherkinLine.cs Github

copy

Full Screen

...5using Gherkin.Ast;67namespace Gherkin8{9 public class GherkinLine : IGherkinLine10 {11 private static char[] inlineWhitespaceChars = new char[] { ' ', '\t', '\u00A0'};1213 private readonly string lineText;14 private readonly string trimmedLineText;15 public int LineNumber { get; private set; }1617 public GherkinLine(string line, int lineNumber)18 {19 this.LineNumber = lineNumber;2021 this.lineText = line;22 this.trimmedLineText = this.lineText.TrimStart();23 }2425 public void Detach()26 {27 //nop28 }2930 public int Indent31 {32 get { return lineText.Length - trimmedLineText.Length; }33 }3435 public bool IsEmpty()36 {37 return trimmedLineText.Length == 0;38 }3940 public bool StartsWith(string text)41 {42 return trimmedLineText.StartsWith(text);43 }4445 public bool StartsWithTitleKeyword(string text)46 {47 return StringUtils.StartsWith(trimmedLineText, text) &&48 StartsWithFrom(trimmedLineText, text.Length, GherkinLanguageConstants.TITLE_KEYWORD_SEPARATOR);49 }5051 private static bool StartsWithFrom(string text, int textIndex, string value)52 {53 return string.CompareOrdinal(text, textIndex, value, 0, value.Length) == 0;54 }5556 public string GetLineText(int indentToRemove)57 {58 if (indentToRemove < 0 || indentToRemove > Indent)59 return trimmedLineText;6061 return lineText.Substring(indentToRemove);62 }6364 public string GetRestTrimmed(int length)65 {66 return trimmedLineText.Substring(length).Trim();67 }6869 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;8081 if (tagName.IndexOfAny(inlineWhitespaceChars) >= 0)82 throw new InvalidTagException("A tag may not contain whitespace", new Location(LineNumber, position));8384 yield return new GherkinLineSpan(position, tagName);85 position += item.Length;86 }87 position++; // separator88 }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 last96 {97 if (!isBeforeFirst)98 {99 int trimmedStart;100 var cellText = Trim(item.Item1, out trimmedStart);101 var cellPosition = item.Item2 + trimmedStart;102103 if (cellText.Length == 0)104 cellPosition = item.Item2;105106 yield return new GherkinLineSpan(Indent + cellPosition + 1, cellText);107 }108109 isBeforeFirst = false;110 }111 }112113 private IEnumerable<Tuple<string, int>> SplitCells(string row)114 {115 var rowEnum = row.GetEnumerator(); 116117 string cell = "";118 int pos = 0;119 int startPos = 0;120 while (rowEnum.MoveNext()) { ...

Full Screen

Full Screen

GherkinUtil.cs

Source:GherkinUtil.cs Github

copy

Full Screen

...34 ICSharpCode.AvalonEdit.Document.DocumentLine line = document.GetLineByNumber(1);35 while (line != null)36 {37 string line_text = document.GetText(line.Offset, line.TotalLength);38 Token token = new Token(new GherkinLine(line_text, line.LineNumber), location);39 try40 {41 if (s_TokenMatcher.Match_Language(token) && IsSupported(token.MatchedText))42 {43 return token.MatchedText;44 }45 if (line.LineNumber > 5) return DEFAULT_LANGUAGE;46 line = line.NextLine;47 }48 catch49 {50 return DEFAULT_LANGUAGE;51 }52 }...

Full Screen

Full Screen

Lexer.cs

Source:Lexer.cs Github

copy

Full Screen

...17 _tokenReceiver = tokenReceiver;18 }19 public void Lex(string gherkin)20 {21 foreach (var gherkinLine in GetGherkinLines(gherkin))22 {23 MatchAndCallback("^Given (.*)", _tokenReceiver.Given, gherkinLine);24 MatchAndCallback("^When (.*)", _tokenReceiver.When, gherkinLine);25 MatchAndCallback("^Then (.*)", _tokenReceiver.Then, gherkinLine);26 }27 _tokenReceiver.EndOfFile();28 }29 private static void MatchAndCallback(string pattern, Action<string> callback, string gherkinLine)30 {31 var m = Regex.Match(gherkinLine, pattern);32 33 while (m.Success)34 {35 var theText = m.Groups[1].Value;36 callback(theText);37 38 m = m.NextMatch();39 }40 }41 private static string[] GetGherkinLines(string gherkin)42 {43 return gherkin.Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);44 }45 }46}...

Full Screen

Full Screen

TokenScanner.cs

Source:TokenScanner.cs Github

copy

Full Screen

...26 public virtual Token Read()27 {28 var line = reader.ReadLine();29 var location = new Ast.Location(++lineNumber);30 return line == null ? new Token(null, location) : new Token(new GherkinLine(line, lineNumber), location);31 }32 } ...

Full Screen

Full Screen

GherkinLine

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using TechTalk.SpecFlow;7using Gherkin;8using System.Text.RegularExpressions;9{10 {11 [Given(@"I have entered (.*) into the calculator")]12 public void GivenIHaveEnteredIntoTheCalculator(int p0)13 {14 Console.WriteLine("I have entered {0} into the calculator", p0);15 }16 [When(@"I press add")]17 public void WhenIPressAdd()18 {19 Console.WriteLine("I press add");20 }21 [Then(@"the result should be (.*) on the screen")]22 public void ThenTheResultShouldBeOnTheScreen(int p0)23 {24 Console.WriteLine("the result should be {0} on the screen", p0);25 }26 [Given(@"I have entered (.*) into the calculator")]27 public void GivenIHaveEnteredIntoTheCalculator(string p0)28 {29 Console.WriteLine("I have entered {0} into the calculator", p0);30 }31 [Given(@"I have entered (.*) into the calculator")]32 public void GivenIHaveEnteredIntoTheCalculator(double p0)33 {34 Console.WriteLine("I have entered {0} into the calculator", p0);35 }36 [Given(@"I have entered (.*) into the calculator")]37 public void GivenIHaveEnteredIntoTheCalculator(decimal p0)38 {39 Console.WriteLine("I have entered {0} into the calculator", p0);40 }41 [Given(@"I have entered (.*) into the calculator")]42 public void GivenIHaveEnteredIntoTheCalculator(bool p0)43 {44 Console.WriteLine("I have entered {0} into the calculator", p0);45 }46 [Given(@"I have entered (.*) into the calculator")]47 public void GivenIHaveEnteredIntoTheCalculator(char p0)48 {49 Console.WriteLine("I have entered {0} into the calculator", p0);50 }51 [Given(@"I have entered (.*) into the calculator")]

Full Screen

Full Screen

GherkinLine

Using AI Code Generation

copy

Full Screen

1using Gherkin;2using System;3{4 {5 static void Main(string[] args)6 {7 string line = "Feature: My Feature";8 GherkinLine gherkinLine = new GherkinLine(line, 1);9 Console.WriteLine(gherkinLine.GetLineText());10 Console.WriteLine(gherkinLine.GetLineText(2));11 Console.WriteLine(gherkinLine.GetLineText(3));12 Console.WriteLine(gherkinLine.GetLineText(4));13 Console.WriteLine(gherkinLine.GetLineText(5));14 Console.WriteLine(gherkinLine.GetLineText(6));15 Console.WriteLine(gherkinLine.GetLineText(7));16 Console.WriteLine(gherkinLine.GetLineText(8));17 Console.WriteLine(gherkinLine.GetLineText(9));18 Console.WriteLine(gherkinLine.GetLineText(10));19 Console.WriteLine(gherkinLine.GetLineText(11));20 Console.WriteLine(gherkinLine.GetLineText(12));21 Console.WriteLine(gherkinLine.GetLineText(13));22 Console.WriteLine(gherkinLine.GetLineText(14));23 Console.WriteLine(gherkinLine.GetLineText(15));24 Console.WriteLine(gherkinLine.GetLineText(16));25 Console.WriteLine(gherkinLine.GetLineText(17));26 Console.WriteLine(gherkinLine.GetLineText(18));27 Console.WriteLine(gherkinLine.GetLineText(19));28 Console.WriteLine(gherkinLine.GetLineText(20));29 Console.WriteLine(gherkinLine.GetLineText(21));30 Console.WriteLine(gherkinLine.GetLineText(22));31 Console.WriteLine(gherkinLine.GetLineText(23));32 Console.WriteLine(gherkinLine.GetLineText(24));33 Console.WriteLine(gherkinLine.GetLineText(25));34 Console.WriteLine(gherkinLine.GetLineText(26));35 Console.WriteLine(gherkinLine.GetLineText(27));36 Console.WriteLine(gherkinLine.GetLineText(28));37 Console.WriteLine(gherkinLine.GetLineText(29));38 Console.WriteLine(gherkinLine.GetLineText(30));39 Console.WriteLine(gherkinLine.GetLineText(31));40 Console.WriteLine(gh

Full Screen

Full Screen

GherkinLine

Using AI Code Generation

copy

Full Screen

1Gherkin.GherkinLine line = new Gherkin.GherkinLine("Scenario: Test", 1);2Console.WriteLine(line.GherkinDialect);3Gherkin.GherkinDialect dialect = new Gherkin.GherkinDialect("en");4Gherkin.GherkinLine line = new Gherkin.GherkinLine("Scenario: Test", 1);5Console.WriteLine(dialect.GetGherkinKeywordForLine(line));6Gherkin.GherkinDialectProvider dialectProvider = new Gherkin.GherkinDialectProvider();7Gherkin.GherkinLine line = new Gherkin.GherkinLine("Scenario: Test", 1);8Console.WriteLine(dialectProvider.GetDialect("en").GetGherkinKeywordForLine(line));9Gherkin.Parser parser = new Gherkin.Parser(new Gherkin.AstBuilder());10Gherkin.GherkinDocument document = parser.Parse("Scenario: Test");11Console.WriteLine(document.Feature.Children[0].Keyword);12Gherkin.TokenMatcher matcher = new Gherkin.TokenMatcher();13Gherkin.GherkinLine line = new Gherkin.GherkinLine("Scenario: Test", 1);14Console.WriteLine(matcher.GetGherkinKeywordTypeForLine(line));15Gherkin.TokenScanner scanner = new Gherkin.TokenScanner();16Gherkin.GherkinLine line = new Gherkin.GherkinLine("Scenario: Test", 1);17Console.WriteLine(scanner.Scan(line.LineText));18Gherkin.Token token = new Gherkin.Token(0, 0, "Scenario: Test");19Console.WriteLine(token.GherkinDialect);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-dotnet automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful