mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 将所有小写的命名空间导入更正为首字母大写格式 - 统一 GFramework 框架的命名空间引用规范 - 修复 core、ecs、godot 等模块的命名空间导入错误 - 标准化文档示例代码中的 using 语句格式 - 确保所有文档中的命名空间引用保持一致性 - 更新 global using 语句以匹配正确的命名空间格式
215 lines
8.2 KiB
C#
215 lines
8.2 KiB
C#
using System.IO;
|
|
using GFramework.SourceGenerators.Bases;
|
|
using GFramework.SourceGenerators.Tests.Core;
|
|
using NUnit.Framework;
|
|
|
|
namespace GFramework.SourceGenerators.Tests.Bases;
|
|
|
|
/// <summary>
|
|
/// Priority 生成器快照测试类
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class PriorityGeneratorSnapshotTests
|
|
{
|
|
/// <summary>
|
|
/// 测试基本的 Priority 特性生成
|
|
/// </summary>
|
|
[Test]
|
|
public async Task Snapshot_BasicPriority()
|
|
{
|
|
const string source = """
|
|
using System;
|
|
|
|
namespace GFramework.SourceGenerators.Abstractions.Bases
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
|
public sealed class PriorityAttribute : Attribute
|
|
{
|
|
public int Value { get; }
|
|
public PriorityAttribute(int value) { Value = value; }
|
|
}
|
|
}
|
|
|
|
namespace GFramework.Core.Abstractions.Bases
|
|
{
|
|
public interface IPrioritized
|
|
{
|
|
int Priority { get; }
|
|
}
|
|
}
|
|
|
|
namespace TestApp
|
|
{
|
|
using GFramework.SourceGenerators.Abstractions.Bases;
|
|
|
|
[Priority(10)]
|
|
public partial class MySystem
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<PriorityGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"bases",
|
|
"snapshots",
|
|
"PriorityGenerator",
|
|
"BasicPriority"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试负数优先级
|
|
/// </summary>
|
|
[Test]
|
|
public async Task Snapshot_NegativePriority()
|
|
{
|
|
const string source = """
|
|
using System;
|
|
|
|
namespace GFramework.SourceGenerators.Abstractions.Bases
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
|
public sealed class PriorityAttribute : Attribute
|
|
{
|
|
public int Value { get; }
|
|
public PriorityAttribute(int value) { Value = value; }
|
|
}
|
|
}
|
|
|
|
namespace GFramework.Core.Abstractions.Bases
|
|
{
|
|
public interface IPrioritized
|
|
{
|
|
int Priority { get; }
|
|
}
|
|
}
|
|
|
|
namespace TestApp
|
|
{
|
|
using GFramework.SourceGenerators.Abstractions.Bases;
|
|
|
|
[Priority(-100)]
|
|
public partial class CriticalSystem
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<PriorityGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"bases",
|
|
"snapshots",
|
|
"PriorityGenerator",
|
|
"NegativePriority"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试使用 PriorityGroup 枚举
|
|
/// </summary>
|
|
[Test]
|
|
public async Task Snapshot_PriorityGroup()
|
|
{
|
|
const string source = """
|
|
using System;
|
|
|
|
namespace GFramework.SourceGenerators.Abstractions.Bases
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
|
public sealed class PriorityAttribute : Attribute
|
|
{
|
|
public int Value { get; }
|
|
public PriorityAttribute(int value) { Value = value; }
|
|
}
|
|
}
|
|
|
|
namespace GFramework.Core.Abstractions.Bases
|
|
{
|
|
public interface IPrioritized
|
|
{
|
|
int Priority { get; }
|
|
}
|
|
|
|
public static class PriorityGroup
|
|
{
|
|
public const int Critical = -100;
|
|
public const int High = -50;
|
|
public const int Normal = 0;
|
|
public const int Low = 50;
|
|
public const int Deferred = 100;
|
|
}
|
|
}
|
|
|
|
namespace TestApp
|
|
{
|
|
using GFramework.SourceGenerators.Abstractions.Bases;
|
|
using GFramework.Core.Abstractions.Bases;
|
|
|
|
[Priority(PriorityGroup.High)]
|
|
public partial class HighPrioritySystem
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<PriorityGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"bases",
|
|
"snapshots",
|
|
"PriorityGenerator",
|
|
"PriorityGroup"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试泛型类支持
|
|
/// </summary>
|
|
[Test]
|
|
public async Task Snapshot_GenericClass()
|
|
{
|
|
const string source = """
|
|
using System;
|
|
|
|
namespace GFramework.SourceGenerators.Abstractions.Bases
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
|
public sealed class PriorityAttribute : Attribute
|
|
{
|
|
public int Value { get; }
|
|
public PriorityAttribute(int value) { Value = value; }
|
|
}
|
|
}
|
|
|
|
namespace GFramework.Core.Abstractions.Bases
|
|
{
|
|
public interface IPrioritized
|
|
{
|
|
int Priority { get; }
|
|
}
|
|
}
|
|
|
|
namespace TestApp
|
|
{
|
|
using GFramework.SourceGenerators.Abstractions.Bases;
|
|
|
|
[Priority(20)]
|
|
public partial class GenericSystem<T>
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<PriorityGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"bases",
|
|
"snapshots",
|
|
"PriorityGenerator",
|
|
"GenericClass"));
|
|
}
|
|
} |