From 898efe9c8846a5ba4ee387506560b552ba707c62 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Thu, 18 Jan 2024 16:26:29 +0000 Subject: [PATCH] Add regression testing for snake case --- Bonsai.Sgen.Tests/CasingGenerationTests.cs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Bonsai.Sgen.Tests/CasingGenerationTests.cs diff --git a/Bonsai.Sgen.Tests/CasingGenerationTests.cs b/Bonsai.Sgen.Tests/CasingGenerationTests.cs new file mode 100644 index 0000000..1badb12 --- /dev/null +++ b/Bonsai.Sgen.Tests/CasingGenerationTests.cs @@ -0,0 +1,56 @@ +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NJsonSchema; + +namespace Bonsai.Sgen.Tests +{ + [TestClass] + public class CasingGenerationTests + { + private static Task CreateTestSchema() + { + return JsonSchema.FromJsonAsync(@" +{ + ""$schema"": ""http://json-schema.org/draft-04/schema#"", + ""type"": ""object"", + ""title"": ""Container"", + ""properties"": { + ""base_type"": { + ""oneOf"": [ + { + ""$ref"": ""#/definitions/thing_container"" + }, + { + ""type"": ""null"" + } + ] + } + }, + ""definitions"": { + ""thing_container"": { + ""type"": ""object"", + ""properties"": { + ""bar"": { + ""type"": [ + ""null"", + ""string"" + ] + } + } + } + } +} +"); + } + + [TestMethod] + public async Task GenerateFromSnakeCase_GeneratePascalCaseNames() + { + var schema = await CreateTestSchema(); + var generator = TestHelper.CreateGenerator(schema); + var code = generator.GenerateFile(); + Assert.IsTrue(code.Contains("public ThingContainer BaseType"), "Incorrect casing for property name."); + CompilerTestHelper.CompileFromSource(code); + } + } +}