Skip to content

Commit

Permalink
fix: Support mutating anonymous methods (a.k.a delegate) properly (#2898
Browse files Browse the repository at this point in the history
)

fix: support anonymoud methods (a.k.a delegate) properly
  • Loading branch information
dupdob authored Apr 11, 2024
1 parent a93b620 commit ead50c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,27 @@ await SendRequest(url, HttpMethod.Get, (request) =>
ShouldMutateSourceInClassToExpected(source, expected);
}

[Fact]
public void ShouldMutateDeleage()
{
var source = @"private void LocalFun()
{
var test = delegate(string name)
{
Console.WriteLine($""Hello {name}"");
};
}";
string expected = @"private void LocalFun()
{if(StrykerNamespace.MutantControl.IsActive(0)){}else{
var test = delegate(string name)
{if(StrykerNamespace.MutantControl.IsActive(1)){}else{
if(StrykerNamespace.MutantControl.IsActive(2)){;}else{Console.WriteLine((StrykerNamespace.MutantControl.IsActive(3)?$"""":$""Hello {name}""));
}}};
}}";

ShouldMutateSourceInClassToExpected(source, expected);
}

[Fact]
public void MutationsShouldHaveLinespan()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal class AnonymousFunctionExpressionOrchestrator : BaseFunctionOrchestrato

protected override ParameterListSyntax ParameterList(AnonymousFunctionExpressionSyntax node) => node switch {ParenthesizedLambdaExpressionSyntax parenthesizedLambda => parenthesizedLambda.ParameterList,
SimpleLambdaExpressionSyntax simpleLambda => SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(simpleLambda.Parameter)),
AnonymousMethodExpressionSyntax anonymousMethod => anonymousMethod.ParameterList,
_ => throw new ArgumentOutOfRangeException(nameof(node), node, null)
};

Expand Down

0 comments on commit ead50c3

Please sign in to comment.