-
Notifications
You must be signed in to change notification settings - Fork 108
Add support for Tag Expressions #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clrudolphi
wants to merge
28
commits into
main
Choose a base branch
from
Exploratory_TagExpression_Support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
44fd54a
Initial commit. This adds support for tag exprssions on Scopes assign…
clrudolphi 416be89
Fix an issue in which the BindingProviderService (as invoked OOP and …
clrudolphi bf7d969
Merge branch 'main' into Exploratory_TagExpression_Support
clrudolphi 20b0f08
Draft update to the documentation on the topic of tag expressions
clrudolphi 71e6fcc
File scope namespace for the ReqnrollTagExpressionParser.
clrudolphi cf3a071
Merge branch 'Documentation_for_Tag_Expressions' into Exploratory_Tag…
clrudolphi 467c8da
Merge branch 'main' into Exploratory_TagExpression_Support
clrudolphi 7033a85
Added nuget package reference to Cucumber.TagExpressions; dropping th…
clrudolphi 193f22c
Merge branch 'main' into Exploratory_TagExpression_Support
clrudolphi d6cbd0a
Update CHANGELOG.md
clrudolphi 67103d0
Merge branch 'main' into Exploratory_TagExpression_Support
304NotModified 259e77b
Update CHANGELOG.md
304NotModified 8e44510
code cleanup
gasparnagy 4d45031
Merge remote-tracking branch 'origin/main' into Exploratory_TagExpres…
gasparnagy d827d4d
Changes per review comments:
clrudolphi 98946cf
Update scoped-bindings.md
clrudolphi 7246af2
code cleanup
gasparnagy 80b5986
fix BindingProviderService to work with empty Tag
gasparnagy f7dd139
Wrapping tag parsing errors in a new type of ITagExpression which dri…
clrudolphi 1627faa
Merge branch 'main' into Exploratory_TagExpression_Support
clrudolphi 5d060d7
Updated tests.
clrudolphi 4403a3e
Added properties to surface tag expression errors via BindingSourcePr…
clrudolphi ec0263a
Refactored tag expression support with addition of a ReqnollTagExpres…
clrudolphi fa433c4
Fix ReqnrollTagExpression missing ToString() override
clrudolphi d472a88
Merge branch 'main' into Exploratory_TagExpression_Support
clrudolphi 813d9c2
small fixes
gasparnagy 74dfbc3
Merge remote-tracking branch 'origin/main' into Exploratory_TagExpres…
gasparnagy e9566b4
Adjusted acceptance test file for tag-expressions Formatters test sce…
clrudolphi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Reqnroll/Bindings/Discovery/IReqnrollTagExpressionParser.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using Cucumber.TagExpressions; | ||
|
|
||
| namespace Reqnroll.Bindings.Discovery; | ||
|
|
||
| /// <summary> | ||
| /// Defines a parser for tag expressions. | ||
| /// </summary> | ||
| public interface IReqnrollTagExpressionParser | ||
| { | ||
| /// <summary> | ||
| /// Parses the specified text into an <see cref="ITagExpression"/>. | ||
| /// </summary> | ||
| /// <param name="text">The tag expression string to parse.</param> | ||
| /// <returns>An <see cref="ITagExpression"/> representing the parsed expression.</returns> | ||
| ITagExpression Parse(string text); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using Cucumber.TagExpressions; | ||
| using System; | ||
|
|
||
| namespace Reqnroll.Bindings.Discovery; | ||
| public class InvalidTagExpression(ITagExpression expression, string originalTagExpression, string message) : ReqnrollTagExpression(expression, originalTagExpression) | ||
| { | ||
| public string Message { get; } = message; | ||
|
|
||
| public override bool Evaluate(System.Collections.Generic.IEnumerable<string> tags) | ||
| { | ||
| throw new InvalidOperationException("Cannot evaluate an invalid tag expression: " + Message); | ||
| } | ||
| public override string ToString() | ||
| { | ||
| return "Invalid tag expression: " + Message; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using Cucumber.TagExpressions; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Reqnroll.Bindings.Discovery; | ||
|
|
||
| public class ReqnrollTagExpression(ITagExpression inner, string tagExpressionText) : ITagExpression | ||
| { | ||
| public string TagExpressionText { get; } = tagExpressionText; | ||
|
|
||
| public override string ToString() | ||
| { | ||
| return inner.ToString(); | ||
| } | ||
|
|
||
| public virtual bool Evaluate(IEnumerable<string> inputs) | ||
| { | ||
| return inner.Evaluate(inputs); | ||
| } | ||
| } |
65 changes: 65 additions & 0 deletions
65
Reqnroll/Bindings/Discovery/ReqnrollTagExpressionParser.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| using Cucumber.TagExpressions; | ||
| using System; | ||
|
|
||
| namespace Reqnroll.Bindings.Discovery; | ||
|
|
||
| public class ReqnrollTagExpressionParser : IReqnrollTagExpressionParser | ||
| { | ||
| public ITagExpression Parse(string tagExpression) | ||
| { | ||
| var tagExpressionParser = new TagExpressionParser(); | ||
| try | ||
| { | ||
| var result = tagExpressionParser.Parse(tagExpression); | ||
| result = Rewrite(result); | ||
| return new ReqnrollTagExpression(result, tagExpression); | ||
| } | ||
| catch (TagExpressionException ex) | ||
| { | ||
| var msg = ex.Message; | ||
| if (ex.TagToken != null) | ||
| { | ||
| msg += $" (at offset {ex.TagToken.Position})"; | ||
| } | ||
| return new InvalidTagExpression(null, tagExpression, msg); | ||
| } | ||
| } | ||
|
|
||
| // iff the expression is a literal node, prefix it with '@' if not already present | ||
| private ITagExpression Rewrite(ITagExpression expression) | ||
| { | ||
| if (expression is LiteralNode) | ||
| { | ||
| return PrefixLiteralNode(expression); | ||
| } | ||
| if (ConfirmExpressionHasAtPrefixes(expression)) | ||
| return expression; | ||
| throw new TagExpressionException("In multi-term tag expressions, all tag names must start with '@'."); | ||
| } | ||
|
|
||
| private bool ConfirmExpressionHasAtPrefixes(ITagExpression expression) | ||
| { | ||
| switch (expression) | ||
| { | ||
| case NullExpression: | ||
| return true; | ||
| case BinaryOpNode binaryNode: | ||
| return ConfirmExpressionHasAtPrefixes(binaryNode.Left) && ConfirmExpressionHasAtPrefixes(binaryNode.Right); | ||
| case NotNode notNode: | ||
| return ConfirmExpressionHasAtPrefixes(notNode.Operand); | ||
| case LiteralNode literalNode: | ||
| return literalNode.Name.StartsWith("@"); | ||
| default: | ||
| throw new InvalidOperationException($"Unknown tag expression node type: {expression.GetType().FullName}"); | ||
| } | ||
| } | ||
|
|
||
| private ITagExpression PrefixLiteralNode(ITagExpression expression) | ||
| { | ||
| var literalNode = (LiteralNode)expression; | ||
| if (literalNode.Name.IsNullOrEmpty() || literalNode.Name.StartsWith("@")) | ||
| return literalNode; | ||
|
|
||
| return new LiteralNode("@" + literalNode.Name); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.