How to use CompositeParserException method of Gherkin.CompositeParserException class

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

DeveroomGherkinParser.cs

Source:DeveroomGherkinParser.cs Github

copy

Full Screen

...33 catch (ParserException parserException)34 {35 logger.LogVerbose($"ParserErrors: {parserException.Message}");36 gherkinDocument = GetResultOfInvalid();37 if (parserException is CompositeParserException compositeParserException)38 parserErrors.AddRange(compositeParserException.Errors);39 else40 parserErrors.Add(parserException);41 }42 catch (Exception e)43 {44 logger.LogException(_monitoringService, e, "Exception during Gherkin parsing");45 gherkinDocument = GetResult();46 }47 return false;48 }49 private DeveroomGherkinDocument GetResultOfInvalid()50 {51 // trying to "finish" open nodes by sending dummy <endrule> messages up to 5 levels of nesting52 for (int i = 0; i < 10; i++)53 {54 var result = GetResult();55 if (result != null)56 return result;57 try58 {59 AstBuilder.EndRule(RuleType.None);60 }61 catch (Exception)62 {63 }64 }65 return null;66 }67 public DeveroomGherkinDocument Parse(TextReader featureFileReader, string sourceFilePath)68 {69 var tokenScanner = (ITokenScanner)new HotfixTokenScanner(featureFileReader);70 var tokenMatcher = new TokenMatcher(DialectProvider);71 _astBuilder = new DeveroomGherkinAstBuilder(sourceFilePath, () => tokenMatcher.CurrentDialect);72 var parser = new InternalParser(_astBuilder, AstBuilder.RecordStateForLine, _monitoringService);73 var gherkinDocument = parser.Parse(tokenScanner, tokenMatcher);74 CheckSemanticErrors(gherkinDocument);75 return gherkinDocument;76 }77 class InternalParser : Parser<DeveroomGherkinDocument>78 {79 private readonly Action<int, int> _recordStateForLine;80 private readonly IMonitoringService _monitoringService;81 public InternalParser(IAstBuilder<DeveroomGherkinDocument> astBuilder, Action<int, int> recordStateForLine, IMonitoringService monitoringService)82 : base(astBuilder)83 {84 _recordStateForLine = recordStateForLine;85 _monitoringService = monitoringService;86 }87 public int NullMatchToken(int state, Token token)88 {89 return MatchToken(state, token, new ParserContext()90 {91 Errors = new List<ParserException>(),92 TokenMatcher = new AllFalseTokenMatcher(),93 TokenQueue = new Queue<Token>(),94 TokenScanner = new NullTokenScanner()95 });96 }97 protected override int MatchToken(int state, Token token, ParserContext context)98 {99 _recordStateForLine?.Invoke(token.Location.Line, state);100 try101 {102 return base.MatchToken(state, token, context);103 }104 catch (InvalidOperationException ex)105 {106 _monitoringService.MonitorError(ex);107 throw;108 }109 }110 }111 public DeveroomGherkinDocument GetResult()112 {113 return _astBuilder.GetResult();114 }115 #region Semantic Errors116 protected virtual void CheckSemanticErrors(DeveroomGherkinDocument specFlowDocument)117 {118 var errors = new List<ParserException>();119 errors.AddRange(((DeveroomGherkinAstBuilder)_astBuilder).Errors);120 if (specFlowDocument?.Feature != null)121 {122 CheckForDuplicateScenarios(specFlowDocument.Feature, errors);123 CheckForDuplicateExamples(specFlowDocument.Feature, errors);124 CheckForMissingExamples(specFlowDocument.Feature, errors);125 CheckForRulesPreSpecFlow31(specFlowDocument.Feature, errors);126 }127 // collect128 if (errors.Count == 1)129 throw errors[0];130 if (errors.Count > 1)131 throw new CompositeParserException(errors.ToArray());132 }133 private void CheckForRulesPreSpecFlow31(Feature feature, List<ParserException> errors)134 {135 //TODO: Show error when Rule keyword is used in SpecFlow v3.0 or earlier136 }137 private void CheckForDuplicateScenarios(Feature feature, List<ParserException> errors)138 {139 // duplicate scenario name140 var duplicatedScenarios = feature.FlattenScenarioDefinitions().GroupBy(sd => sd.Name, sd => sd).Where(g => g.Count() > 1).ToArray();141 errors.AddRange(142 duplicatedScenarios.Select(g =>143 new SemanticParserException(144 $"Feature file already contains a scenario with name '{g.Key}'",145 g.ElementAt(1).Location)));...

Full Screen

Full Screen

ParserException.cs

Source:ParserException.cs Github

copy

Full Screen

...114 {115 }116 }117 [Serializable]118 public class CompositeParserException : ParserException119 {120 public IEnumerable<ParserException> Errors { get; private set; }121 public CompositeParserException(ParserException[] errors)122 : base(GetMessage(errors))123 {124 if (errors == null) throw new ArgumentNullException("errors");125 Errors = errors;126 }127 private static string GetMessage(ParserException[] errors)128 {129 return "Parser errors:" + Environment.NewLine + string.Join(Environment.NewLine, errors.Select(e => e.Message));130 }131 protected CompositeParserException(SerializationInfo info, StreamingContext context) : base(info, context)132 {133 Errors = (ParserException[])info.GetValue("Errors", typeof (ParserException[]));134 }135 public override void GetObjectData(SerializationInfo info, StreamingContext context)136 {137 base.GetObjectData(info, context);138 info.AddValue("Errors", Errors.ToArray());139 }140 }141}...

Full Screen

Full Screen

GherkinTokenTagger.cs

Source:GherkinTokenTagger.cs Github

copy

Full Screen

...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());...

Full Screen

Full Screen

LexicParcer.cs

Source:LexicParcer.cs Github

copy

Full Screen

...18 using (var reader = new StreamReader(file)) {19 var ts = new TokenScanner(reader);20 try {21 feature = (Feature)parser.Parse(ts);22 } catch (CompositeParserException ex) {23 _errorFiles.Add(new ErrorInfo {24 FilePath = file,25 CompositeException = ex26 });27 return null;28 } catch (NullReferenceException ex) {29 _errorFiles.Add(new ErrorInfo {30 FilePath = file,31 Exception = ex32 });33 return null;34 }35 ts = null;36 }37 var steps = (from scenario in feature.ScenarioDefinitions38 from step in scenario.Steps39 let exampleSteps = GetSteps(step, scenario)40 from s in exampleSteps41 select s).ToList();42 var featureInfo = new FeatureFileInfo(file, steps);43 return featureInfo;44 }45 public static List<GherkinStep> GetSteps(Step step, ScenarioDefinition scenario) {46 var res = new List<GherkinStep>();47 var outline = scenario as ScenarioOutline;48 var stepText = step.Text;49 if (outline != null && stepText.Contains("<") && stepText.Contains(">")) {50 var m = _exampleRegex.Match(stepText);51 if (m.Success) {52 for (int i = 0; i < m.Groups.Count; i++) {53 var exampleValue = m.Groups[i].Value.Replace("<", string.Empty).Replace(">", string.Empty);54 var resStep = GetGherkinStep(step, exampleValue);55 res.Add(resStep);56 }57 }58 }59 else {60 var resStep = GetGherkinStep(step, stepText);61 res.Add(resStep);62 }63 return res;64 }65 private static GherkinStep GetGherkinStep(Step step, string stepText) {66 var resStep = new GherkinStep {67 Text = stepText,68 Column = (ushort) step.Location.Column,69 Line = (ushort) step.Location.Line,70 Keyword = step.Keyword71 };72 return resStep;73 }74 public static List<FeatureFileInfo> ParseFolder(string directory, bool includeSubdirs = true) {75 _errorFiles.Clear();76 var files = Directory.EnumerateFiles(directory, "*.feature",77 includeSubdirs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToList();78 var res = new List<FeatureFileInfo>(files.Count);79 res.AddRange(files.AsParallel().Select(ParseFile).Where(r=>r!= null));80 return res;81 }82 }83 public class ErrorInfo {84 public string FilePath { get; set; }85 public CompositeParserException CompositeException { get; set; }86 public Exception Exception { get; set; }87 }88}...

Full Screen

Full Screen

GherkinParser.cs

Source:GherkinParser.cs Github

copy

Full Screen

...18 return new GherkinFile(path, Enumerable.Empty<ParseErrorInformation>(),19 gherkinDocument);20 }21 }22 catch (CompositeParserException cpe)23 {24 return new GherkinFile(path, ToErrorInformation(cpe.Errors, text));25 }26 catch (ParserException pe)27 {28 return new GherkinFile(path, new List<ParseErrorInformation> {ToErrorInformation(pe, text)});29 }30 }31 private static IEnumerable<ParseErrorInformation> ToErrorInformation(32 in IEnumerable<ParserException> errors, string text)33 {34 var splitFile = FileUtils.SplitString(text);35 return errors.Select(error => ToErrorInformation(error, splitFile));36 }...

Full Screen

Full Screen

GherkinEvents.cs

Source:GherkinEvents.cs Github

copy

Full Screen

...29 }30 if (printPickles) {31 throw new NotSupportedException ("Gherkin.NET doesn't have a pickle compiler yet");32 }33 } catch (CompositeParserException e) {34 foreach (ParserException error in e.Errors) {35 addErrorAttachment (events, error, sourceEvent.uri);36 }37 } catch (ParserException e) {38 addErrorAttachment (events, e, sourceEvent.uri);39 }40 return events;41 }42 private void addErrorAttachment (List<IEvent> events, ParserException e, String uri)43 {44 events.Add (new AttachmentEvent (45 new AttachmentEvent.SourceRef (46 uri,47 new AttachmentEvent.Location (...

Full Screen

Full Screen

MissingExamplesParserFactory.cs

Source:MissingExamplesParserFactory.cs Github

copy

Full Screen

...37 return;3839 throw;40 }41 catch (CompositeParserException e)42 {43 if(e.Errors.All(ShouldIgnoreException))44 return;4546 throw;47 }48 }4950 private static bool ShouldIgnoreException(ParserException e) =>51 Regex.IsMatch(e.Message, @"^\(\d+:\d+\): Scenario Outline '.*?' has no examples defined$");52 } ...

Full Screen

Full Screen

FeatureParser.cs

Source:FeatureParser.cs Github

copy

Full Screen

...24 {25 var file = new FeatureFile(parser.Parse(gherkinFilePath), gherkinFilePath);26 featureFiles.Add(file);27 }28 catch (CompositeParserException e)29 {30 Log.Error(e, $"The file has not been parsed: {gherkinFilePath}");31 _context.IsRunSuccessful = false;32 }33 catch (Exception e)34 {35 Log.Fatal(e, $"The file has not been parsed: {gherkinFilePath}");36 throw;37 }38 }39 return featureFiles;40 }41 }42}...

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

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 {12 }13 catch (CompositeParserException ex)14 {15 }16 }17 }18}

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

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 CompositeParserException cpe = new CompositeParserException();12 cpe.AddParserException(new ParserException(1, "error1"));13 cpe.AddParserException(new ParserException(2, "error2"));14 Console.WriteLine(cpe.Message);15 Console.ReadLine();16 }17 }18}191 error(s) parsing feature file: error1202 error(s) parsing feature file: error2211 error(s) parsing feature file: error1222 error(s) parsing feature file: error2

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

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 {12 CompositeParserException compositeParserException = new CompositeParserException();13 compositeParserException.AddParserException(new ParserException("Error in parsing", new Location(1, 0)));14 compositeParserException.AddParserException(new ParserException("Error in parsing", new Location(2, 0)));15 compositeParserException.AddParserException(new ParserException("Error in parsing", new Location(3, 0)));16 compositeParserException.AddParserException(new ParserException("Error in parsing", new Location(4, 0)));17 compositeParserException.AddParserException(new ParserException("Error in parsing", new Location(5, 0)));18 throw compositeParserException;19 }20 catch (CompositeParserException compositeParserException)21 {22 Console.WriteLine(compositeParserException.Message);23 }24 }25 }26}

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin;7using System.IO;8{9 {10 static void Main(string[] args)11 {12 {13 string[] featureFiles = Directory.GetFiles(@"C:\Users\Public\Documents\GherkinCompositeParserException", "*.feature");14 foreach (string featureFile in featureFiles)15 {16 Console.WriteLine("Feature File: " + featureFile);17 var parser = new Gherkin.Parser();18 var feature = parser.Parse(File.ReadAllText(featureFile), featureFile);19 Console.WriteLine("Feature: " + feature.Name);20 }21 }22 catch (CompositeParserException ex)23 {24 foreach (var error in ex.Errors)25 {26 Console.WriteLine("Error: " + error.Message);27 Console.WriteLine("Line: " + error.Location.Line);28 Console.WriteLine("Column: " + error.Location.Column);29 }30 }31 }32 }33}

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

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 CompositeParserException compositeParserException = new CompositeParserException();12 compositeParserException.CompositeParserExceptionMethod();13 }14 public void CompositeParserExceptionMethod()15 {16 List<ParserException> parserExceptions = new List<ParserException>();17 ParserException parserException = new ParserException("error");18 parserExceptions.Add(parserException);19 CompositeParserException compositeParserException = new CompositeParserException(parserExceptions);20 }21 }22}23using System;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28using Gherkin;29{30 {31 static void Main(string[] args)32 {33 CompositeParserException compositeParserException = new CompositeParserException();34 compositeParserException.CompositeParserExceptionMethod();35 }36 public void CompositeParserExceptionMethod()37 {38 CompositeParserException compositeParserException = new CompositeParserException();39 List<ParserException> parserExceptions = compositeParserException.ParserExceptions;40 }41 }42}43using System;44using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48using Gherkin;49{50 {51 static void Main(string[] args)52 {53 CompositeParserException compositeParserException = new CompositeParserException();54 compositeParserException.CompositeParserExceptionMethod();55 }56 public void CompositeParserExceptionMethod()57 {58 CompositeParserException compositeParserException = new CompositeParserException();59 string message = compositeParserException.Message;60 }61 }62}

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1{2 {3 static void Main(string[] args)4 {5 {6 var parser = new Parser();7 var feature = parser.Parse("Feature: Test Feature8");9 }10 catch (CompositeParserException ex)11 {12 Console.WriteLine(ex.Message);13 }14 catch (Exception ex)15 {16 Console.WriteLine(ex.Message);17 }18 }19 }20}21{22 {23 static void Main(string[] args)24 {25 {26 var parser = new Parser();27 var feature = parser.Parse("Feature: Test Feature28");29 }30 catch (CompositeParserException ex)31 {32 Console.WriteLine(ex.Message);33 }34 catch (Exception ex)35 {36 Console.WriteLine(ex.Message);37 }38 }39 }40}

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using Gherkin;4using Gherkin.Ast;5using Gherkin.Parser;6using Gherkin.TokenScanner;7{8 {9 static void Main(string[] args)10 {11 List<string> lines = new List<string>();12 lines.Add("Feature: Login");13 lines.Add("Scenario: Login with valid credentials");14 lines.Add("Given user is on login page");15 lines.Add("When user enters valid credentials");16 lines.Add("And click on login button");17 lines.Add("Then user should be logged in");18 Parser<GherkinDocument> parser = new Parser<GherkinDocument>();19 {20 GherkinDocument gherkinDocument = parser.Parse(lines);21 }22 catch (CompositeParserException ex)23 {24 List<ParserException> exceptions = ex.GetExceptions();25 foreach (ParserException exception in exceptions)26 {27 Console.WriteLine(exception.Message);28 }29 }30 }31 }32}

Full Screen

Full Screen

CompositeParserException

Using AI Code Generation

copy

Full Screen

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 {12 var parser = new Parser();13 var feature = parser.Parse("Feature: Hello

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.

Most used method in CompositeParserException

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful