Skip to content

Commit

Permalink
fix: restore parsing of patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
dupdob committed Nov 22, 2024
1 parent 6826228 commit 1736132
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mono.Cecil;
using Shouldly;
using Stryker.Abstractions;
using Stryker.Abstractions.Mutators;
Expand Down Expand Up @@ -81,6 +82,27 @@ void MethodA() {if(StrykerNamespace.MutantControl.IsActive(0)){}else{
ShouldMutateSourceToExpected(source, expected);
}



[TestMethod]
public void ShouldMutatePatterns()
{

var source = @"public void Test()
{
Console.WriteLine(new[] { 1, 2, 3, 4 } is [>= 0, .., 2 or 4]);
}
";
var expected = @"public void Test()
{ if(StrykerNamespace.MutantControl.IsActive(0)) {}else{
if(StrykerNamespace.MutantControl.IsActive(1)){;}else{Console.WriteLine((StrykerNamespace.MutantControl.IsActive(2)?new[] { 1, 2, 3, 4 } is not [>= 0, .., 2 or 4]:(StrykerNamespace.MutantControl.IsActive(5)?new[] { 1, 2, 3, 4 } is [>= 0, .., 2 and 4]:(StrykerNamespace.MutantControl.IsActive(4)?new[] { 1, 2, 3, 4 } is [< 0, .., 2 or 4]:(StrykerNamespace.MutantControl.IsActive(3)?new[] { 1, 2, 3, 4 } is [> 0, .., 2 or 4]:new[] { 1, 2, 3, 4 } is [>= 0, .., 2 or 4])))));}
}
}
";
ShouldMutateSourceInClassToExpected(source, expected);

}

[TestMethod]
public void ShouldMutateBlockStatements()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Extensions.Logging;
using Spectre.Console;
using Stryker.Abstractions;
using Stryker.Abstractions.Logging;
using Stryker.Abstractions.Mutants;
Expand Down Expand Up @@ -47,8 +46,6 @@ private static List<INodeOrchestrator> BuildOrchestratorList() =>
new DoNotMutateOrchestrator<ParameterListSyntax>(),
// enum values
new DoNotMutateOrchestrator<EnumMemberDeclarationSyntax>(),
// pattern marching
new DoNotMutateOrchestrator<RecursivePatternSyntax>(),
new DoNotMutateOrchestrator<UsingDirectiveSyntax>(),
// constants and constant fields
new DoNotMutateOrchestrator<FieldDeclarationSyntax>(
Expand All @@ -65,6 +62,9 @@ private static List<INodeOrchestrator> BuildOrchestratorList() =>
new MemberAccessExpressionOrchestrator<SimpleNameSyntax>(),
new MemberAccessExpressionOrchestrator<PostfixUnaryExpressionSyntax>(t =>
t.IsKind(SyntaxKind.SuppressNullableWarningExpression)),
// ensure patterhsyntax nodes are mutated (as they are neither expression nor statements, they are not mutated by default)
new NodeSpecificOrchestrator<PatternSyntax, PatternSyntax>(),
new NodeSpecificOrchestrator<SubpatternSyntax, SubpatternSyntax>(),
new ConditionalExpressionOrchestrator(),
new ConstantPatternSyntaxOrchestrator(),
// ensure static constructs are marked properly
Expand Down

0 comments on commit 1736132

Please sign in to comment.