Skip to content

Commit

Permalink
localを別スキーマから参照しようとするとエラーになることを検証
Browse files Browse the repository at this point in the history
  • Loading branch information
KurisuJuha committed Jan 8, 2025
1 parent fd616d7 commit b70ad2a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
41 changes: 41 additions & 0 deletions mooresmaster.Tests/DefineInterfaceTests/DefineInterfaceTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using Xunit;

Expand Down Expand Up @@ -32,4 +33,44 @@ public void GlobalDefineInterfaceTest()
Assert.True(firstGlobalInterface.Properties.ContainsKey("test2"));
Assert.True(firstGlobalInterface.Properties.ContainsKey("test3"));
}

[Fact]
public void GlobalDefineInterfaceFailedTest()
{
const string failedTestText = """
id: defineInterfaceFailedTestSchema
type: object
implementationInterface:
- ILocalInterface
properties:
- key: test0
type: integer
- key: test1
type: integer
""";

const string passedTestText = """
id: defineInterfaceFailedTestSchema
type: object
implementationInterface:
- IGlobalInterface
properties:
- key: test2
type: integer
- key: test3
type: integer
""";

var defineInterfaceTestSchemaText = Test.GetSchema("DefineInterfaceTests/DefineInterfaceTestSchema.yml");

// ScopeがLocalのInterfaceを別ファイルから参照している場合エラーになる
Assert.ThrowsAny<Exception>(() => { _ = Test.Generate(defineInterfaceTestSchemaText, failedTestText); });

// globalであれば問題ない
Test.Generate(defineInterfaceTestSchemaText, passedTestText);
}
}
18 changes: 13 additions & 5 deletions mooresmaster.Tests/Test.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using mooresmaster.Generator.Definitions;
using mooresmaster.Generator.Json;
Expand Down Expand Up @@ -72,13 +73,20 @@ public void JsonParserTest()
// Assert.Equivalent(node, answer, true);
}

public static (SchemaTable schemaTable, NameTable nameTable, Semantics semantics, Definition definition) Generate(string yaml)
public static (SchemaTable schemaTable, NameTable nameTable, Semantics semantics, Definition definition) Generate(params string[] yamlTexts)
{
var jsonSchema = Yaml.ToJson(yaml);
var schemaTable = new SchemaTable();
var json = JsonParser.Parse(JsonTokenizer.GetTokens(jsonSchema));
var schema = JsonSchemaParser.ParseSchema(json as JsonObject, schemaTable);
var semantics = SemanticsGenerator.Generate([schema], schemaTable);
var schemas = new List<Schema>();

foreach (var yaml in yamlTexts)
{
var jsonSchema = Yaml.ToJson(yaml);
var json = JsonParser.Parse(JsonTokenizer.GetTokens(jsonSchema));
var schema = JsonSchemaParser.ParseSchema(json as JsonObject, schemaTable);
schemas.Add(schema);
}

var semantics = SemanticsGenerator.Generate([..schemas], schemaTable);
var nameTable = NameResolver.Resolve(semantics, schemaTable);
var definition = DefinitionGenerator.Generate(semantics, nameTable, schemaTable);

Expand Down

0 comments on commit b70ad2a

Please sign in to comment.