Skip to content

Commit 0f87a76

Browse files
committed
サンプルコードを外に出した
1 parent 3951229 commit 0f87a76

4 files changed

Lines changed: 44 additions & 36 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#if ENABLE_COMMAND_FORGE_GENERATOR
2+
namespace CommandForgeGenerator.Command
3+
{
4+
public partial class TextCommand : ICommandForgeCommand
5+
{
6+
public const string Type = "text";
7+
public readonly CommandId CommandId;
8+
9+
public readonly string Character;
10+
public readonly string Body;
11+
12+
13+
public static TextCommand Create(int commandId, global::Newtonsoft.Json.Linq.JToken json)
14+
{
15+
16+
var Character = (string)json["character"];
17+
var Body = (string)json["body"];
18+
19+
20+
return new TextCommand(commandId, Character, Body);
21+
}
22+
23+
public TextCommand(int commandId, string Character, string Body)
24+
{
25+
CommandId = (CommandId)commandId;
26+
27+
this.Character = Character;
28+
this.Body = Body;
29+
30+
}
31+
}
32+
}
33+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace CommandForgeGenerator.Command;
2+
3+
// 他の生成結果サンプルコマンドをコンパイルエラーにしないためのコード
4+
5+
public interface ICommandForgeCommand { }
6+
public enum CommandId{}
Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,9 @@
1+
using System.IO;
2+
13
namespace CommandForgeGenerator.Tests;
24

35
public class GenerateTestCode
46
{
5-
public const string TextCommand = """
6-
#if ENABLE_COMMAND_FORGE_GENERATOR
7-
namespace CommandForgeGenerator.Command
8-
{
9-
public partial class TextCommand : ICommandForgeCommand
10-
{
11-
public const string Type = "text";
12-
public readonly CommandId CommandId;
13-
14-
public readonly string Character;
15-
public readonly string Body;
16-
17-
18-
public static TextCommand Create(int commandId, global::Newtonsoft.Json.Linq.JToken json)
19-
{
20-
21-
var Character = (string)json["character"];
22-
var Body = (string)json["body"];
23-
24-
25-
return new TextCommand(commandId, Character, Body);
26-
}
27-
28-
public TextCommand(int commandId, string Character, string Body)
29-
{
30-
CommandId = (CommandId)commandId;
31-
32-
this.Character = Character;
33-
this.Body = Body;
34-
35-
}
36-
}
37-
}
38-
#endif
39-
""";
7+
// プロジェクトファイルに存在する GenerateSampleTextCommand.cs を取得する
8+
public static string TextCommandStr => File.ReadAllText("../../../CommandForgeGenerator.Tests/GenerateSampleTextCommand.cs");
409
}

CommandForgeGenerator.Tests/Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void GenerateTest()
6565
var codeFiles = CodeGenerator.Generate(commandsSchema);
6666

6767
Assert.Equal(16, codeFiles.Count);
68-
Assert.Equal(GenerateTestCode.TextCommand, codeFiles.FirstOrDefault(c => c.FileName == "TextCommand.g.cs").Code);
68+
Assert.Equal(GenerateTestCode.TextCommandStr, codeFiles.FirstOrDefault(c => c.FileName == "TextCommand.g.cs").Code);
6969

7070
#region Internal
7171

0 commit comments

Comments
 (0)