mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
fix(generator): 修复ContextAware生成器的代码生成问题
- 修复生成代码末尾多余的换行符问题 - 添加GFramework.Core.rule命名空间引用 - 在测试中添加框架存根代码以提供必要的接口依赖 - 更新解决方案设置以包含新的分析器测试文件
This commit is contained in:
parent
eaa706a7e4
commit
eebd7de409
@ -30,17 +30,31 @@ public class ContextAwareGeneratorTests
|
||||
}
|
||||
}
|
||||
|
||||
namespace TestApp;
|
||||
|
||||
using GFramework.SourceGenerators.Attributes.rule;
|
||||
|
||||
[ContextAware]
|
||||
public partial class MyRule
|
||||
namespace TestApp
|
||||
{
|
||||
using GFramework.SourceGenerators.Attributes.rule;
|
||||
|
||||
[ContextAware]
|
||||
public partial class MyRule
|
||||
{
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
const string frameworkStub = """
|
||||
namespace GFramework.Core.rule
|
||||
{
|
||||
public interface IContextAware
|
||||
{
|
||||
void SetContext(GFramework.Core.architecture.IArchitectureContext context);
|
||||
}
|
||||
}
|
||||
|
||||
namespace GFramework.Core.architecture
|
||||
{
|
||||
public interface IArchitectureContext {}
|
||||
}
|
||||
""";
|
||||
// 定义期望的生成结果代码
|
||||
const string expected = """
|
||||
// <auto-generated/>
|
||||
@ -61,7 +75,7 @@ public class ContextAwareGeneratorTests
|
||||
|
||||
// 执行源代码生成器测试
|
||||
await GeneratorTest<ContextAwareGenerator>.RunAsync(
|
||||
source,
|
||||
source + "\n" + frameworkStub,
|
||||
("MyRule.ContextAware.g.cs", expected)
|
||||
);
|
||||
}
|
||||
|
||||
@ -105,9 +105,8 @@ public sealed class ContextAwareGenerator : IIncrementalGenerator
|
||||
sb.AppendLine(" Context = context;");
|
||||
sb.AppendLine(" }");
|
||||
|
||||
|
||||
sb.AppendLine("}");
|
||||
|
||||
return sb.ToString();
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,9 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAnalyzerTest_00601_002Ecs_002Fl_003AD_0021_003FTool_003FDevelopment_0020Tools_003FJetBrains_003F_002EJetBrains_003F_002ERider_003Fconfig_003Fresharper_002Dhost_003FSourcesCache_003Fe7a998cc7aa4af29968182b46ff292b3634fc9b5961db3d3d2a5291dc5a7843_003FAnalyzerTest_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADiagnostic_002Ecs_002Fl_003AD_0021_003FTool_003FDevelopment_0020Tools_003FJetBrains_003F_002EJetBrains_003F_002ERider_003Fconfig_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8fed4175e0a54d839582ab555761a2de4d5128_003Ff3_003Fd48d28bd_003FDiagnostic_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AInputEventAction_002Ecs_002Fl_003AD_0021_003FTool_003FDevelopment_0020Tools_003FJetBrains_003F_002EJetBrains_003F_002ERider_003Fconfig_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F1c378f459c054fecaf4484a0fa6d44c055a800_003F18_003F33b52a1c_003FInputEventAction_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIVerifierExtensions_002Ecs_002Fl_003AD_0021_003FTool_003FDevelopment_0020Tools_003FJetBrains_003F_002EJetBrains_003F_002ERider_003Fconfig_003Fresharper_002Dhost_003FSourcesCache_003F3a7fb23d304bcd1dd4fcb38114e45d28a6a1446eb6b71c918bcb1d73a6cbf3_003FIVerifierExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASolutionState_002Ecs_002Fl_003AD_0021_003FTool_003FDevelopment_0020Tools_003FJetBrains_003F_002EJetBrains_003F_002ERider_003Fconfig_003Fresharper_002Dhost_003FSourcesCache_003F59c43162311a41dc4e9a06273ab3fb541e6a64318777591f77584020ff865_003FSolutionState_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c33c8ad6_002Dd992_002D4817_002D855f_002D764f7c7897fa/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Generates_ContextAware_Code" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||
<TestAncestor>
|
||||
<TestId>NUnit3x::BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E::net8.0::GFramework.SourceGenerators.Tests.rule.ContextAwareGeneratorTests</TestId>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user