mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
- 定义了 Godot 源代码生成器的诊断规则表格 - 添加了上下文获取生成器的全面单元测试 - 实现了自动生成行为和注册导出集合的诊断功能 - 配置了全局 using 语句简化代码生成器实现 - 添加了完整的分析器发布跟踪文档记录新规则
86 lines
3.5 KiB
C#
86 lines
3.5 KiB
C#
using GFramework.Godot.SourceGenerators.Behavior;
|
|
using GFramework.Godot.SourceGenerators.Tests.Core;
|
|
|
|
namespace GFramework.Godot.SourceGenerators.Tests.Behavior;
|
|
|
|
[TestFixture]
|
|
public class AutoSceneGeneratorTests
|
|
{
|
|
[Test]
|
|
public async Task Generates_Scene_Behavior_Boilerplate()
|
|
{
|
|
const string source = """
|
|
using System;
|
|
using GFramework.Godot.SourceGenerators.Abstractions;
|
|
using Godot;
|
|
|
|
namespace GFramework.Godot.SourceGenerators.Abstractions
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
|
public sealed class AutoSceneAttribute : Attribute
|
|
{
|
|
public AutoSceneAttribute(string key) { }
|
|
}
|
|
}
|
|
|
|
namespace Godot
|
|
{
|
|
public class Node { }
|
|
public class Node2D : Node { }
|
|
}
|
|
|
|
namespace GFramework.Game.Abstractions.Scene
|
|
{
|
|
public interface ISceneBehavior { }
|
|
}
|
|
|
|
namespace GFramework.Godot.Scene
|
|
{
|
|
using GFramework.Game.Abstractions.Scene;
|
|
using Godot;
|
|
|
|
public static class SceneBehaviorFactory
|
|
{
|
|
public static ISceneBehavior Create<T>(T owner, string key)
|
|
where T : Node
|
|
{
|
|
return null!;
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace TestApp
|
|
{
|
|
[AutoScene("Gameplay")]
|
|
public partial class GameplayRoot : Node2D
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
const string expected = """
|
|
// <auto-generated />
|
|
#nullable enable
|
|
|
|
namespace TestApp;
|
|
|
|
partial class GameplayRoot
|
|
{
|
|
private global::GFramework.Game.Abstractions.Scene.ISceneBehavior? __autoSceneBehavior_Generated;
|
|
|
|
public static string SceneKeyStr => "Gameplay";
|
|
|
|
public global::GFramework.Game.Abstractions.Scene.ISceneBehavior GetScene()
|
|
{
|
|
return __autoSceneBehavior_Generated ??= global::GFramework.Godot.Scene.SceneBehaviorFactory.Create(this, SceneKeyStr);
|
|
}
|
|
}
|
|
|
|
""";
|
|
|
|
await GeneratorTest<AutoSceneGenerator>.RunAsync(
|
|
source,
|
|
("TestApp_GameplayRoot.AutoScene.g.cs", expected));
|
|
}
|
|
}
|