mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-13 23:31:50 +01:00
Test namespace generation in imported types.
This commit is contained in:
parent
4f431856ba
commit
881a59b2c9
10
capnpc-csharp.tests/Properties/Resources.Designer.cs
generated
10
capnpc-csharp.tests/Properties/Resources.Designer.cs
generated
@ -70,6 +70,16 @@ namespace capnpc_csharp.Tests.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
|
/// </summary>
|
||||||
|
internal static byte[] UnitTest10_capnp {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("UnitTest10_capnp", resourceCulture);
|
||||||
|
return ((byte[])(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized resource of type System.Byte[].
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -118,6 +118,9 @@
|
|||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<data name="UnitTest10_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\UnitTest10.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
<data name="UnitTest3_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="UnitTest3_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>..\Resources\UnitTest3.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>..\Resources\UnitTest3.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</data>
|
</data>
|
||||||
|
BIN
capnpc-csharp.tests/Resources/UnitTest10.capnp.bin
Normal file
BIN
capnpc-csharp.tests/Resources/UnitTest10.capnp.bin
Normal file
Binary file not shown.
9
capnpc-csharp.tests/UnitTest10.capnp
Normal file
9
capnpc-csharp.tests/UnitTest10.capnp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
@0xbbfd48ae4b99d012;
|
||||||
|
|
||||||
|
using Cxx = import "/capnp/c++.capnp";
|
||||||
|
|
||||||
|
$Cxx.namespace("Foo::Bar::Baz");
|
||||||
|
|
||||||
|
struct Outer {
|
||||||
|
inner @0: import "UnitTest10b.capnp".Inner ;
|
||||||
|
}
|
7
capnpc-csharp.tests/UnitTest10b.capnp
Normal file
7
capnpc-csharp.tests/UnitTest10b.capnp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
@0xaf95c1c78b01be97;
|
||||||
|
|
||||||
|
using Cxx = import "/capnp/c++.capnp";
|
||||||
|
|
||||||
|
$Cxx.namespace("Foo::Garf::Snarf");
|
||||||
|
|
||||||
|
struct Inner {}
|
@ -1,6 +1,7 @@
|
|||||||
using capnpc_csharp.Tests.Properties;
|
using capnpc_csharp.Tests.Properties;
|
||||||
using Capnp;
|
using Capnp;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -47,6 +48,29 @@ namespace CapnpC
|
|||||||
// Should not throw
|
// Should not throw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test10ImportedNamespaces()
|
||||||
|
{
|
||||||
|
var model = Load(Resources.UnitTest10_capnp);
|
||||||
|
var codeGen = NewGeneratorFor(model);
|
||||||
|
var genFile = model.FilesToGenerate.First();
|
||||||
|
var outerTypeDef = genFile.NestedTypes.First();
|
||||||
|
var outerType = Model.Types.FromDefinition(outerTypeDef);
|
||||||
|
var innerType = outerTypeDef.Fields[0].Type;
|
||||||
|
var innerTypeDef = innerType.Definition;
|
||||||
|
var names = codeGen.GetNames();
|
||||||
|
var outerNameSyntax = names.GetQName(outerType, outerTypeDef);
|
||||||
|
var innerNameSyntax = names.GetQName(innerType, outerTypeDef);
|
||||||
|
string[] outerNamespace = { "Foo", "Bar", "Baz" };
|
||||||
|
string[] innerNamespace = { "Foo", "Garf", "Snarf" };
|
||||||
|
CollectionAssert.AreEqual(outerNamespace, (outerTypeDef.DeclaringElement as Model.GenFile).Namespace);
|
||||||
|
CollectionAssert.AreEqual(innerNamespace, (innerType.Definition.DeclaringElement as Model.GenFile).Namespace);
|
||||||
|
string outerNSStr = String.Join('.', outerNamespace);
|
||||||
|
string innerNSStr = String.Join('.', innerNamespace);
|
||||||
|
Assert.AreEqual($"{outerNSStr}.Outer", outerNameSyntax.ToString());
|
||||||
|
Assert.AreEqual($"{innerNSStr}.Inner", innerNameSyntax.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
static Generator.CodeGenerator NewGeneratorFor(Model.SchemaModel model)
|
static Generator.CodeGenerator NewGeneratorFor(Model.SchemaModel model)
|
||||||
=> new Generator.CodeGenerator(model, new Generator.GeneratorOptions());
|
=> new Generator.CodeGenerator(model, new Generator.GeneratorOptions());
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ namespace CapnpC.Generator
|
|||||||
return qtype;
|
return qtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
NameSyntax GetQName(Model.Type type, TypeDefinition scope)
|
internal NameSyntax GetQName(Model.Type type, TypeDefinition scope)
|
||||||
{
|
{
|
||||||
// FIXME: With the help of the 'scope' parameter we will be able to generate abbreviated
|
// FIXME: With the help of the 'scope' parameter we will be able to generate abbreviated
|
||||||
// qualified names. Unfortunately the commented approach is too naive. It will fail if
|
// qualified names. Unfortunately the commented approach is too naive. It will fail if
|
||||||
|
Loading…
x
Reference in New Issue
Block a user