Test for absence of name clashes with immediately enclosing type.

This commit is contained in:
Kuba Ober 2019-08-29 10:28:53 -04:00
parent 4411cd90d0
commit e543b62e2b
4 changed files with 24 additions and 2 deletions

View File

@ -3,3 +3,7 @@
enum Enumerant {
byte @0;
}
struct Foo {
foo @0: UInt8;
}

View File

@ -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))

View File

@ -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)
{