mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
- 定义了 Godot 源代码生成器的诊断规则表格 - 添加了上下文获取生成器的全面单元测试 - 实现了自动生成行为和注册导出集合的诊断功能 - 配置了全局 using 语句简化代码生成器实现 - 添加了完整的分析器发布跟踪文档记录新规则
98 lines
4.1 KiB
C#
98 lines
4.1 KiB
C#
using GFramework.Godot.SourceGenerators.Behavior;
|
|
using GFramework.Godot.SourceGenerators.Tests.Core;
|
|
|
|
namespace GFramework.Godot.SourceGenerators.Tests.Behavior;
|
|
|
|
[TestFixture]
|
|
public class AutoUiPageGeneratorTests
|
|
{
|
|
[Test]
|
|
public async Task Generates_Ui_Page_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 AutoUiPageAttribute : Attribute
|
|
{
|
|
public AutoUiPageAttribute(string key, string layerName) { }
|
|
}
|
|
}
|
|
|
|
namespace Godot
|
|
{
|
|
public class Node { }
|
|
public class CanvasItem : Node { }
|
|
public class Control : CanvasItem { }
|
|
}
|
|
|
|
namespace GFramework.Game.Abstractions.Enums
|
|
{
|
|
public enum UiLayer
|
|
{
|
|
Page,
|
|
Overlay,
|
|
Modal
|
|
}
|
|
}
|
|
|
|
namespace GFramework.Game.Abstractions.UI
|
|
{
|
|
public interface IUiPageBehavior { }
|
|
}
|
|
|
|
namespace GFramework.Godot.UI
|
|
{
|
|
using GFramework.Game.Abstractions.Enums;
|
|
using GFramework.Game.Abstractions.UI;
|
|
using Godot;
|
|
|
|
public static class UiPageBehaviorFactory
|
|
{
|
|
public static IUiPageBehavior Create<T>(T owner, string key, UiLayer layer)
|
|
where T : CanvasItem
|
|
{
|
|
return null!;
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace TestApp
|
|
{
|
|
[AutoUiPage("MainMenu", "Page")]
|
|
public partial class MainMenu : Control
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
const string expected = """
|
|
// <auto-generated />
|
|
#nullable enable
|
|
|
|
namespace TestApp;
|
|
|
|
partial class MainMenu
|
|
{
|
|
private global::GFramework.Game.Abstractions.UI.IUiPageBehavior? __autoUiPageBehavior_Generated;
|
|
|
|
public static string UiKeyStr => "MainMenu";
|
|
|
|
public global::GFramework.Game.Abstractions.UI.IUiPageBehavior GetPage()
|
|
{
|
|
return __autoUiPageBehavior_Generated ??= global::GFramework.Godot.UI.UiPageBehaviorFactory.Create(this, UiKeyStr, global::GFramework.Game.Abstractions.Enums.UiLayer.Page);
|
|
}
|
|
}
|
|
|
|
""";
|
|
|
|
await GeneratorTest<AutoUiPageGenerator>.RunAsync(
|
|
source,
|
|
("TestApp_MainMenu.AutoUiPage.g.cs", expected));
|
|
}
|
|
}
|