mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 23:01:44 +01:00
Test renaming of enumerants that are C# keywords.
This commit is contained in:
parent
9a7ccc6b13
commit
4411cd90d0
10
capnpc-csharp.tests/Properties/Resources.Designer.cs
generated
10
capnpc-csharp.tests/Properties/Resources.Designer.cs
generated
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
BIN
capnpc-csharp.tests/Resources/UnitTest1.capnp.bin
Normal file
BIN
capnpc-csharp.tests/Resources/UnitTest1.capnp.bin
Normal file
Binary file not shown.
5
capnpc-csharp.tests/UnitTest1.capnp
Normal file
5
capnpc-csharp.tests/UnitTest1.capnp
Normal file
@ -0,0 +1,5 @@
|
||||
@0x93d3c4d19cd84a4c;
|
||||
|
||||
enum Enumerant {
|
||||
byte @0;
|
||||
}
|
55
capnpc-csharp.tests/UnitTests.cs
Normal file
55
capnpc-csharp.tests/UnitTests.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="*.cs" />
|
||||
<Compile Include="UnitTests.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user