Best Gherkin-dotnet code snippet using Gherkin.Parser
Program.cs
Source:Program.cs
...8using System.Text.RegularExpressions;9using System.Xml.Linq;10using ILMerging;11using NConsoler;12namespace ImportGherkinParser13{14 class Program15 {16 static void Main(string[] args)17 {18 Console.WriteLine("Gherkin parser import tool:");19 Console.WriteLine(" + adds signing for the assembly");20 Console.WriteLine(" + generates Language.xml from the parser");21 Console.WriteLine();22 Consolery.Run(typeof(Program), args);23 return;24 }25 static private readonly Regex parserVersionRe = new Regex(@"(?<version>[\d\.]+)");26 [Action("Imports official Gherkin parser to SpecFlow")]27 public static void ImportGherkinParser(28 [Required(Description = "Original gherkin parser, like gherkin-1.0.21.dll")] string gherkinParser,29 [Optional("specflow.snk", "key")] string keyFile,30 [Optional("Gherkin.dll", "out")] string outputFile,31 [Optional("Languages.xml", "lngout")] string languagesOutputFile32 )33 {34 string gherkinParserFullPath = Path.GetFullPath(gherkinParser);35 Version parserVersion = GetParserVersion(gherkinParserFullPath);36 if (parserVersion == null)37 return;38 string keyFullPath = Path.GetFullPath(keyFile);39 string outputFileFullPath = Path.GetFullPath(outputFile);40 string languagesOutputFileFullPath = Path.GetFullPath(languagesOutputFile);41 CreateSignedParser(gherkinParserFullPath, parserVersion, keyFullPath, outputFileFullPath);42 Assembly parserAssembly = LoadParser(outputFileFullPath);43 GenerateLanguageDescriptions(parserAssembly, languagesOutputFileFullPath);44 }45 private static Version GetParserVersion(string gherkinParserFullPath)46 {47 var match = parserVersionRe.Match(Path.GetFileNameWithoutExtension(gherkinParserFullPath));48 if (!match.Success)49 {50 Console.WriteLine("> Unable to detect parser version");51 return null;52 }53 var version = new Version(match.Groups["version"].Value);54 version = new Version(version.Major, version.Minor, version.Build, version.Revision < 0 ? 0 : version.Revision);55 return version;56 }57 private static Assembly LoadParser(string outputFileFullPath)58 {59 Console.WriteLine("Loading imported parser from {0}", outputFileFullPath);60 return Assembly.LoadFrom(outputFileFullPath);61 }62 private static void CreateSignedParser(string gherkinParserFullPath, Version version, string keyFullPath, string outputFileFullPath)63 {64 Console.WriteLine("Generating signed parser...");65 ILMerge ilMerge = new ILMerge();66 ilMerge.KeyFile = keyFullPath;67 ilMerge.Version = version;68 string simpleJsonPath = Path.Combine(Path.GetDirectoryName(gherkinParserFullPath), "com.googlecode.json-simple-json-simple.dll");69 string base46Path = Path.Combine(Path.GetDirectoryName(gherkinParserFullPath), "net.iharder-base64.dll");70 ilMerge.SetInputAssemblies(new[] { gherkinParserFullPath, simpleJsonPath, base46Path });71 ilMerge.OutputFile = outputFileFullPath;72 ilMerge.TargetKind = ILMerge.Kind.Dll;73 ilMerge.Log = true;74 ilMerge.Merge();75 Console.WriteLine();76 }77 private static readonly Dictionary<string, string> languageTranslations = 78 new Dictionary<string, string>()79 {80 {"se", "sv"},81 {"lu", "lb-LU"},82 };83 private class KeywordTranslation84 {...
GherkinTextBufferParser.cs
Source:GherkinTextBufferParser.cs
2using System.Collections.Generic;3using System.Diagnostics;4using System.Linq;5using Microsoft.VisualStudio.Text;6using TechTalk.SpecFlow.Parser;7using TechTalk.SpecFlow.Parser.Gherkin;8using TechTalk.SpecFlow.Vs2010Integration.Tracing;9using TechTalk.SpecFlow.Vs2010Integration.Utils;10namespace TechTalk.SpecFlow.Vs2010Integration.LanguageService11{12 public class GherkinTextBufferParser13 {14 private const string ParserTraceCategory = "EditorParser";15 private const int PartialParseCountLimit = 30;16 private int partialParseCount = 0;17 private readonly IProjectScope projectScope;18 private readonly IVisualStudioTracer visualStudioTracer;19 public GherkinTextBufferParser(IProjectScope projectScope, IVisualStudioTracer visualStudioTracer)20 {21 this.projectScope = projectScope;22 this.visualStudioTracer = visualStudioTracer;23 }24 private GherkinDialect GetGherkinDialect(ITextSnapshot textSnapshot)25 {26 try27 {28 return projectScope.GherkinDialectServices.GetGherkinDialect(29 lineNo => textSnapshot.GetLineFromLineNumber(lineNo).GetText());30 }31 catch(Exception)32 {33 return null;34 }35 }36 public GherkinFileScopeChange Parse(GherkinTextBufferChange change, IGherkinFileScope previousScope = null)37 {38 var gherkinDialect = GetGherkinDialect(change.ResultTextSnapshot);39 if (gherkinDialect == null)40 return GetInvalidDialectScopeChange(change);41 bool fullParse = false;42 if (previousScope == null)43 fullParse = true;44 else if (!Equals(previousScope.GherkinDialect, gherkinDialect))45 fullParse = true;46 else if (partialParseCount >= PartialParseCountLimit)47 fullParse = true;48 else if (GetFirstAffectedScenario(change, previousScope) == null)49 fullParse = true;50 if (fullParse)51 return FullParse(change.ResultTextSnapshot, gherkinDialect);52 return PartialParse(change, previousScope);53 }54 private GherkinFileScopeChange GetInvalidDialectScopeChange(GherkinTextBufferChange change)55 {56 var fileScope = new GherkinFileScope(null, change.ResultTextSnapshot)57 {58 InvalidFileEndingBlock = new InvalidFileBlock(0, 59 change.ResultTextSnapshot.LineCount - 1,60 new ErrorInfo("Invalid Gherkin dialect!", 0, 0, null))61 };62 return GherkinFileScopeChange.CreateEntireScopeChange(fileScope);63 }64 private GherkinFileScopeChange FullParse(ITextSnapshot textSnapshot, GherkinDialect gherkinDialect)65 {66 visualStudioTracer.Trace("Start full parsing", ParserTraceCategory);67 Stopwatch stopwatch = new Stopwatch();68 stopwatch.Start();69 partialParseCount = 0;70 var gherkinListener = new GherkinTextBufferParserListener(gherkinDialect, textSnapshot, projectScope);71 var scanner = new GherkinScanner(gherkinDialect, textSnapshot.GetText(), 0);72 scanner.Scan(gherkinListener);73 var gherkinFileScope = gherkinListener.GetResult();74 var result = new GherkinFileScopeChange(75 gherkinFileScope,76 true, true,77 gherkinFileScope.GetAllBlocks(),78 Enumerable.Empty<IGherkinFileBlock>());79 stopwatch.Stop();80 TraceFinishParse(stopwatch, "full", result);81 return result;82 }83 private GherkinFileScopeChange PartialParse(GherkinTextBufferChange change, IGherkinFileScope previousScope)84 {85 visualStudioTracer.Trace("Start incremental parsing", ParserTraceCategory);86 Stopwatch stopwatch = new Stopwatch();87 stopwatch.Start();88 partialParseCount++;89 var textSnapshot = change.ResultTextSnapshot;90 IScenarioBlock firstAffectedScenario = GetFirstAffectedScenario(change, previousScope);91 VisualStudioTracer.Assert(firstAffectedScenario != null, "first affected scenario is null");92 int parseStartPosition = textSnapshot.GetLineFromLineNumber(firstAffectedScenario.GetStartLine()).Start;93 string fileContent = textSnapshot.GetText(parseStartPosition, textSnapshot.Length - parseStartPosition);94 var gherkinListener = new GherkinTextBufferPartialParserListener(95 previousScope.GherkinDialect,96 textSnapshot, projectScope, 97 previousScope, 98 change.EndLine, change.LineCountDelta);99 var scanner = new GherkinScanner(previousScope.GherkinDialect, fileContent, firstAffectedScenario.GetStartLine());100 IScenarioBlock firstUnchangedScenario = null;101 try102 {103 scanner.Scan(gherkinListener);104 }105 catch (PartialListeningDoneException partialListeningDoneException)106 {107 firstUnchangedScenario = partialListeningDoneException.FirstUnchangedScenario;108 }109 var partialResult = gherkinListener.GetResult();110 var result = MergePartialResult(previousScope, partialResult, firstAffectedScenario, firstUnchangedScenario, change.LineCountDelta);111 stopwatch.Stop();112 TraceFinishParse(stopwatch, "incremental", result);113 return result;114 }115 private IScenarioBlock GetFirstAffectedScenario(GherkinTextBufferChange change, IGherkinFileScope previousScope)116 {117 if (change.Type == GherkinTextBufferChangeType.SingleLine)118 //single-line changes on the start cannot influence the previous scenario119 return previousScope.ScenarioBlocks.LastOrDefault(s => s.GetStartLine() <= change.StartLine);120 // if multiple lines are added at the first line of a block, it can happen that these lines will belong121 // to the previous block122 return previousScope.ScenarioBlocks.LastOrDefault(s => s.GetStartLine() < change.StartLine); 123 }124 private GherkinFileScopeChange MergePartialResult(IGherkinFileScope previousScope, IGherkinFileScope partialResult, IScenarioBlock firstAffectedScenario, IScenarioBlock firstUnchangedScenario, int lineCountDelta)125 {126 Debug.Assert(partialResult.HeaderBlock == null, "Partial parse cannot re-parse header");127 Debug.Assert(partialResult.BackgroundBlock == null, "Partial parse cannot re-parse background");128 List<IGherkinFileBlock> changedBlocks = new List<IGherkinFileBlock>();129 List<IGherkinFileBlock> shiftedBlocks = new List<IGherkinFileBlock>();130 GherkinFileScope fileScope = new GherkinFileScope(previousScope.GherkinDialect, partialResult.TextSnapshot)131 {132 HeaderBlock = previousScope.HeaderBlock,133 BackgroundBlock = previousScope.BackgroundBlock134 };135 // inserting the non-affected scenarios136 fileScope.ScenarioBlocks.AddRange(previousScope.ScenarioBlocks.TakeUntilItemExclusive(firstAffectedScenario));137 //inserting partial result138 fileScope.ScenarioBlocks.AddRange(partialResult.ScenarioBlocks);139 changedBlocks.AddRange(partialResult.ScenarioBlocks);140 if (partialResult.InvalidFileEndingBlock != null)141 {142 VisualStudioTracer.Assert(firstUnchangedScenario == null, "first affected scenario is not null");143 // the last scenario was changed, but it became invalid144 fileScope.InvalidFileEndingBlock = partialResult.InvalidFileEndingBlock;145 changedBlocks.Add(fileScope.InvalidFileEndingBlock);146 }147 if (firstUnchangedScenario != null)148 {149 Tracing.VisualStudioTracer.Assert(partialResult.InvalidFileEndingBlock == null, "there is an invalid file ending block");150 // inserting the non-effected scenarios at the end151 var shiftedScenarioBlocks = previousScope.ScenarioBlocks.SkipFromItemInclusive(firstUnchangedScenario)152 .Select(scenario => scenario.Shift(lineCountDelta)).ToArray();153 fileScope.ScenarioBlocks.AddRange(shiftedScenarioBlocks);154 shiftedBlocks.AddRange(shiftedScenarioBlocks);155 if (previousScope.InvalidFileEndingBlock != null)156 {157 fileScope.InvalidFileEndingBlock = previousScope.InvalidFileEndingBlock.Shift(lineCountDelta);158 shiftedBlocks.Add(fileScope.InvalidFileEndingBlock);159 }160 }161 return new GherkinFileScopeChange(fileScope, false, false, changedBlocks, shiftedBlocks);162 }163 private void TraceFinishParse(Stopwatch stopwatch, string parseKind, GherkinFileScopeChange result)164 {165 visualStudioTracer.Trace(166 string.Format("Finished {0} parsing in {1} ms, {2} errors", parseKind, stopwatch.ElapsedMilliseconds, result.GherkinFileScope.TotalErrorCount()), ParserTraceCategory);167 }168 }169}...
GherkinSyntaxParserTests.cs
Source:GherkinSyntaxParserTests.cs
1namespace GherkinSyntaxHighlighter.Tests.Unit2{3 using NSubstitute;4 using NUnit.Framework;5 using global::GherkinSyntaxHighlighter.Parser;6 // Examples from: http://dannorth.net/introducing-bdd/7 // TODO: Mock expectations could be replaced by an adapter with one expect method...8 [TestFixture]9 public class GivenAClassOrMethodIdentifier10 {11 [Test]12 public void WhenStringStartsWithGerkinSyntaxThenCallsObserverWithOneGivenAndMultiplePascalSpans()13 {14 var mockGherkinSyntaxParserObserver = Substitute.For<ISyntaxParserObserver>();15 var gherkinSyntaxParser = new SyntaxParser(mockGherkinSyntaxParserObserver);16 gherkinSyntaxParser.Parse("GivenTheAccountIsInCredit");17 mockGherkinSyntaxParserObserver.Received(1).AddGherkinSyntaxSpanAt(0, 5); // Given18 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(5, 3); // The19 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(8, 7); // Account20 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(15, 2); // Is21 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(17, 2); // In22 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(19, 6); // Credit23 }24 [Test]25 public void WhenStringStartsWithAndContainsGherkinSntaxThenCallsObserverWithOneGivenAndOneAndSpan()26 {27 var mockGherkinSyntaxParserObserver = Substitute.For<ISyntaxParserObserver>();28 var gherkinSyntaxParser = new SyntaxParser(mockGherkinSyntaxParserObserver);29 gherkinSyntaxParser.Parse("GivenTheAccountIsInCreditAndTheCardIsValid");30 mockGherkinSyntaxParserObserver.Received(1).AddGherkinSyntaxSpanAt(0, 5); // Given31 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(5, 3); // The32 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(8, 7); // Account33 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(15, 2); // Is34 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(17, 2); // In35 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(19, 6); // Credit36 mockGherkinSyntaxParserObserver.Received(1).AddGherkinSyntaxSpanAt(25, 3); // And37 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(28, 3); // The38 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(31, 4); // Card39 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(35, 2); // Is40 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(37, 5); // Valid41 }42 [Test]43 public void WhenStringStartWithAndContainsGherkinSntaxThenCallsObserverWithOneWhenAndOneThenSpan()44 {45 var mockGherkinSyntaxParserObserver = Substitute.For<ISyntaxParserObserver>();46 var gherkinSyntaxParser = new SyntaxParser(mockGherkinSyntaxParserObserver);47 gherkinSyntaxParser.Parse("WhenCustomerRequestsCashThenEnsureAccountIsDebitedAndEnsureCashDispensed");48 mockGherkinSyntaxParserObserver.Received(1).AddGherkinSyntaxSpanAt(0, 4); // When49 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(4, 8); // Customer50 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(12, 8); // Requests51 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(20, 4); // Cash52 mockGherkinSyntaxParserObserver.Received(1).AddGherkinSyntaxSpanAt(24, 4); // Then53 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(28, 6); // Ensure54 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(34, 7); // Account55 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(41, 2); // Is56 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(43, 7); // Debited57 mockGherkinSyntaxParserObserver.Received(1).AddGherkinSyntaxSpanAt(50, 3); // And58 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(53, 6); // Ensure59 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(59, 4); // Cash60 mockGherkinSyntaxParserObserver.Received(1).AddPascalCaseSpanAt(63, 9); // Dispensed61 }62 }63}...
GherkinTokenTagger.cs
Source:GherkinTokenTagger.cs
...6using System.Threading;7using Gherkin;8using Microsoft.VisualStudio.Text;9using Microsoft.VisualStudio.Text.Tagging;10namespace SpecFlow.VisualStudio.Editor.Parser11{12 internal sealed class GherkinTokenTagger : ITagger<GherkinTokenTag>13 {14 private class ParsingResult15 {16 public int SnapshotVersion { get; private set; }17 public GherkinTokenTag[] Tags { get; private set; }18 public ParsingResult(int snapshotVersion, GherkinTokenTag[] tags)19 {20 SnapshotVersion = snapshotVersion;21 Tags = tags;22 }23 }24 private readonly ITextBuffer buffer;25 private ParsingResult lastResult = null;26 internal GherkinTokenTagger(ITextBuffer buffer)27 {28 this.buffer = buffer;29 }30 public event EventHandler<SnapshotSpanEventArgs> TagsChanged;31 public IEnumerable<ITagSpan<GherkinTokenTag>> GetTags(NormalizedSnapshotSpanCollection spans)32 {33 var snapshot = spans[0].Snapshot;34 var tokenTags = Parse(snapshot);35 if (tokenTags == null)36 yield break;37 foreach (SnapshotSpan queriedSpan in spans)38 {39 foreach (var tokenTag in tokenTags)40 {41 var tokenSpan = tokenTag.Span;42 if (tokenSpan.IntersectsWith(queriedSpan))43 yield return new TagSpan<GherkinTokenTag>(tokenSpan, tokenTag);44 if (tokenSpan.Start > queriedSpan.End)45 break;46 }47 }48 }49 private GherkinTokenTag[] Parse(ITextSnapshot snapshot)50 {51 var currentLastResult = lastResult;52 if (currentLastResult != null && currentLastResult.SnapshotVersion == snapshot.Version.VersionNumber)53 return currentLastResult.Tags;54 55 var fileContent = snapshot.GetText();56 var stopwatch = new Stopwatch();57 stopwatch.Start();58 var parserErrors = new List<ParserException>();59 var tokenTagBuilder = new GherkinTokenTagBuilder(snapshot);60 var parser = new GherkinEditorParser(tokenTagBuilder);61 var reader = new StringReader(fileContent);62 try63 {64 parser.Parse(new TokenScanner(reader), new TokenMatcher(VsGherkinDialectProvider.Instance));65 }66 catch (CompositeParserException compositeParserException)67 {68 parserErrors.AddRange(compositeParserException.Errors);69 }70 catch (ParserException parserException)71 {72 parserErrors.Add(parserException);73 }74 catch (Exception ex)75 {76 //nop;77 Debug.WriteLine(ex);78 }79 var tokenTags = new List<GherkinTokenTag>();80 tokenTags.AddRange((GherkinTokenTag[])tokenTagBuilder.GetResult());81 tokenTags.AddRange(parserErrors.Select(e => new GherkinTokenTag(e, snapshot)));82 tokenTags.Sort((t1, t2) => t1.Span.Start.Position.CompareTo(t2.Span.Start.Position));83 stopwatch.Stop();84 Debug.WriteLine("Gherkin3: parsed v{0} on thread {1} in {2} ms", snapshot.Version.VersionNumber, Thread.CurrentThread.ManagedThreadId, stopwatch.ElapsedMilliseconds);...
ParseGherkinQueryRequestHandler.cs
Source:ParseGherkinQueryRequestHandler.cs
...3using System.Linq;4using System.Text;5using Gherkin.Ast;6using MediatR;7using SFA.DAS.Payments.Automation.Application.GherkinSpecs.StepParsers;8using SFA.DAS.Payments.Automation.Domain.Specifications;9namespace SFA.DAS.Payments.Automation.Application.GherkinSpecs.ParseGherkinQuery10{11 public class ParseGherkinQueryRequestHandler : IRequestHandler<ParseGherkinQueryRequest, ParseGherkinQueryResponse>12 {13 private static readonly string[] PrimaryScenarioKeywords = { "Given", "When", "Then" };14 private static readonly StepParser[] StepParsers =15 {16 new CommitmentsStepParser(),17 new IndefinateLevyBalanceStepParser(),18 new NoLevyBalanceStepParser(),19 new SpecificLevyBalanceStepParser(),20 new SubmissionStepParser(),21 new ContractTypeStepParser(),22 new EmploymentStatusStepParser()23 };24 public ParseGherkinQueryResponse Handle(ParseGherkinQueryRequest message)25 {26 try27 {28 var doc = ParseGherkin(message.GherkinSpecs);29 var docSpecs = doc.Feature.Children.ToArray();30 var specifications = new Specification[docSpecs.Length];31 for (var i = 0; i < specifications.Length; i++)32 {33 specifications[i] = ParseScenario(docSpecs[i]);34 }35 return new ParseGherkinQueryResponse36 {37 Results = specifications38 };39 }40 catch (Exception ex)41 {42 return new ParseGherkinQueryResponse43 {44 Error = new ParserException(ex)45 };46 }47 }48 private Gherkin.Ast.GherkinDocument ParseGherkin(string specs)49 {50 using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(specs)))51 using (var reader = new StreamReader(stream))52 {53 var parser = new Gherkin.Parser();54 return parser.Parse(reader);55 }56 }57 private Specification ParseScenario(ScenarioDefinition scenarioDefinition)58 {59 var specification = new Specification60 {61 Name = scenarioDefinition.Name62 };63 var currentStepKeyword = "";64 foreach (var step in scenarioDefinition.Steps)65 {66 if (PrimaryScenarioKeywords.Any(x => x.Equals(step.Keyword.Trim(), StringComparison.CurrentCultureIgnoreCase)))67 {68 currentStepKeyword = step.Keyword.Trim().ToLower();69 }70 ParseStep(currentStepKeyword, step, specification);71 }72 return specification;73 }74 private void ParseStep(string keyword, Step step, Specification specification)75 {76 foreach (var parser in StepParsers)77 {78 if (parser.CanParse(keyword, step.Text))79 {80 parser.Parse(step, specification);81 return;82 }83 }84 }85 }86}...
NoProjectScope.cs
Source:NoProjectScope.cs
...5using TechTalk.SpecFlow.IdeIntegration.Generator;6using TechTalk.SpecFlow.IdeIntegration.Options;7using TechTalk.SpecFlow.IdeIntegration.Tracing;8using TechTalk.SpecFlow.Infrastructure;9using TechTalk.SpecFlow.Parser;10using TechTalk.SpecFlow.Bindings;11using TechTalk.SpecFlow.Vs2010Integration.GherkinFileEditor;12using TechTalk.SpecFlow.Vs2010Integration.Options;13using TechTalk.SpecFlow.Vs2010Integration.Tracing;14namespace TechTalk.SpecFlow.Vs2010Integration.LanguageService15{16 internal class NoProjectScope : IProjectScope17 {18 public GherkinTextBufferParser GherkinTextBufferParser { get; private set; }19 public GherkinFileEditorClassifications Classifications { get; private set; }20 public GherkinProcessingScheduler GherkinProcessingScheduler { get; private set; }21 public SpecFlowProjectConfiguration SpecFlowProjectConfiguration { get; private set; }22 public GherkinDialectServices GherkinDialectServices { get; private set; }23 public IIntegrationOptionsProvider IntegrationOptionsProvider { get; private set; }24 public IIdeTracer Tracer { get; private set; }25 public event Action SpecFlowProjectConfigurationChanged { add {} remove {} }26 public event Action GherkinDialectServicesChanged { add { } remove { } }27 public GherkinScopeAnalyzer GherkinScopeAnalyzer28 {29 get { return null; }30 }31 public VsStepSuggestionProvider StepSuggestionProvider32 {33 get { return null; }34 }35 public IStepDefinitionMatchService BindingMatchService36 {37 get { return null; }38 }39 public IGeneratorServices GeneratorServices40 {41 get { return null; }42 }43 public NoProjectScope(GherkinFileEditorClassifications classifications, IVisualStudioTracer visualStudioTracer, IIntegrationOptionsProvider integrationOptionsProvider)44 {45 GherkinTextBufferParser = new GherkinTextBufferParser(this, visualStudioTracer);46 GherkinProcessingScheduler = new GherkinProcessingScheduler(visualStudioTracer, false);47 SpecFlowProjectConfiguration = new SpecFlowProjectConfiguration();48 GherkinDialectServices = new GherkinDialectServices(SpecFlowProjectConfiguration.GeneratorConfiguration.FeatureLanguage); 49 Classifications = classifications;50 IntegrationOptionsProvider = integrationOptionsProvider;51 Tracer = visualStudioTracer;52 }53 public void Dispose()54 {55 //nop56 }57 }58}...
GherkinTextBufferPartialParserListener.cs
Source:GherkinTextBufferPartialParserListener.cs
1using System.Collections.Generic;2using System.Linq;3using Microsoft.VisualStudio.Text;4using TechTalk.SpecFlow.Parser;5using TechTalk.SpecFlow.Parser.Gherkin;6using TechTalk.SpecFlow.Vs2010Integration.GherkinFileEditor;7namespace TechTalk.SpecFlow.Vs2010Integration.LanguageService8{9 internal class PartialListeningDoneException : ScanningCancelledException10 {11 public IScenarioBlock FirstUnchangedScenario { get; private set; }12 public PartialListeningDoneException(IScenarioBlock firstUnchangedScenario)13 {14 FirstUnchangedScenario = firstUnchangedScenario;15 }16 }17 internal class GherkinTextBufferPartialParserListener : GherkinTextBufferParserListenerBase18 {19 private readonly IGherkinFileScope previousScope;20 private readonly int changeLastLine;21 private readonly int changeLineDelta;22 protected override string FeatureTitle { get { return previousScope.HeaderBlock == null ? null : previousScope.HeaderBlock.Title; } }23 protected override IEnumerable<string> FeatureTags { get { return previousScope.HeaderBlock == null ? Enumerable.Empty<string>() : previousScope.HeaderBlock.Tags; } }24 public GherkinTextBufferPartialParserListener(GherkinDialect gherkinDialect, ITextSnapshot textSnapshot, IProjectScope projectScope, IGherkinFileScope previousScope, int changeLastLine, int changeLineDelta)25 : base(gherkinDialect, textSnapshot, projectScope)26 {27 this.previousScope = previousScope;28 this.changeLastLine = changeLastLine;29 this.changeLineDelta = changeLineDelta;30 }31 protected override void OnScenarioBlockCreating(int editorLine)32 {33 base.OnScenarioBlockCreating(editorLine);34 if (editorLine > changeLastLine)35 {36 var firstUnchangedScenario = previousScope.ScenarioBlocks.FirstOrDefault(37 prevScenario => prevScenario.GetStartLine() + changeLineDelta == editorLine);38 if (firstUnchangedScenario != null)...
SpecFlowLangParser.cs
Source:SpecFlowLangParser.cs
2using System.Diagnostics;3using System.Globalization;4using System.IO;5using System.Linq;6using TechTalk.SpecFlow.Parser.Gherkin;7using TechTalk.SpecFlow.Parser.GherkinBuilder;8using TechTalk.SpecFlow.Parser.SyntaxElements;9namespace TechTalk.SpecFlow.Parser10{11 public class SpecFlowLangParser12 {13 private readonly GherkinDialectServices dialectServices;14 public SpecFlowLangParser(CultureInfo defaultLanguage)15 {16 this.dialectServices = new GherkinDialectServices(defaultLanguage);17 }18 public Feature Parse(TextReader featureFileReader, string sourceFilePath)19 {20 var fileContent = featureFileReader.ReadToEnd();21 var language = dialectServices.GetLanguage(fileContent);22 var gherkinDialect = dialectServices.GetGherkinDialect(language);23 var gherkinListener = new GherkinParserListener(sourceFilePath);24 GherkinScanner scanner = new GherkinScanner(gherkinDialect, fileContent);25 scanner.Scan(gherkinListener);26 Feature feature = gherkinListener.GetResult();27 if (gherkinListener.Errors.Count > 0)28 throw new SpecFlowParserException(gherkinListener.Errors);29 Debug.Assert(feature != null, "If there were no errors, the feature cannot be null");30 feature.Language = language.LanguageForConversions.Name;31 return feature;32 }33 }34}...
Parser
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin;7using Gherkin.Ast;8{9 {10 static void Main(string[] args)11 {12 Parser parser = new Parser();13 Then I should be logged in";14 var result = parser.Parse(feature);15 Console.WriteLine("Feature: " + result.Feature.Name);16 var scenario = result.Feature.Children.First();17 Console.WriteLine("Scenario: " + scenario.Name);18 var step = scenario.Steps.First();19 Console.WriteLine("Step: " + step.Keyword + step.Text);20 Console.ReadLine();21 }22 }23}24using System;25using System.Collections.Generic;26using System.Linq;27using System.Text;28using System.Threading.Tasks;29using Gherkin;30using Gherkin.Ast;31{32 {33 static void Main(string[] args)34 {35 var parser = new Parser();36 Then I should be logged in";37 var result = parser.Parse(feature);38 Console.WriteLine("Feature: " + result.Feature.Name);39 var scenario = result.Feature.Children.First();40 Console.WriteLine("Scenario: " + scenario.Name);41 var step = scenario.Steps.First();42 Console.WriteLine("Step: " + step.Keyword + step.Text);43 Console.ReadLine();44 }45 }46}47using System;48using System.Collections.Generic;49using System.Linq;50using System.Text;51using System.Threading.Tasks;52using Gherkin;53using Gherkin.Ast;54{55 {56 static void Main(string[] args)57 {58 var parser = new Parser();59 Then I should be logged in";60 var result = parser.Parse(feature);
Parser
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin;7{8 {9 static void Main(string[] args)10 {11 Then I get a feature object";12 var parser = new Parser();13 var feature = parser.Parse(featureText);14 Console.WriteLine("Feature: {0}", feature.Name);15 Console.WriteLine("Description: {0}", feature.Description);16 Console.WriteLine("Tags: {0}", string.Join(",", feature.Tags));17 Console.WriteLine("Scenarios:");18 foreach (var scenario in feature.Scenarios)19 {20 Console.WriteLine("\tScenario: {0}", scenario.Name);21 Console.WriteLine("\tDescription: {0}", scenario.Description);22 Console.WriteLine("\tTags: {0}", string.Join(",", scenario.Tags));23 Console.WriteLine("\tSteps:");24 foreach (var step in scenario.Steps)25 {26 Console.WriteLine("\t\t{0} {1}", step.Keyword, step.Text);27 }28 }29 Console.ReadLine();30 }31 }32}33using System;34using System.Collections.Generic;35using System.Linq;36using System.Text;37using System.Threading.Tasks;38using Gherkin;39{40 {41 static void Main(string[] args)42 {43 Then I get a feature object";44 var parser = new Parser();45 var feature = parser.Parse(featureText);46 Console.WriteLine("Feature: {0}", feature.Name);47 Console.WriteLine("Description: {0}", feature.Description);48 Console.WriteLine("Tags: {0}", string.Join(",", feature.Tags));49 Console.WriteLine("Scenarios:");50 foreach (var scenario in feature.Scenarios)51 {52 Console.WriteLine("\tScenario: {0}", scenario.Name);
Parser
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin;7using Gherkin.Ast;8using System.IO;9{10 {11 static void Main(string[] args)12 {13 string featureText = File.ReadAllText(@"D:\CSharp\GherkinParser\GherkinParser\Features\1.feature");14 var parser = new Parser();15 var gherkinDocument = parser.Parse(featureText);16 Console.WriteLine(gherkinDocument.Feature.Name);17 Console.ReadLine();18 }19 }20}
Parser
Using AI Code Generation
1using Gherkin;2using Gherkin.Ast;3using System;4using System.Collections.Generic;5using System.IO;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9{10 {11 static void Main(string[] args)12 {13 var parser = new Parser();14 var feature = parser.Parse(@"
Parser
Using AI Code Generation
1using System;2using TechTalk.SpecFlow.Parser;3using TechTalk.SpecFlow.Parser.SyntaxElements;4using TechTalk.SpecFlow.Parser.Gherkin;5using System.Collections.Generic;6using System.IO;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 static void Main(string[] args)13 {14 string path = @"C:\Users\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\1.feature";15 var parser = new GherkinParser();16 var feature = parser.Parse(new StreamReader(path));17 Console.WriteLine(feature.Title);18 Console.ReadLine();19 }20 }21}22using System;23using TechTalk.SpecFlow.Parser;24using TechTalk.SpecFlow.Parser.SyntaxElements;25using TechTalk.SpecFlow.Parser.Gherkin;26using System.Collections.Generic;27using System.IO;28using System.Linq;29using System.Text;30using System.Threading.Tasks;31{32 {33 static void Main(string[] args)34 {35 string path = @"C:\Users\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\1.feature";36 var parser = new GherkinParser();37 var feature = parser.Parse(new StreamReader(path));38 Console.WriteLine(feature.Title);39 Console.ReadLine();40 }41 }42}
Parser
Using AI Code Generation
1Gherkin.Parser p = new Gherkin.Parser();2Gherkin.GherkinDocument g = p.Parse("Feature: Hello");3Gherkin.GherkinDocument g = new Gherkin.GherkinDocument();4Gherkin.Parser p = new Gherkin.Parser();5Gherkin.GherkinDocument g = p.Parse("Feature: Hello");6Gherkin.GherkinDocument g = new Gherkin.GherkinDocument();7Gherkin.Parser p = new Gherkin.Parser();8Gherkin.GherkinDocument g = p.Parse("Feature: Hello");9Gherkin.GherkinDocument g = new Gherkin.GherkinDocument();10Gherkin.Parser p = new Gherkin.Parser();11Gherkin.GherkinDocument g = p.Parse("Feature: Hello");12Gherkin.GherkinDocument g = new Gherkin.GherkinDocument();13Gherkin.Parser p = new Gherkin.Parser();14Gherkin.GherkinDocument g = p.Parse("Feature: Hello");15Gherkin.GherkinDocument g = new Gherkin.GherkinDocument();
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!!