-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Breaking down FilePattern (#2681)
* Simplifying DiffIgnoreChangesInput * Update FilePattern.cs * Up * up * Rename the class * up --------- Co-authored-by: Rouke Broersma <[email protected]>
- Loading branch information
1 parent
0374632
commit b4f22e5
Showing
8 changed files
with
103 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
36 changes: 36 additions & 0 deletions
36
src/Stryker.Core/Stryker.Core.UnitTest/ExclusionPatternTests.cs
This file contains 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,36 @@ | ||
using System; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Stryker.Core.UnitTest | ||
{ | ||
public class ExclusionPatternTests : TestBase | ||
{ | ||
[Fact] | ||
public void ExclusionPattern_Null() | ||
{ | ||
_ = Assert.Throws<ArgumentNullException>(() => new ExclusionPattern(null)); | ||
} | ||
|
||
[Fact] | ||
public void ExclusionPattern_Globs() | ||
{ | ||
var s1 = new ExclusionPattern(@"Person.cs"); | ||
var s2 = new ExclusionPattern(@"!Person.cs"); | ||
|
||
s1.IsExcluded.ShouldBeFalse(); | ||
s2.IsExcluded.ShouldBeTrue(); | ||
s1.Glob.ToString().ShouldBe(s2.Glob.ToString()); | ||
} | ||
|
||
[Fact] | ||
public void ExclusionPattern_MutantSpans() | ||
{ | ||
var s1 = new ExclusionPattern(@"src/Person.cs{10..100}"); | ||
var s2 = new ExclusionPattern(@"src/Person.cs"); | ||
|
||
s1.MutantSpans.ShouldBe(new [] { (10, 100)}); | ||
s2.MutantSpans.ShouldBeEmpty(); | ||
} | ||
} | ||
} |
This file contains 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 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 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,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using DotNet.Globbing; | ||
|
||
namespace Stryker.Core | ||
{ | ||
public readonly struct ExclusionPattern | ||
{ | ||
private static readonly Regex _mutantSpanGroupRegex = new("(\\{(\\d+)\\.\\.(\\d+)\\})+$"); | ||
private static readonly Regex _mutantSpanRegex = new Regex("\\{(\\d+)\\.\\.(\\d+)\\}"); | ||
|
||
public ExclusionPattern(string s) | ||
{ | ||
if (s is null) | ||
{ | ||
throw new ArgumentNullException(nameof(s)); | ||
} | ||
|
||
IsExcluded = s.StartsWith('!'); | ||
|
||
var pattern = IsExcluded ? s[1..] : s; | ||
var mutantSpansRegex = _mutantSpanGroupRegex.Match(pattern); | ||
if (mutantSpansRegex.Success) | ||
{ | ||
var filePathPart = pattern[..^mutantSpansRegex.Length]; | ||
var normalized = FilePathUtils.NormalizePathSeparators(filePathPart); | ||
Glob = Glob.Parse(normalized); | ||
|
||
MutantSpans = _mutantSpanRegex | ||
.Matches(mutantSpansRegex.Value) | ||
.Select(x => (int.Parse(x.Groups[1].Value), int.Parse(x.Groups[2].Value))); | ||
} | ||
else | ||
{ | ||
var normalized = FilePathUtils.NormalizePathSeparators(pattern); | ||
Glob = Glob.Parse(normalized); | ||
MutantSpans = Enumerable.Empty<(int, int)>(); | ||
} | ||
} | ||
|
||
public bool IsExcluded { get; } | ||
|
||
public Glob Glob { get; } | ||
|
||
public IEnumerable<(int Start, int End)> MutantSpans { get; } | ||
} | ||
} |
This file contains 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 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 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