Skip to content

Commit

Permalink
Added string mutators.
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoxocephalus committed Oct 1, 2024
1 parent bd20fc6 commit 7eaa0a3
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 @@ -58,6 +58,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 @@ -62,6 +62,8 @@ private static string GetReplacement(string identifier) =>
"ToLowerInvariant" => "ToUpperInvariant",
"PadLeft" => "PadRight",
"PadRight" => "PadLeft",
"IndexOf" => "LastIndexOf",
"LastIndexOf" => "IndexOf",
_ => null
};

Expand Down

0 comments on commit 7eaa0a3

Please sign in to comment.