mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-04-02 19:55:57 +08:00
- 实现AI-First配表方案,支持怪物、物品、技能等静态内容管理 - 集成YAML配置源文件与JSON Schema结构描述功能 - 提供一对象一文件的目录组织方式和运行时只读查询能力 - 实现Source Generator生成配置类型和表包装类 - 集成VS Code插件提供配置浏览、raw编辑和递归校验功能 - 开发YamlConfigSchemaValidator实现JSON Schema子集校验 - 支持嵌套对象、对象数组、标量数组与深层enum引用约束校验 - 实现跨表引用检测和热重载时依赖表联动校验机制
94 lines
3.3 KiB
C#
94 lines
3.3 KiB
C#
namespace GFramework.SourceGenerators.Tests.Config;
|
|
|
|
/// <summary>
|
|
/// 验证 schema 配置生成器的错误诊断行为。
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class SchemaConfigGeneratorTests
|
|
{
|
|
/// <summary>
|
|
/// 验证缺失必填 id 字段时会产生命名明确的诊断。
|
|
/// </summary>
|
|
[Test]
|
|
public void Run_Should_Report_Diagnostic_When_Id_Property_Is_Missing()
|
|
{
|
|
const string source = """
|
|
namespace TestApp
|
|
{
|
|
public sealed class Dummy
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
const string schema = """
|
|
{
|
|
"type": "object",
|
|
"required": ["name"],
|
|
"properties": {
|
|
"name": { "type": "string" }
|
|
}
|
|
}
|
|
""";
|
|
|
|
var result = SchemaGeneratorTestDriver.Run(
|
|
source,
|
|
("monster.schema.json", schema));
|
|
|
|
var diagnostics = result.Results.Single().Diagnostics;
|
|
var diagnostic = diagnostics.Single();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(diagnostic.Id, Is.EqualTo("GF_ConfigSchema_003"));
|
|
Assert.That(diagnostic.Severity, Is.EqualTo(DiagnosticSeverity.Error));
|
|
Assert.That(diagnostic.GetMessage(), Does.Contain("monster.schema.json"));
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 验证深层不支持的数组嵌套会带着完整字段路径产生命名明确的诊断。
|
|
/// </summary>
|
|
[Test]
|
|
public void Run_Should_Report_Diagnostic_When_Nested_Array_Type_Is_Not_Supported()
|
|
{
|
|
const string source = """
|
|
namespace TestApp
|
|
{
|
|
public sealed class Dummy
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
const string schema = """
|
|
{
|
|
"type": "object",
|
|
"required": ["id"],
|
|
"properties": {
|
|
"id": { "type": "integer" },
|
|
"waves": {
|
|
"type": "array",
|
|
"items": {
|
|
"type": "array",
|
|
"items": { "type": "integer" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
""";
|
|
|
|
var result = SchemaGeneratorTestDriver.Run(
|
|
source,
|
|
("monster.schema.json", schema));
|
|
|
|
var diagnostic = result.Results.Single().Diagnostics.Single();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(diagnostic.Id, Is.EqualTo("GF_ConfigSchema_004"));
|
|
Assert.That(diagnostic.GetMessage(), Does.Contain("waves"));
|
|
Assert.That(diagnostic.GetMessage(), Does.Contain("array<array>"));
|
|
});
|
|
}
|
|
} |