-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new matchBaseParameterOnName parameter on AutoConstructorAttribute
- Loading branch information
1 parent
d30c221
commit 2b8d9b5
Showing
7 changed files
with
239 additions
and
16 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
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
2 changes: 1 addition & 1 deletion
2
...r.Tests/AddParameterlessGeneratorTests.cs → ...nerator/AddParameterlessGeneratorTests.cs
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
2 changes: 1 addition & 1 deletion
2
...or.Tests/ConflictingParameterNameTests.cs → ...enerator/ConflictingParameterNameTests.cs
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
118 changes: 118 additions & 0 deletions
118
tests/AutoConstructor.Tests/Generator/MatchBaseParameterOnNameTests.cs
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,118 @@ | ||
using Xunit; | ||
using VerifySourceGenerator = AutoConstructor.Tests.Verifiers.CSharpSourceGeneratorVerifier<AutoConstructor.Generator.AutoConstructorGenerator>; | ||
|
||
namespace AutoConstructor.Tests.Generator; | ||
|
||
public class MatchBaseParameterOnNameTests | ||
{ | ||
[Fact] | ||
public async Task Run_WhenMatchBaseParameterOnNameIsTrue_ShouldGenerateClass() | ||
{ | ||
const string code = @" | ||
namespace Test | ||
{ | ||
public class ParentClass | ||
{ | ||
private readonly long service; | ||
public ParentClass(long service) | ||
{ | ||
this.service = service; | ||
} | ||
} | ||
[AutoConstructor(matchBaseParameterOnName: true)] | ||
public partial class Test : ParentClass | ||
{ | ||
private readonly int service; | ||
} | ||
}"; | ||
|
||
const string generated = @"namespace Test | ||
{ | ||
partial class Test | ||
{ | ||
public Test(int service) : base(service) | ||
{ | ||
this.service = service; | ||
} | ||
} | ||
} | ||
"; | ||
await VerifySourceGenerator.RunAsync(code, generated); | ||
} | ||
|
||
[Fact] | ||
public async Task Run_WhenMatchBaseParameterOnNameIsFalse_ShouldGenerateClass() | ||
{ | ||
const string code = @" | ||
namespace Test | ||
{ | ||
public class ParentClass | ||
{ | ||
private readonly long service; | ||
public ParentClass(long service) | ||
{ | ||
this.service = service; | ||
} | ||
} | ||
[AutoConstructor(matchBaseParameterOnName: false)] | ||
public partial class Test : ParentClass | ||
{ | ||
private readonly int service; | ||
} | ||
}"; | ||
|
||
const string generated = @"namespace Test | ||
{ | ||
partial class Test | ||
{ | ||
public Test(int service, long b0__service) : base(b0__service) | ||
{ | ||
this.service = service; | ||
} | ||
} | ||
} | ||
"; | ||
await VerifySourceGenerator.RunAsync(code, generated); | ||
} | ||
|
||
[Fact] | ||
public async Task Run_WhenMatchBaseParameterOnNameIsFalseWithSameType_ShouldGenerateClass() | ||
{ | ||
const string code = @" | ||
namespace Test | ||
{ | ||
public class ParentClass | ||
{ | ||
private readonly int service; | ||
public ParentClass(int service) | ||
{ | ||
this.service = service; | ||
} | ||
} | ||
[AutoConstructor(matchBaseParameterOnName: false)] | ||
public partial class Test : ParentClass | ||
{ | ||
private readonly int service; | ||
} | ||
}"; | ||
|
||
const string generated = @"namespace Test | ||
{ | ||
partial class Test | ||
{ | ||
public Test(int service) : base(service) | ||
{ | ||
this.service = service; | ||
} | ||
} | ||
} | ||
"; | ||
await VerifySourceGenerator.RunAsync(code, generated); | ||
} | ||
} |