From 3f6e3ad8dc13ddb0aa244178321788ddaee209dc Mon Sep 17 00:00:00 2001 From: Myoxocephalus Date: Fri, 18 Oct 2024 12:21:16 +0200 Subject: [PATCH] feat: Add string mutators for LastIndexOf and IndexOf. (#3054) Added string mutators. --- docs/mutations.md | 2 ++ .../Mutators/StringMethodMutatorTests.cs | 2 ++ src/Stryker.Core/Stryker.Core/Mutators/StringMethodMutator.cs | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/mutations.md b/docs/mutations.md index 16ab045dd..4fe129a1b 100644 --- a/docs/mutations.md +++ b/docs/mutations.md @@ -173,6 +173,8 @@ Do you have a suggestion for a (new) mutator? Feel free to create an [issue](htt | `ElementAt()` | `'\0'` | | `ElementAtOrDefault()` | `'\0'` | | `EndsWith()` | `StartsWith()` | +| `IndexOf()` | `LastIndexOf()` | +| `LastIndexOf()` | `IndexOf()` | | `PadLeft()` | `PadRight()` | | `PadRight()` | `PadLeft()` | | `StartsWith()` | `EndsWith()` | diff --git a/src/Stryker.Core/Stryker.Core.UnitTest/Mutators/StringMethodMutatorTests.cs b/src/Stryker.Core/Stryker.Core.UnitTest/Mutators/StringMethodMutatorTests.cs index 477182126..9739cc82a 100644 --- a/src/Stryker.Core/Stryker.Core.UnitTest/Mutators/StringMethodMutatorTests.cs +++ b/src/Stryker.Core/Stryker.Core.UnitTest/Mutators/StringMethodMutatorTests.cs @@ -59,6 +59,8 @@ void TestMethod() { "String Method Mutation (Replace ToLowerInvariant() with ToUpperInvariant())")] [DataRow("testString.PadLeft(10)", "PadRight", "String Method Mutation (Replace PadLeft() with PadRight())")] [DataRow("testString.PadRight(10)", "PadLeft", "String Method Mutation (Replace PadRight() with PadLeft())")] + [DataRow("testString.LastIndexOf(c)", "IndexOf", "String Method Mutation (Replace LastIndexOf() with IndexOf())")] + [DataRow("testString.IndexOf(c)", "LastIndexOf", "String Method Mutation (Replace IndexOf() with LastIndexOf())")] public void ShouldMutateStringMethods(string expression, string mutatedMethod, string expectedDisplayName) { var (semanticModel, expressionSyntax) = CreateSemanticModelFromExpression(expression); diff --git a/src/Stryker.Core/Stryker.Core/Mutators/StringMethodMutator.cs b/src/Stryker.Core/Stryker.Core/Mutators/StringMethodMutator.cs index 815866082..99367a780 100644 --- a/src/Stryker.Core/Stryker.Core/Mutators/StringMethodMutator.cs +++ b/src/Stryker.Core/Stryker.Core/Mutators/StringMethodMutator.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -63,6 +63,8 @@ private static string GetReplacement(string identifier) => "ToLowerInvariant" => "ToUpperInvariant", "PadLeft" => "PadRight", "PadRight" => "PadLeft", + "IndexOf" => "LastIndexOf", + "LastIndexOf" => "IndexOf", _ => null };