Best Gherkin-dotnet code snippet using Gherkin.GherkinLine.StartsWith
GherkinParser.cs
Source:GherkinParser.cs
...78 var lineNumber = rule.Location.Line;79 var hasOneRule = false;80 foreach (var meta in dialect.MetaKeywords)81 {82 if (desc.StartsWith(meta.Trim()))83 {84 lineNumber++;85 foreach (Match match in Regex.Matches(desc, @"\*{2}(.*?)\*{2}", RegexOptions.Singleline))86 {87 var comment = match.Groups[0].Value.Trim().TrimStart(new char[] { '*' }).TrimEnd(new char[] { '*' }).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);88 foreach (var line in comment)89 {90 if (line.IndexOf(":") > -1)91 {92 yield return new RuleMeta(93 new Location(++lineNumber, 0),94 line.Substring(0, line.IndexOf(":")).Trim(),95 line.Substring(line.IndexOf(":") + 1).Trim());96 hasOneRule = true;97 }98 }99 desc = CleanDescription(desc.Replace(match.Groups[0].Value, string.Empty));100 }101 }102 }103 if (hasOneRule) lineNumber = lineNumber + 2;104 var lines = desc.Split(new[] { Environment.NewLine }, StringSplitOptions.None);105 var current = 0;106 var hasTopLevel = false;107 IEnumerable<NarrativeMap> mapping;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 }259 private static INarrative CreateNarrative(NarrativeMap map, string description, int lineNumber)...
GherkinLine.cs
Source:GherkinLine.cs
...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 {
...
GherkinUtil.cs
Source:GherkinUtil.cs
...20 }21 public static bool IsGherkinHighlighting(string highlighingName)22 {23 return (highlighingName != null) &&24 highlighingName.StartsWith(GherkinHighlightingBaseName, StringComparison.CurrentCulture);25 }26 /// <summary>27 /// Get current Gherkin language setting by scanning first 5 lines28 /// </summary>29 /// <param name="document"></param>30 /// <returns>language defined in tag or English as default language</returns>31 public static string CurrentLanguage(ICSharpCode.AvalonEdit.Document.TextDocument document)32 {33 var location = new Ast.Location();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);...
StartsWith
Using AI Code Generation
1using Gherkin;2{3 {4 static void Main(string[] args)5 {6 GherkinLine line = new GherkinLine("Feature: Hello World", 1);7 System.Console.WriteLine(line.StartsWith("Feature"));8 }9 }10}11using Gherkin;12using Gherkin.Ast;13{14 {15 static void Main(string[] args)16 {17 var feature = new Feature(new List<Tag>(), new GherkinKeyword("Feature"), "Hello World", "", new List<ScenarioDefinition>());18 System.Console.WriteLine(feature.StartsWith("Feature"));19 }20 }21}22using Gherkin;23using Gherkin.Ast;24{25 {26 static void Main(string[] args)27 {28 var scenario = new Scenario(new List<Tag>(), new GherkinKeyword("Scenario"), "Hello World", "", new List<Step>());29 System.Console.WriteLine(scenario.StartsWith("Scenario"));30 }31 }32}33using Gherkin;34using Gherkin.Ast;35{36 {37 static void Main(string[] args)38 {39 var scenarioOutline = new ScenarioOutline(new List<Tag>(), new GherkinKeyword("Scenario Outline"), "Hello World", "", new List<Step>(), new List<Examples>());40 System.Console.WriteLine(scenarioOutline.StartsWith("Scenario Outline"));41 }42 }43}44using Gherkin;45using Gherkin.Ast;46{47 {48 static void Main(string[] args)49 {50 var background = new Background(new List<Tag>(), new GherkinKeyword("Background"), "Hello World", "", new List<Step>());51 System.Console.WriteLine(background.StartsWith("Background"));52 }53 }54}
StartsWith
Using AI Code Generation
1using System;2using System.IO;3using Gherkin;4{5{6static void Main(string[] args)7{8GherkinLine line = new GherkinLine("*", 0);9Console.WriteLine(line.StartsWith("*"));10Console.ReadLine();11}12}13}14using System;15using System.IO;16using Gherkin;17{18{19static void Main(string[] args)20{21GherkinLine line = new GherkinLine("*", 0);22Console.WriteLine(line.StartsWith("a"));23Console.ReadLine();24}25}26}27using System;28using System.IO;29using Gherkin;30{31{32static void Main(string[] args)33{34GherkinLine line = new GherkinLine("*", 0);35Console.WriteLine(line.StartsWith("a", StringComparison.InvariantCulture));36Console.ReadLine();37}38}39}40using System;41using System.IO;42using Gherkin;43{44{45static void Main(string[] args)46{47GherkinLine line = new GherkinLine("*", 0);48Console.WriteLine(line.StartsWith("a", StringComparison.InvariantCultureIgnoreCase));49Console.ReadLine();50}51}52}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!