-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playing around with fixing generated code with generic paramters (#143)
- Loading branch information
Showing
7 changed files
with
141 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Moq.AutoMock.Generator.Example; | ||
|
||
public interface ILogger<T> | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Moq.AutoMocker.TestGenerator; | ||
|
||
public enum TargetTestingFramework | ||
{ | ||
Unknown, | ||
MSTest, | ||
Xunit, | ||
NUnit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Text; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
|
||
namespace Moq.AutoMocker.TestGenerator; | ||
|
||
internal static class TestNameBuilder | ||
{ | ||
public static IEnumerable<string> CreateTestName(GeneratorTargetClass testClass, NullConstructorParameterTest test) | ||
{ | ||
int testNameIndex = 0; | ||
for (string testName = $"{testClass.Sut!.Name}Constructor_WithNull{test.NullTypeName}_ThrowsArgumentNullException"; | ||
; | ||
testName = $"{testClass.Sut!.Name}Constructor_WithNull{test.NullTypeName}{++testNameIndex}_ThrowsArgumentNullException") | ||
{ | ||
if (!SyntaxFacts.IsValidIdentifier(testName)) | ||
{ | ||
StringBuilder sb = new(testName.Length); | ||
for (int i = 0; i < testName.Length; i++) | ||
{ | ||
if (sb.Length == 0) | ||
{ | ||
if (SyntaxFacts.IsIdentifierStartCharacter(testName[i])) | ||
{ | ||
sb.Append(testName[i]); | ||
} | ||
} | ||
else | ||
{ | ||
if (SyntaxFacts.IsIdentifierPartCharacter(testName[i])) | ||
{ | ||
sb.Append(testName[i]); | ||
} | ||
} | ||
} | ||
yield return sb.ToString(); | ||
} | ||
else | ||
{ | ||
yield return testName; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters