Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## Improvements:

## Bug fixes:

*Contributors of this release (in alphabetical order):*
* Fix: Ambiguous steps reported wehn definition matches via more than one tag (#95)
*Contributors of this release (in alphabetical order):* @clrudolphi

# v2025.1.256 - 2025-03-07

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Reqnroll.VisualStudio.Discovery;
public class ProjectBindingImplementationEqualityComparer : IEqualityComparer<ProjectBindingImplementation>
{
public bool Equals(ProjectBindingImplementation x, ProjectBindingImplementation y)
{
if (ReferenceEquals(x, y)) return true;
if (x is null || y is null) return false;

return x.Method == y.Method &&
x.ParameterTypes.SequenceEqual(y.ParameterTypes) &&
Equals(x.SourceLocation, y.SourceLocation);
}

public int GetHashCode(ProjectBindingImplementation obj)
{
if (obj is null) return 0;

unchecked // Use unchecked to handle potential integer overflow
{
int hash = 17;
hash = hash * 23 + (obj.Method?.GetHashCode() ?? 0);

foreach (var paramType in obj.ParameterTypes)
hash = hash * 23 + (paramType?.GetHashCode() ?? 0);

hash = hash * 23 + (obj.SourceLocation?.GetHashCode() ?? 0);
return hash;
}
}
}
10 changes: 9 additions & 1 deletion Reqnroll.VisualStudio/Discovery/ProjectBindingRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
private const string DocStringDefaultTypeName = TypeShortcuts.StringType;
public static ProjectBindingRegistry Invalid = new(ImmutableArray<ProjectStepDefinitionBinding>.Empty, ImmutableArray<ProjectHookBinding>.Empty);

private static ProjectBindingImplementationEqualityComparer _equalityComparerForProjectBindingImplementations = new();
private static int _versionCounter;

private ProjectBindingRegistry(IEnumerable<ProjectStepDefinitionBinding> stepDefinitions, IEnumerable<ProjectHookBinding> hooks)
Expand Down Expand Up @@ -186,7 +187,14 @@
var matchesWithScope = sdMatches.Where(m =>
m.MatchedStepDefinition.Scope != null).ToArray();
if (matchesWithScope.Any())
sdMatches = matchesWithScope;
{
// Group matches by everything except the Scope property
// and take the first item from each group
sdMatches = matchesWithScope
.GroupBy(m => m.MatchedStepDefinition.Implementation, _equalityComparerForProjectBindingImplementations)
.Select(g => g.First())
.ToArray();
}
}

return sdMatches;
Expand Down Expand Up @@ -216,7 +224,7 @@
{
var stepDefinitionParser = new StepDefinitionFileParser();
var projectStepDefinitionBindings = await stepDefinitionParser.Parse(stepDefinitionFile);
return Where(binding => binding.Implementation.SourceLocation.SourceFile != stepDefinitionFile.FullName)

Check warning on line 227 in Reqnroll.VisualStudio/Discovery/ProjectBindingRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
.WithStepDefinitions(projectStepDefinitionBindings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,33 @@ Scenario: Matches combination scoped step definitions
"""
And no binding error should be highlighted

Scenario: Matches on multiple tags (without improperly highlighting as Ambiguous)
Given there is a Reqnroll project scope
And the following step definition with mulitple Tag Scopes in the project:
| type | regex | tag scope |
| When | I use a step with multiple tags | @mytag1,@mytag2 |
When the following feature file is opened in the editor
"""
Feature: Addition

@mytag1
@mytag2
Scenario: Random scenario
When I use a step with multiple tags

"""
And the project is built and the initial binding discovery is performed
Then all section of types DefinedStep should be highlighted as
"""
Feature: Addition

@mytag1
@mytag2
Scenario: Random scenario
When {DefinedStep}I use a step with multiple tags{/DefinedStep}
"""
And no binding error should be highlighted

Scenario: Analyses all scopes of background steps
Given there is a Reqnroll project scope
And the following step definitions in the project:
Expand Down
Loading
Loading