Skip to content

Commit

Permalink
feat: Add string mutators for LastIndexOf and IndexOf. (#3054)
Browse files Browse the repository at this point in the history
Added string mutators.
  • Loading branch information
Myoxocephalus authored Oct 18, 2024
1 parent 34fc801 commit 3f6e3ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand Down Expand Up @@ -63,6 +63,8 @@ private static string GetReplacement(string identifier) =>
"ToLowerInvariant" => "ToUpperInvariant",
"PadLeft" => "PadRight",
"PadRight" => "PadLeft",
"IndexOf" => "LastIndexOf",
"LastIndexOf" => "IndexOf",
_ => null
};

Expand Down

0 comments on commit 3f6e3ad

Please sign in to comment.