-
Notifications
You must be signed in to change notification settings - Fork 0
Bugfix/simple method with parameter #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using System.Collections.Immutable; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Text; | ||
|
|
||
| namespace EasySourceGenerators.GeneratorTests; | ||
|
|
||
| public class SimpleMethodWithParameterTests | ||
| { | ||
| [Test] | ||
| public void SimpleMethodWithParameterTests_Test() | ||
| { | ||
| string source = """ | ||
| using EasySourceGenerators.Abstractions; | ||
|
|
||
| namespace TestNamespace; | ||
|
|
||
| public partial class SimpleMethodWithParameterClass | ||
| { | ||
| public partial int SimpleMethodWithParameter(int someIntParameter); | ||
|
|
||
| [GeneratesMethod(sameClassMethodName: nameof(SimpleMethodWithParameter))] | ||
| private static int SimpleMethodWithParameter_Generator(int someIntParameter) | ||
| { | ||
| return 5; | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| ImmutableArray<Diagnostic> diagnostics = GeneratorTestHelper.GetGeneratorOnlyDiagnostics(source); | ||
|
|
||
| Diagnostic? msgh007 = diagnostics.FirstOrDefault(diagnostic => diagnostic.Id == "MSGH007"); | ||
| Assert.That(msgh007, Is.Not.Null, "Expected MSGH007 for simple generator method with runtime parameter."); | ||
| Assert.That(msgh007!.Location.IsInSource, Is.True, "MSGH007 should point to generator source."); | ||
|
|
||
| TextSpan span = msgh007.Location.SourceSpan; | ||
| string highlightedCode = source.Substring(span.Start, span.Length); | ||
| Assert.That(highlightedCode, Does.Contain("SimpleMethodWithParameter_Generator(int someIntParameter)")); | ||
| Assert.That(highlightedCode, Does.Not.Contain("return 5;"), | ||
| "MSGH007 should highlight the generator method signature, not the method body."); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,4 +7,5 @@ MSGH002 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator | |||||
| MSGH003 | GeneratesMethodGenerator | Disabled | GeneratesMethodGenerator | ||||||
| MSGH004 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator | ||||||
| MSGH005 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator | ||||||
| MSGH006 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator | ||||||
| MSGH006 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator | ||||||
| MSGH007 | GeneratesMethodGenerator | Error | GeneratesMethodGeneratorDiagnostics | ||||||
|
||||||
| MSGH007 | GeneratesMethodGenerator | Error | GeneratesMethodGeneratorDiagnostics | |
| MSGH007 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -53,4 +53,12 @@ internal static class GeneratesMethodGeneratorDiagnostics | |||||
| category: Category, | ||||||
| defaultSeverity: DiagnosticSeverity.Error, | ||||||
| isEnabledByDefault: true); | ||||||
|
|
||||||
| internal static readonly DiagnosticDescriptor CannotUseRuntimeParameterForCompileTimeGeneratorError = new( | ||||||
| id: "MSGH007", | ||||||
| title: "Cannot use runtime parameter for compile-time generator", | ||||||
| messageFormat: "Method generators cannot have any parameters, as they will be run at compile time to generate the method output value. Use MethodTemplate if you want to emit method body instead of single value.", | ||||||
|
||||||
| messageFormat: "Method generators cannot have any parameters, as they will be run at compile time to generate the method output value. Use MethodTemplate if you want to emit method body instead of single value.", | |
| messageFormat: "Method generators cannot have any parameters, as they will be run at compile time to generate the method output value. Use the fluent method-generation API (e.g., Generate.Method() / MethodBuilder) if you want to emit a method body instead of a single value.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test naming is inconsistent with the rest of the test suite (which uses descriptive names like
GeneratesMethod_WithNonStaticMethod_EmitsMSGH002). Consider renamingSimpleMethodWithParameterTests_Testto describe the behavior under test (e.g., that a parameterized simple generator emits MSGH007 and highlights only the signature).