Skip to content

Commit 3081277

Browse files
committed
Fix CppClass.ToString() for ObjC generics
1 parent 82a2ede commit 3081277

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/CppAst.Tests/TestObjectiveC.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ @interface BaseInterface
204204
Assert.AreEqual(1, myInterface.TemplateParameters.Count);
205205
Assert.IsTrue(myInterface.TemplateParameters[0] is CppTemplateParameterType templateParam1 && templateParam1.Name == "T1");
206206

207+
var text = myInterface.ToString();
208+
Assert.AreEqual("@interface MyInterface<T1> : BaseInterface", text);
209+
207210
// By default, typedef declared within interfaces are global, but in that case, it is depending on a template parameter
208211
// So it is not part of the global namespace
209212
Assert.AreEqual(0, compilation.Typedefs.Count);
@@ -279,7 +282,10 @@ @interface MyInterface <MyProtocol>
279282
Assert.AreEqual(2, myProtocol2.ObjCImplementedProtocols.Count);
280283
Assert.AreEqual(myProtocol, myProtocol2.ObjCImplementedProtocols[0]);
281284
Assert.AreEqual(myProtocol1, myProtocol2.ObjCImplementedProtocols[1]);
282-
285+
286+
var text2 = myProtocol2.ToString();
287+
Assert.AreEqual("@protocol MyProtocol2 <MyProtocol, MyProtocol1>", text2);
288+
283289
var myInterface = compilation.Classes[3];
284290
Assert.AreEqual(CppClassKind.ObjCInterface, myInterface.ClassKind);
285291
Assert.AreEqual("MyInterface", myInterface.Name);
@@ -345,11 +351,13 @@ @interface MyInterface (MyCategory)
345351
Assert.AreEqual("MyInterface", myInterfaceWithCategory.Name);
346352
Assert.AreEqual("MyCategory", myInterfaceWithCategory.ObjCCategoryName);
347353
Assert.AreEqual(myInterface, myInterfaceWithCategory.ObjCCategoryTargetClass);
354+
355+
var text = myInterfaceWithCategory.ToString();
356+
Assert.AreEqual("@interface MyInterface (MyCategory)", text);
348357
}, GetDefaultObjCOptions()
349358
);
350359
}
351-
352-
360+
353361
private static CppParserOptions GetDefaultObjCOptions()
354362
{
355363
return new CppParserOptions

src/CppAst/CppClass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public override string ToString()
248248
builder.Append(TemplateSpecializedArguments[i].ToString());
249249
}
250250
}
251-
else if(TemplateKind == CppTemplateKind.TemplateClass)
251+
else if (TemplateParameters.Count > 0)
252252
{
253253
for (var i = 0; i < TemplateParameters.Count; i++)
254254
{

0 commit comments

Comments
 (0)