How to use Rule method of Gherkin.Ast.Rule class

Best Gherkin-dotnet code snippet using Gherkin.Ast.Rule.Rule

AstBuilder.cs

Source:AstBuilder.cs Github

copy

Full Screen

...1819 public void Reset()20 {21 stack.Clear();22 stack.Push(new AstNode(RuleType.None));23 comments.Clear();24 }2526 public void Build(Token token)27 {28 if (token.MatchedType == TokenType.Comment)29 {30 comments.Add(CreateComment(GetLocation(token), token.MatchedText));31 }32 else33 {34 CurrentNode.Add((RuleType) token.MatchedType, token);35 }36 }3738 public void StartRule(RuleType ruleType)39 {40 stack.Push(new AstNode(ruleType));41 }4243 public void EndRule(RuleType ruleType)44 {45 var node = stack.Pop();46 object transformedNode = GetTransformedNode(node);47 CurrentNode.Add(node.RuleType, transformedNode);48 }4950 public T GetResult()51 {52 return CurrentNode.GetSingle<T>(RuleType.GherkinDocument);53 }5455 private object GetTransformedNode(AstNode node)56 {57 switch (node.RuleType)58 {59 case RuleType.Step:60 {61 var stepLine = node.GetToken(TokenType.StepLine);62 var stepArg = node.GetSingle<StepArgument>(RuleType.DataTable) ??63 node.GetSingle<StepArgument>(RuleType.DocString) ??64 null; // empty arg65 return CreateStep(GetLocation(stepLine), stepLine.MatchedKeyword, stepLine.MatchedText, stepArg, node);66 }67 case RuleType.DocString:68 {69 var separatorToken = node.GetTokens(TokenType.DocStringSeparator).First();70 var contentType = separatorToken.MatchedText.Length == 0 ? null : separatorToken.MatchedText;71 var lineTokens = node.GetTokens(TokenType.Other);72 var content = string.Join(Environment.NewLine, lineTokens.Select(lt => lt.MatchedText));73 var delimiter = separatorToken.MatchedKeyword.Length == 0 ? null : separatorToken.MatchedKeyword;7475 return CreateDocString(GetLocation(separatorToken), contentType, content, delimiter, node);76 }77 case RuleType.DataTable:78 {79 var rows = GetTableRows(node);80 return CreateDataTable(rows, node);81 }82 case RuleType.Background:83 {84 var backgroundLine = node.GetToken(TokenType.BackgroundLine);85 var description = GetDescription(node);86 var steps = GetSteps(node);87 return CreateBackground(GetLocation(backgroundLine), backgroundLine.MatchedKeyword, backgroundLine.MatchedText, description, steps, node);88 }89 case RuleType.ScenarioDefinition:90 {91 var tags = GetTags(node);9293 var scenarioNode = node.GetSingle<AstNode>(RuleType.Scenario);94 var scenarioLine = scenarioNode.GetToken(TokenType.ScenarioLine);9596 var description = GetDescription(scenarioNode);97 var steps = GetSteps(scenarioNode);98 var examples = scenarioNode.GetItems<Examples>(RuleType.ExamplesDefinition).ToArray();99 return CreateScenario(tags, GetLocation(scenarioLine), scenarioLine.MatchedKeyword, scenarioLine.MatchedText, description, steps, examples, node);100 }101 case RuleType.ExamplesDefinition:102 {103 var tags = GetTags(node);104 var examplesNode = node.GetSingle<AstNode>(RuleType.Examples);105 var examplesLine = examplesNode.GetToken(TokenType.ExamplesLine);106 var description = GetDescription(examplesNode);107108 var allRows = examplesNode.GetSingle<TableRow[]>(RuleType.ExamplesTable);109 var header = allRows != null ? allRows.First() : null;110 var rows = allRows != null ? allRows.Skip(1).ToArray() : null;111 return CreateExamples(tags, GetLocation(examplesLine), examplesLine.MatchedKeyword, examplesLine.MatchedText, description, header, rows, node);112 }113 case RuleType.ExamplesTable:114 {115 return GetTableRows(node);116 }117 case RuleType.Description:118 {119 var lineTokens = node.GetTokens(TokenType.Other);120121 // Trim trailing empty lines122 lineTokens = lineTokens.Reverse().SkipWhile(t => string.IsNullOrWhiteSpace(t.MatchedText)).Reverse();123124 return string.Join(Environment.NewLine, lineTokens.Select(lt => lt.MatchedText));125 }126 case RuleType.Feature:127 {128 var header = node.GetSingle<AstNode>(RuleType.FeatureHeader);129 if(header == null) return null;130 var tags = GetTags(header);131 var featureLine = header.GetToken(TokenType.FeatureLine);132 if(featureLine == null) return null;133 var children = new List<IHasLocation> ();134 var background = node.GetSingle<Background>(RuleType.Background);135 if (background != null) 136 {137 children.Add (background);138 }139 var childrenEnumerable = children.Concat(node.GetItems<IHasLocation>(RuleType.ScenarioDefinition))140 .Concat(node.GetItems<IHasLocation>(RuleType.Rule));141 var description = GetDescription(header);142 if(featureLine.MatchedGherkinDialect == null) return null;143 var language = featureLine.MatchedGherkinDialect.Language;144145 return CreateFeature(tags, GetLocation(featureLine), language, featureLine.MatchedKeyword, featureLine.MatchedText, description, childrenEnumerable.ToArray(), node);146 }147 case RuleType.Rule:148 {149 var header = node.GetSingle<AstNode>(RuleType.RuleHeader);150 if (header == null) return null;151 var tags = GetTags(header);152 var ruleLine = header.GetToken(TokenType.RuleLine);153 if (ruleLine == null) return null;154 var children = new List<IHasLocation>();155 var background = node.GetSingle<Background>(RuleType.Background);156 if (background != null)157 {158 children.Add(background);159 }160 var childrenEnumerable = children.Concat(node.GetItems<IHasLocation>(RuleType.ScenarioDefinition));161 var description = GetDescription(header);162 if (ruleLine.MatchedGherkinDialect == null) return null;163 var language = ruleLine.MatchedGherkinDialect.Language;164165 return CreateRule(tags, GetLocation(ruleLine), ruleLine.MatchedKeyword, ruleLine.MatchedText, description, childrenEnumerable.ToArray(), node);166 }167 case RuleType.GherkinDocument:168 {169 var feature = node.GetSingle<Feature>(RuleType.Feature);170171 return CreateGherkinDocument(feature, comments.ToArray(), node);172 }173 }174175 return node;176 }177178 protected virtual Background CreateBackground(Ast.Location location, string keyword, string name, string description, Step[] steps, AstNode node)179 {180 return new Background(location, keyword, name, description, steps);181 }182183 protected virtual DataTable CreateDataTable(TableRow[] rows, AstNode node)184 {185 return new DataTable(rows);186 }187188 protected virtual Comment CreateComment(Ast.Location location, string text)189 {190 return new Comment(location, text);191 }192193 protected virtual Examples CreateExamples(Tag[] tags, Ast.Location location, string keyword, string name, string description, TableRow header, TableRow[] body, AstNode node)194 {195 return new Examples(tags, location, keyword, name, description, header, body);196 }197198 protected virtual Scenario CreateScenario(Tag[] tags, Ast.Location location, string keyword, string name, string description, Step[] steps, Examples[] examples, AstNode node)199 {200 return new Scenario(tags, location, keyword, name, description, steps, examples);201 }202203 protected virtual DocString CreateDocString(Ast.Location location, string contentType, string content, string delimiter, AstNode node)204 {205 return new DocString(location, contentType, content, delimiter);206 }207208 protected virtual Step CreateStep(Ast.Location location, string keyword, string text, StepArgument argument, AstNode node)209 {210 return new Step(location, keyword, text, argument);211 }212213 protected virtual GherkinDocument CreateGherkinDocument(Feature feature, Comment[] gherkinDocumentComments, AstNode node) {214 return new GherkinDocument(feature, gherkinDocumentComments);215 }216217 protected virtual Feature CreateFeature(Tag[] tags, Ast.Location location, string language, string keyword, string name, string description, IHasLocation[] children, AstNode node)218 {219 return new Feature(tags, location, language, keyword, name, description, children);220 }221222 protected virtual Rule CreateRule(Tag[] tags, Ast.Location location, string keyword, string name, string description, IHasLocation[] children, AstNode node)223 {224 return new Rule(tags, location, keyword, name, description, children);225 }226227 protected virtual Tag CreateTag(Ast.Location location, string name, AstNode node)228 {229 return new Tag(location, name);230 }231232 protected virtual Ast.Location CreateLocation(int line, int column)233 {234 return new Ast.Location(line, column);235 }236237 protected virtual TableRow CreateTableRow(Ast.Location location, TableCell[] cells, AstNode node)238 {239 return new TableRow(location, cells);240 }241242 protected virtual TableCell CreateTableCell(Ast.Location location, string value)243 {244 return new TableCell(location, value);245 }246247 private Ast.Location GetLocation(Token token, int column = 0)248 {249 return column == 0 ? token.Location : CreateLocation(token.Location.Line, column);250 }251252 private Tag[] GetTags(AstNode node)253 {254 var tagsNode = node.GetSingle<AstNode>(RuleType.Tags);255 if (tagsNode == null)256 return new Tag[0];257258 return tagsNode.GetTokens(TokenType.TagLine)259 .SelectMany(t => t.MatchedItems, (t, tagItem) =>260 CreateTag(GetLocation(t, tagItem.Column), tagItem.Text, tagsNode))261 .ToArray();262 }263264 private TableRow[] GetTableRows(AstNode node)265 {266 var rows = node.GetTokens(TokenType.TableRow).Select(token => CreateTableRow(GetLocation(token), GetCells(token), node)).ToArray();267 CheckCellCountConsistency(rows);268 return rows;269 }270271 protected virtual void CheckCellCountConsistency(TableRow[] rows)272 {273 if (rows.Length == 0)274 return;275276 int cellCount = rows[0].Cells.Count();277 foreach (var row in rows)278 {279 if (row.Cells.Count() != cellCount)280 {281 HandleAstError("inconsistent cell count within the table", row.Location);282 }283 }284 }285286 protected virtual void HandleAstError(string message, Ast.Location location)287 {288 throw new AstBuilderException(message, location);289 }290291 private TableCell[] GetCells(Token tableRowToken)292 {293 return tableRowToken.MatchedItems294 .Select(cellItem => CreateTableCell(GetLocation(tableRowToken, cellItem.Column), cellItem.Text))295 .ToArray();296 }297298 private static Step[] GetSteps(AstNode scenarioDefinitionNode)299 {300 return scenarioDefinitionNode.GetItems<Step>(RuleType.Step).ToArray();301 }302303 private static string GetDescription(AstNode scenarioDefinitionNode)304 {305 return scenarioDefinitionNode.GetSingle<string>(RuleType.Description);306 }307 }308} ...

Full Screen

Full Screen

DeveroomGherkinParser.cs

Source:DeveroomGherkinParser.cs Github

copy

Full Screen

...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)));146 }147 private void CheckForDuplicateExamples(Feature feature, List<ParserException> errors)148 {149 foreach (var scenarioOutline in feature.FlattenScenarioDefinitions().OfType<ScenarioOutline>())150 {151 var duplicateExamples = scenarioOutline.Examples152 .Where(e => !String.IsNullOrWhiteSpace(e.Name))153 .Where(e => e.Tags.All(t => t.Name != "ignore"))154 .GroupBy(e => e.Name, e => e).Where(g => g.Count() > 1);155 foreach (var duplicateExample in duplicateExamples)156 {157 var message = $"Scenario Outline '{scenarioOutline.Name}' already contains an example with name '{duplicateExample.Key}'";158 var semanticParserException = new SemanticParserException(message, duplicateExample.ElementAt(1).Location);159 errors.Add(semanticParserException);160 }161 }162 }163 private void CheckForMissingExamples(Feature feature, List<ParserException> errors)164 {165 foreach (var scenarioOutline in feature.FlattenScenarioDefinitions().OfType<ScenarioOutline>())166 {167 if (DoesntHavePopulatedExamples(scenarioOutline))168 {169 var message = $"Scenario Outline '{scenarioOutline.Name}' has no examples defined";170 var semanticParserException = new SemanticParserException(message, scenarioOutline.Location);171 errors.Add(semanticParserException);172 }173 }174 }175 private static bool DoesntHavePopulatedExamples(ScenarioOutline scenarioOutline)176 {177 return !scenarioOutline.Examples.Any() || scenarioOutline.Examples.Any(x => x.TableBody == null || !x.TableBody.Any());178 }179 #endregion180 #region Expected tokens181 class NullAstBuilder : IAstBuilder<DeveroomGherkinDocument>182 {183 public void Build(Token token)184 {185 }186 public void StartRule(RuleType ruleType)187 {188 }189 public void EndRule(RuleType ruleType)190 {191 }192 public DeveroomGherkinDocument GetResult()193 {194 return null;195 }196 public void Reset()197 {198 }199 }200 class AllFalseTokenMatcher : ITokenMatcher201 {202 public bool Match_EOF(Token token)203 {204 return false;205 }206 public bool Match_Empty(Token token)207 {208 return false;209 }210 public bool Match_Comment(Token token)211 {212 return false;213 }214 public bool Match_TagLine(Token token)215 {216 return false;217 }218 public bool Match_FeatureLine(Token token)219 {220 return false;221 }222 public bool Match_RuleLine(Token token)223 {224 return false;225 }226 public bool Match_BackgroundLine(Token token)227 {228 return false;229 }230 public bool Match_ScenarioLine(Token token)231 {232 return false;233 }234 public bool Match_ExamplesLine(Token token)235 {236 return false;...

Full Screen

Full Screen

AstMessagesConverter.cs

Source:AstMessagesConverter.cs Github

copy

Full Screen

...7using Comment = Gherkin.CucumberMessages.Types.Comment;8using Examples = Gherkin.CucumberMessages.Types.Examples;9using Feature = Gherkin.CucumberMessages.Types.Feature;10using Location = Gherkin.CucumberMessages.Types.Location;11using Rule = Gherkin.CucumberMessages.Types.Rule;12using Step = Gherkin.CucumberMessages.Types.Step;13using DataTable = Gherkin.CucumberMessages.Types.DataTable;14using DocString = Gherkin.CucumberMessages.Types.DocString;15using GherkinDocument = Gherkin.CucumberMessages.Types.GherkinDocument;16using Scenario = Gherkin.CucumberMessages.Types.Scenario;17using TableCell = Gherkin.CucumberMessages.Types.TableCell;18using TableRow = Gherkin.CucumberMessages.Types.TableRow;19using Tag = Gherkin.CucumberMessages.Types.Tag;20namespace Gherkin.CucumberMessages21{22 public class AstMessagesConverter23 {24 private readonly IIdGenerator _idGenerator;25 public AstMessagesConverter(IIdGenerator idGenerator)26 {27 _idGenerator = idGenerator;28 }29 public GherkinDocument ConvertGherkinDocumentToEventArgs(Ast.GherkinDocument gherkinDocument, string sourceEventUri)30 {31 return new GherkinDocument()32 {33 Uri = sourceEventUri,34 Feature = ConvertFeature(gherkinDocument),35 Comments = ConvertComments(gherkinDocument)36 };37 }38 private IReadOnlyCollection<Comment> ConvertComments(Ast.GherkinDocument gherkinDocument)39 {40 return gherkinDocument.Comments.Select(c =>41 new Comment()42 {43 Text = c.Text,44 Location = ConvertLocation(c.Location)45 }).ToReadOnlyCollection();46 }47 private Feature ConvertFeature(Ast.GherkinDocument gherkinDocument)48 {49 var feature = gherkinDocument.Feature;50 if (feature == null)51 {52 return null;53 }54 var children = feature.Children.Select(ConvertToFeatureChild).ToReadOnlyCollection();55 var tags = feature.Tags.Select(ConvertTag).ToReadOnlyCollection();56 return new Feature()57 {58 Name = CucumberMessagesDefaults.UseDefault(feature.Name, CucumberMessagesDefaults.DefaultName),59 Description = CucumberMessagesDefaults.UseDefault(feature.Description, CucumberMessagesDefaults.DefaultDescription),60 Keyword = feature.Keyword,61 Language = feature.Language,62 Location = ConvertLocation(feature.Location),63 Children = children,64 Tags = tags65 };66 }67 private static Location ConvertLocation(Ast.Location location)68 {69 return new Location(location.Column, location.Line);70 }71 private FeatureChild ConvertToFeatureChild(IHasLocation hasLocation)72 {73 var tuple = ConvertToChild(hasLocation);74 return new FeatureChild(tuple.Item3, tuple.Item1, tuple.Item2);75 }76 77 private RuleChild ConvertToRuleChild(IHasLocation hasLocation)78 {79 var tuple = ConvertToChild(hasLocation);80 return new RuleChild(tuple.Item1, tuple.Item3);81 }82 83 private Tuple<Background, Rule, Scenario> ConvertToChild(IHasLocation hasLocation)84 {85 switch (hasLocation)86 {87 case Gherkin.Ast.Background background:88 var backgroundSteps = background.Steps.Select(ConvertStep).ToList();89 return new Tuple<Background, Rule, Scenario>(new Background90 {91 Id = _idGenerator.GetNewId(),92 Location = ConvertLocation(background.Location),93 Name = CucumberMessagesDefaults.UseDefault(background.Name, CucumberMessagesDefaults.DefaultName),94 Description = CucumberMessagesDefaults.UseDefault(background.Description, CucumberMessagesDefaults.DefaultDescription),95 Keyword = background.Keyword,96 Steps = backgroundSteps97 }, null, null);98 case Ast.Scenario scenario:99 var steps = scenario.Steps.Select(ConvertStep).ToList();100 var examples = scenario.Examples.Select(ConvertExamples).ToReadOnlyCollection();101 var tags = scenario.Tags.Select(ConvertTag).ToReadOnlyCollection();102 return new Tuple<Background, Rule, Scenario>(null, null, new Scenario()103 {104 Id = _idGenerator.GetNewId(),105 Keyword = scenario.Keyword,106 Location = ConvertLocation(scenario.Location),107 Name = CucumberMessagesDefaults.UseDefault(scenario.Name, CucumberMessagesDefaults.DefaultName),108 Description = CucumberMessagesDefaults.UseDefault(scenario.Description, CucumberMessagesDefaults.DefaultDescription),109 Steps = steps,110 Examples = examples,111 Tags = tags112 });113 case Ast.Rule rule:114 {115 var ruleChildren = rule.Children.Select(ConvertToRuleChild).ToReadOnlyCollection();116 var ruleTags = rule.Tags.Select(ConvertTag).ToReadOnlyCollection();117 return new Tuple<Background, Rule, Scenario>(null, new Rule118 {119 Id = _idGenerator.GetNewId(),120 Name = CucumberMessagesDefaults.UseDefault(rule.Name, CucumberMessagesDefaults.DefaultName),121 Description = CucumberMessagesDefaults.UseDefault(rule.Description, CucumberMessagesDefaults.DefaultDescription),122 Keyword = rule.Keyword,123 Children = ruleChildren,124 Location = ConvertLocation(rule.Location),125 Tags = ruleTags126 }, null);127 }128 default:129 throw new NotImplementedException();130 }131 }...

Full Screen

Full Screen

DomBuilder.cs

Source:DomBuilder.cs Github

copy

Full Screen

...28 public object BuildFromNode(ASTNode astNode)29 {30 switch (astNode.Node)31 {32 case RuleType.Description:33 return string.Join(Environment.NewLine, astNode.GetAllSubNodes().Cast<Token>().Select(t => t.Text));34 case RuleType.Multiline_Arg:35 {36 int indent = astNode.GetSubNodesOf(RuleType._MultiLineArgument).Cast<Token>().First().Indent; //TODO: use indent37 return string.Join(Environment.NewLine, astNode.GetAllSubNodes().Cast<Token>().Where(t => t.MatchedType != TokenType.MultiLineArgument).Select(t => t.Text)); //TODO: indent38 }39 case RuleType.Table_Arg:40 case RuleType.Examples_Table:41 {42 var rows = astNode.GetSubNodesOf(RuleType._TableRow).Cast<GherkinTableRow>().ToArray();43 var header = rows.First();44 return new GherkinTable(header, rows.Skip(1).ToArray());45 }46 case RuleType.Step:47 {48 var stepToken = astNode.GetSubNodesOf(RuleType._Step).Cast<Token>().First();49 var step = CreateStep(stepToken.MatchedKeyword, StepKeyword.Given, stepToken.Text, null, ScenarioBlock.Given); //TODO: G/W/T50 step.MultiLineTextArgument = astNode.GetSubNodesOf(RuleType.Multiline_Arg).Cast<string>().FirstOrDefault();51 step.TableArg = astNode.GetSubNodesOf(RuleType.Table_Arg).Cast<GherkinTable>().FirstOrDefault();52 return step;53 }54 case RuleType.Background:55 {56 var backgroundToken = astNode.GetSubNodesOf(RuleType._Background).Cast<Token>().First();57 var description = astNode.GetSubNodesOf(RuleType.Description).Cast<string>().FirstOrDefault();58 var steps = astNode.GetSubNodesOf(RuleType.Step).Cast<ScenarioStep>().ToArray();59 return new Background(backgroundToken.MatchedKeyword, backgroundToken.Text, description, new ScenarioSteps(steps));60 }61 case RuleType.Scenario:62 {63 //Tags will be added at Scenario_Base64 var scenarioToken = astNode.GetSubNodesOf(RuleType._Scenario).Cast<Token>().First();65 var description = astNode.GetSubNodesOf(RuleType.Description).Cast<string>().FirstOrDefault();66 var steps = astNode.GetSubNodesOf(RuleType.Step).Cast<ScenarioStep>().ToArray();67 return new Scenario(scenarioToken.MatchedKeyword, scenarioToken.Text, description, null, new ScenarioSteps(steps));68 }69 case RuleType.ScenarioOutline:70 {71 //Tags will be added at Scenario_Base72 var scenarioToken = astNode.GetSubNodesOf(RuleType._ScenarioOutline).Cast<Token>().First();73 var description = astNode.GetSubNodesOf(RuleType.Description).Cast<string>().FirstOrDefault();74 var steps = astNode.GetSubNodesOf(RuleType.Step).Cast<ScenarioStep>().ToArray();75 var exampleSets = astNode.GetSubNodesOf(RuleType.Examples).Cast<ExampleSet>().ToArray();76 return new ScenarioOutline(scenarioToken.MatchedKeyword, scenarioToken.Text, description, null, new ScenarioSteps(steps), new Examples(exampleSets));77 }78 case RuleType.Scenario_Base:79 {80 var tags = astNode.GetAllSubNodes().OfType<Tag>().ToArray();81 var scenario = astNode.GetAllSubNodes().OfType<Scenario>().First();82 scenario.Tags = new Tags(tags);83 return scenario;84 }85 case RuleType.Examples:86 {87 var examplesToken = astNode.GetSubNodesOf(RuleType._Examples).Cast<Token>().First();88 var description = astNode.GetSubNodesOf(RuleType.Description).Cast<string>().FirstOrDefault();89 var tags = astNode.GetAllSubNodes().OfType<Tag>().ToArray();90 var table = astNode.GetSubNodesOf(RuleType.Examples_Table).Cast<GherkinTable>().First();91 return new ExampleSet(examplesToken.MatchedKeyword, examplesToken.Text, description, new Tags(tags), table);92 }93 case RuleType.Feature_File:94 {95 var featureDef = astNode.GetSubNodesOf(RuleType.Feature_Def).Cast<ASTNode>().First();96 var featureToken = featureDef.GetSubNodesOf(RuleType._Feature).Cast<Token>().First();97 var description = featureDef.GetSubNodesOf(RuleType.Description).Cast<string>().FirstOrDefault();98 var tags = featureDef.GetAllSubNodes().OfType<Tag>().ToArray();99 var background = astNode.GetSubNodesOf(RuleType.Background).Cast<Background>().FirstOrDefault();100 var scenarios = astNode.GetSubNodesOf(RuleType.Scenario_Base).Cast<Scenario>().ToArray();101 return new Feature(featureToken.MatchedKeyword, featureToken.Text, new Tags(tags), description, background, scenarios, null); //TODO: comments;102 }103 }104 return astNode;105 }106 public ScenarioStep CreateStep(string keyword, StepKeyword stepKeyword, string text, FilePosition position, ScenarioBlock scenarioBlock)107 {108 ScenarioStep step;109 switch (stepKeyword)110 {111 case StepKeyword.Given:112 step = new Given();113 break;114 case StepKeyword.When:...

Full Screen

Full Screen

AstEventConverter.cs

Source:AstEventConverter.cs Github

copy

Full Screen

...6using Comment = Gherkin.Events.Args.Ast.Comment;7using Examples = Gherkin.Events.Args.Ast.Examples;8using Feature = Gherkin.Events.Args.Ast.Feature;9using Location = Gherkin.Events.Args.Ast.Location;10using Rule = Gherkin.Events.Args.Ast.Rule;11using Step = Gherkin.Events.Args.Ast.Step;12using StepsContainer = Gherkin.Events.Args.Ast.StepsContainer;13namespace Gherkin.Stream.Converter14{15 public class AstEventConverter16 {17 public GherkinDocumentEventArgs ConvertGherkinDocumentToEventArgs(GherkinDocument gherkinDocument, string sourceEventUri)18 {19 return new GherkinDocumentEventArgs()20 {21 Uri = sourceEventUri,22 Feature = ConvertFeature(gherkinDocument),23 Comments = ConvertComments(gherkinDocument)24 };25 }26 private IReadOnlyCollection<Comment> ConvertComments(GherkinDocument gherkinDocument)27 {28 return gherkinDocument.Comments.Select(c =>29 new Comment()30 {31 Text = c.Text,32 Location = ConvertLocation(c.Location)33 }).ToReadOnlyCollection();34 }35 private Feature ConvertFeature(GherkinDocument gherkinDocument)36 {37 var feature = gherkinDocument.Feature;38 if (feature == null)39 {40 return null;41 }42 return new Feature()43 {44 Name = feature.Name == string.Empty ? null : feature.Name,45 Keyword = feature.Keyword,46 Language = feature.Language,47 Location = ConvertLocation(feature.Location),48 Children = feature.Children.Select(ConvertToChildren).ToReadOnlyCollection()49 };50 }51 private static Location ConvertLocation(Ast.Location location)52 {53 return new Location(location.Column, location.Line);54 }55 private Children ConvertToChildren(IHasLocation hasLocation)56 {57 switch (hasLocation)58 {59 case Background background:60 return new Children()61 {62 Background = new StepsContainer()63 {64 Location = ConvertLocation(background.Location),65 Name = background.Name == string.Empty ? null : background.Name,66 Keyword = background.Keyword,67 Steps = background.Steps.Select(s => ConvertStep(s)).ToList()68 }69 };70 case Scenario scenario:71 return new Children()72 {73 Scenario = new StepsContainer()74 {75 Keyword = scenario.Keyword,76 Location = ConvertLocation(scenario.Location),77 Name = scenario.Name == string.Empty ? null : scenario.Name,78 Steps = scenario.Steps.Select(s => ConvertStep(s)).ToList(),79 Examples = scenario.Examples.Select(ConvertExamples).ToReadOnlyCollection(),80 }81 };82 case Ast.Rule rule:83 {84 return new Children()85 {86 Rule = new Rule()87 {88 Name = rule.Name == string.Empty ? null : rule.Name,89 Keyword = rule.Keyword,90 Children = rule.Children.Select(ConvertToChildren).ToReadOnlyCollection(),91 Location = ConvertLocation(rule.Location)92 }93 };94 }95 default:96 throw new NotImplementedException();97 }98 }99 private Examples ConvertExamples(Ast.Examples examples)100 {...

Full Screen

Full Screen

GherkinDialectProvider.cs

Source:GherkinDialectProvider.cs Github

copy

Full Screen

...105 {106 return new GherkinDialect(107 "en",108 new[] {"Feature"},109 new[] {"Rule"},110 new[] {"Background"},111 new[] {"Scenario"},112 new[] {"Scenario Outline", "Scenario Template"},113 new[] {"Examples", "Scenarios"},114 new[] {"* ", "Given "},115 new[] {"* ", "When " },116 new[] {"* ", "Then " },117 new[] {"* ", "And " },118 new[] {"* ", "But " });119 }120 }121122 public class GherkinLanguageSetting123 { ...

Full Screen

Full Screen

GherkinEditorParser.cs

Source:GherkinEditorParser.cs Github

copy

Full Screen

...99 {100 public void Build(Token token)101 {102 }103 public void StartRule(RuleType ruleType)104 {105 }106 public void EndRule(RuleType ruleType)107 {108 }109 public object GetResult()110 {111 return null;112 }113 public void Reset()114 {115 116 }117 }118 public static TokenType[] GetExpectedTokens(int state)119 {120 var parser = new GherkinEditorParser(new GherkinTokenTagBuilder(null))...

Full Screen

Full Screen

GherkinAstExtensions.cs

Source:GherkinAstExtensions.cs Github

copy

Full Screen

...8 public static class GherkinAstExtensions9 {10 public static IEnumerable<StepsContainer> StepsContainers(this IHasChildren container)11 => container.Children.OfType<StepsContainer>();12 public static IEnumerable<StepsContainer> FlattenStepsContainers(this IHasChildren featureOrRule)13 {14 foreach (var featureChild in featureOrRule.Children)15 {16 if (featureChild is StepsContainer stepsContainer)17 yield return stepsContainer;18 else if (featureChild is IHasChildren containerNode)19 foreach (var ruleStepsContainer in containerNode.StepsContainers())20 {21 yield return ruleStepsContainer;22 }23 }24 }25 public static IEnumerable<Scenario> ScenarioDefinitions(this IHasChildren container)26 => container.Children.OfType<Scenario>();27 public static IEnumerable<Scenario> FlattenScenarioDefinitions(this IHasChildren featureOrRule)28 => featureOrRule.FlattenStepsContainers().OfType<Scenario>();29 public static IEnumerable<Rule> Rules(this Feature feature)30 => feature.Children.OfType<Rule>();31 public static Background Background(this Feature feature)32 => feature.Children.OfType<Background>().FirstOrDefault();33 public static ScenarioBlock? ToScenarioBlock(this StepKeyword stepKeyword)34 {35 switch (stepKeyword)36 {37 case StepKeyword.Given:38 return ScenarioBlock.Given;39 case StepKeyword.When:40 return ScenarioBlock.When;41 case StepKeyword.Then:42 return ScenarioBlock.Then;43 }44 return null;...

Full Screen

Full Screen

Rule

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.Ast;7{8 {9 static void Main(string[] args)10 {11 Rule rule = new Rule();12 rule.KeyWord = "Rule";13 rule.Name = "Rule1";14 rule.Description = "Rule1 Description";15 rule.Location = new Location(1, 1);16 Console.WriteLine(rule.Keyword + " " + rule.Name + " " + rule.Description + " " + rule.Location.Column + " " + rule.Location.Line);17 }18 }19}

Full Screen

Full Screen

Rule

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.Ast;7{8 {9 static void Main(string[] args)10 {11 Rule rule = new Rule("rule1", new List<Step>(), new List<Tag>());12 Console.WriteLine(rule.Keyword);13 Console.WriteLine(rule.Name);14 Console.WriteLine(rule.Description);15 Console.WriteLine(rule.Steps);16 Console.WriteLine(rule.Tags);17 Console.WriteLine(rule.Location);18 Console.WriteLine(rule.Comments);19 Console.WriteLine(rule.Id);20 Console.WriteLine(rule.ToString());21 Console.WriteLine(rule.GetHashCode());22 Console.WriteLine(rule.GetType());23 Console.WriteLine(rule.Equals(rule));24 Console.WriteLine(rule.Equals(null));25 Console.ReadLine();26 }27 }28}

Full Screen

Full Screen

Rule

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.Ast;7{8 {9 static void Main(string[] args)10 {11 Rule rule = new Rule("rule1", new List<Tag>(), "Scenario: scenario1", new List<Step>());12 Console.WriteLine(rule.RuleKeyword);13 Console.WriteLine(rule.RuleName);14 Console.WriteLine(rule.RuleLine);15 Console.WriteLine(rule.ScenarioDefinition.Keyword);16 Console.WriteLine(rule.ScenarioDefinition.Name);17 Console.WriteLine(rule.ScenarioDefinition.Line);18 Console.WriteLine(rule.ScenarioDefinition.Steps[0].Keyword);19 Console.WriteLine(rule.ScenarioDefinition.Steps[0].Text);20 Console.WriteLine(rule.ScenarioDefinition.Steps[0].Line);21 Console.ReadLine();22 }23 }24}25using System;26using System.Collections.Generic;27using System.Linq;28using System.Text;29using System.Threading.Tasks;30using Gherkin.Parser;31{32 {33 static void Main(string[] args)34 {35 Parser parser = new Parser();36 Rule rule = parser.ParseRule("Rule: rule137Given step1");38 Console.WriteLine(rule.RuleKeyword);39 Console.WriteLine(rule.RuleName);40 Console.WriteLine(rule.RuleLine);41 Console.WriteLine(rule.ScenarioDefinition.Keyword);42 Console.WriteLine(rule.ScenarioDefinition.Name);43 Console.WriteLine(rule.ScenarioDefinition.Line);44 Console.WriteLine(rule.ScenarioDefinition.Steps[0].Keyword);45 Console.WriteLine(rule.ScenarioDefinition.Steps[0].Text);46 Console.WriteLine(rule.ScenarioDefinition.Steps[0].Line);47 Console.ReadLine();48 }49 }50}51using System;52using System.Collections.Generic;53using System.Linq;54using System.Text;55using System.Threading.Tasks;56using Gherkin.Parser;57{58 {59 static void Main(string[] args)60 {

Full Screen

Full Screen

Rule

Using AI Code Generation

copy

Full Screen

1using Gherkin.Ast;2using Gherkin.Parser;3using Gherkin.TokenMatcher;4using Gherkin.Util;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 static void Main(string[] args)13 {14 Parser<GherkinDocument> parser = new Parser<GherkinDocument>(new AstBuilder());15 GherkinDocument gherkinDocument = parser.Parse("Feature: test16");17 Rule rule = gherkinDocument.Feature.Children[0].Rule;18 Console.WriteLine(rule.Keyword);19 Console.WriteLine(rule.Name);20 Console.WriteLine(rule.Line);21 Console.ReadLine();22 }23 }24}

Full Screen

Full Screen

Rule

Using AI Code Generation

copy

Full Screen

1using Gherkin.Ast;2Rule r = new Rule();3r.RuleMethod();4using Gherkin.Ast;5Rule r = new Rule();6r.RuleMethod();7using Gherkin.Ast;8Rule r = new Rule();9r.RuleMethod();10using Gherkin.Ast;11Rule r = new Rule();12r.RuleMethod();13using Gherkin.Ast;14Rule r = new Rule();15r.RuleMethod();16using Gherkin.Ast;17Rule r = new Rule();18r.RuleMethod();19using Gherkin.Ast;20Rule r = new Rule();21r.RuleMethod();22using Gherkin.Ast;23Rule r = new Rule();24r.RuleMethod();25using Gherkin.Ast;26Rule r = new Rule();27r.RuleMethod();28using Gherkin.Ast;29Rule r = new Rule();30r.RuleMethod();31using Gherkin.Ast;32Rule r = new Rule();33r.RuleMethod();34using Gherkin.Ast;35Rule r = new Rule();36r.RuleMethod();37using Gherkin.Ast;38Rule r = new Rule();39r.RuleMethod();

Full Screen

Full Screen

Rule

Using AI Code Generation

copy

Full Screen

1using Gherkin.Ast;2{3 {4 static void Main(string[] args)5 {6 Console.WriteLine("Hello World!");7 var rule = new Rule("Rule1", new Location(1, 1), new List<ITag>(), "Rule1", "Rule1", new List<Step>(), new List<Background>(), new List<ScenarioDefinition>(), new List<Comment>(), new List<DataTableRow>(), new List<Tag>());8 var rule1 = rule.Rule1;9 var rule2 = rule.Rule2;10 var rule3 = rule.Rule3;11 var rule4 = rule.Rule4;12 var rule5 = rule.Rule5;13 var rule6 = rule.Rule6;14 var rule7 = rule.Rule7;15 var rule8 = rule.Rule8;16 var rule9 = rule.Rule9;17 var rule10 = rule.Rule10;18 var rule11 = rule.Rule11;19 var rule12 = rule.Rule12;20 var rule13 = rule.Rule13;21 var rule14 = rule.Rule14;22 var rule15 = rule.Rule15;23 var rule16 = rule.Rule16;24 var rule17 = rule.Rule17;25 var rule18 = rule.Rule18;26 var rule19 = rule.Rule19;27 var rule20 = rule.Rule20;28 var rule21 = rule.Rule21;29 var rule22 = rule.Rule22;30 var rule23 = rule.Rule23;31 var rule24 = rule.Rule24;32 var rule25 = rule.Rule25;33 var rule26 = rule.Rule26;34 var rule27 = rule.Rule27;35 var rule28 = rule.Rule28;36 var rule29 = rule.Rule29;37 var rule30 = rule.Rule30;38 var rule31 = rule.Rule31;39 var rule32 = rule.Rule32;40 var rule33 = rule.Rule33;41 var rule34 = rule.Rule34;42 var rule35 = rule.Rule35;43 var rule36 = rule.Rule36;44 var rule37 = rule.Rule37;45 var rule38 = rule.Rule38;46 var rule39 = rule.Rule39;47 var rule40 = rule.Rule40;48 var rule41 = rule.Rule41;49 var rule42 = rule.Rule42;50 var rule43 = rule.Rule43;51 var rule44 = rule.Rule44;

Full Screen

Full Screen

Rule

Using AI Code Generation

copy

Full Screen

1Gherkin.Ast.Rule rule = new Gherkin.Ast.Rule();2rule.Name = "rule1";3rule.Description = "rule1 description";4rule.RuleType = Gherkin.Ast.RuleType.Given;5rule.Expression = "rule1 expression";6Gherkin.Ast.Feature feature = new Gherkin.Ast.Feature();7feature.Name = "feature1";8feature.Description = "feature1 description";9feature.FeatureType = Gherkin.Ast.FeatureType.Given;10feature.Expression = "feature1 expression";11Gherkin.Ast.Scenario scenario = new Gherkin.Ast.Scenario();12scenario.Name = "scenario1";13scenario.Description = "scenario1 description";14scenario.ScenarioType = Gherkin.Ast.ScenarioType.Given;15scenario.Expression = "scenario1 expression";16Gherkin.Ast.ScenarioOutline scenarioOutline = new Gherkin.Ast.ScenarioOutline();17scenarioOutline.Name = "scenarioOutline1";18scenarioOutline.Description = "scenarioOutline1 description";19scenarioOutline.ScenarioOutlineType = Gherkin.Ast.ScenarioOutlineType.Given;20scenarioOutline.Expression = "scenarioOutline1 expression";21Gherkin.Ast.Background background = new Gherkin.Ast.Background();22background.Name = "background1";23background.Description = "background1 description";24background.BackgroundType = Gherkin.Ast.BackgroundType.Given;25background.Expression = "background1 expression";26Gherkin.Ast.Examples examples = new Gherkin.Ast.Examples();27examples.Name = "examples1";28examples.Description = "examples1 description";29examples.ExamplesType = Gherkin.Ast.ExamplesType.Given;30examples.Expression = "examples1 expression";31Gherkin.Ast.Step step = new Gherkin.Ast.Step();

Full Screen

Full Screen

Rule

Using AI Code Generation

copy

Full Screen

1public void Rule()2{3 Rule rule = new Rule();4 rule.Keyword = "Rule";5 rule.Name = "Rule name";6 rule.Description = "Rule description";7 rule.Location = new Location(1, 1);8 rule.Line = 1;9 rule.Column = 1;10 string keyword = rule.Keyword;11 string name = rule.Name;12 string description = rule.Description;13 Location location = rule.Location;14 int line = rule.Line;15 int column = rule.Column;16}17public void Rule()18{19 Rule rule = new Rule();20 rule.Keyword = "Rule";21 rule.Name = "Rule name";22 rule.Description = "Rule description";23 rule.Location = new Location(1, 1);24 rule.Line = 1;25 rule.Column = 1;26 string keyword = rule.Keyword;27 string name = rule.Name;28 string description = rule.Description;29 Location location = rule.Location;30 int line = rule.Line;31 int column = rule.Column;32}

Full Screen

Full Screen

Rule

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.Ast;7{8 {9 static void Main(string[] args)10 {11 var rule = new Rule("First Rule", "First Rule Description");12 Console.WriteLine(rule.Keyword);13 Console.WriteLine(rule.Name);14 Console.WriteLine(rule.Description);15 Console.ReadKey();16 }17 }18}19using System;20using System.Collections.Generic;21using System.Linq;22using System.Text;23using System.Threading.Tasks;24using Gherkin.Ast;25{26 {27 static void Main(string[] args)28 {29 var step = new Step("Given", "I am on the home page", 0, null, null);30 Console.WriteLine(step.Keyword);31 Console.WriteLine(step.Text);32 Console.WriteLine(step.Location.Line);33 Console.WriteLine(step.DocString);34 Console.WriteLine(step.DataTable);35 Console.ReadKey();36 }37 }38}

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 Rule

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful