mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-04-20 10:16:24 +02:00
Test for absence of name clashes with immediately enclosing type.
This commit is contained in:
parent
4411cd90d0
commit
e543b62e2b
Binary file not shown.
@ -2,4 +2,8 @@
|
||||
|
||||
enum Enumerant {
|
||||
byte @0;
|
||||
}
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
foo @0: UInt8;
|
||||
}
|
||||
|
@ -18,6 +18,22 @@ namespace CapnpC
|
||||
Assert.AreEqual("@byte", GetTypeDef(0xc8461867c409f5d4, model).Enumerants[0].Literal);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test01NestedClash()
|
||||
{
|
||||
var model = Load(Resources.UnitTest1_capnp);
|
||||
var structFoo = GetTypeDef(0x93db6ba5509bac24, model);
|
||||
var codeGen = NewGeneratorFor(model);
|
||||
codeGen.Transform(model.FilesToGenerate.First());
|
||||
var names = codeGen.GetNames();
|
||||
var fieldName = names.GetCodeIdentifier(structFoo.Fields[0]).ToString();
|
||||
Assert.AreEqual("Foo", structFoo.Name);
|
||||
Assert.AreNotEqual(structFoo.Name, fieldName);
|
||||
}
|
||||
|
||||
static Generator.CodeGenerator NewGeneratorFor(Model.SchemaModel model)
|
||||
=> new Generator.CodeGenerator(model, new Generator.GeneratorOptions());
|
||||
|
||||
static Model.TypeDefinition GetTypeDef(ulong id, Model.SchemaModel model)
|
||||
{
|
||||
foreach (var defs in model.FilesToGenerate.Select(f => f.NestedTypes))
|
||||
|
@ -33,6 +33,8 @@
|
||||
_interfaceGen = new InterfaceSnippetGen(_names);
|
||||
}
|
||||
|
||||
internal GenNames GetNames() => _names;
|
||||
|
||||
IEnumerable<MemberDeclarationSyntax> TransformEnum(TypeDefinition def)
|
||||
{
|
||||
yield return _commonGen.MakeEnum(def);
|
||||
@ -143,7 +145,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
string Transform(GenFile file)
|
||||
internal string Transform(GenFile file)
|
||||
{
|
||||
if (file.Namespace != null)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user