Test renaming of enumerants that are C# keywords.

This commit is contained in:
Kuba Ober 2019-08-29 01:36:47 -04:00
parent 9a7ccc6b13
commit 4411cd90d0
6 changed files with 74 additions and 0 deletions

View File

@ -59,5 +59,15 @@ namespace capnpc_csharp.Tests.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] UnitTest1_capnp {
get {
object obj = ResourceManager.GetObject("UnitTest1_capnp", resourceCulture);
return ((byte[])(obj));
}
}
}
}

View File

@ -118,4 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="UnitTest1_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnitTest1.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

Binary file not shown.

View File

@ -0,0 +1,5 @@
@0x93d3c4d19cd84a4c;
enum Enumerant {
byte @0;
}

View File

@ -0,0 +1,55 @@
using capnpc_csharp.Tests.Properties;
using Capnp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace CapnpC
{
[TestClass]
public class UnitTests
{
[TestMethod]
public void Test00Enumerant()
{
var model = Load(Resources.UnitTest1_capnp);
Assert.AreEqual("@byte", GetTypeDef(0xc8461867c409f5d4, model).Enumerants[0].Literal);
}
static Model.TypeDefinition GetTypeDef(ulong id, Model.SchemaModel model)
{
foreach (var defs in model.FilesToGenerate.Select(f => f.NestedTypes))
{
if (GetTypeDef(id, defs) is Model.TypeDefinition def) return def;
}
return null;
}
static Model.TypeDefinition GetTypeDef(ulong id, IEnumerable<Model.TypeDefinition> defs)
{
foreach (var def in defs)
{
if (def.Id == id) return def;
var sub = GetTypeDef(id, def.NestedTypes);
if (sub != null) return sub;
}
return null;
}
static Model.SchemaModel Load(byte[] data)
{
WireFrame segments;
var input = new MemoryStream(data);
using (input)
{
segments = Framing.ReadSegments(input);
}
var dec = DeserializerState.CreateRoot(segments);
var reader = Schema.CodeGeneratorRequest.Reader.Create(dec);
var model = Model.SchemaModel.Create(reader);
return model;
}
}
}

View File

@ -19,6 +19,7 @@
<ItemGroup>
<Compile Remove="*.cs" />
<Compile Include="UnitTests.cs" />
</ItemGroup>
<ItemGroup>