-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleMethodWithParameter.cs
More file actions
41 lines (33 loc) · 1.77 KB
/
SimpleMethodWithParameter.cs
File metadata and controls
41 lines (33 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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.");
}
}