Skip to content

Commit d9ff6b1

Browse files
committed
Add a test covering a nested anonymous union
1 parent ad8fb60 commit d9ff6b1

File tree

1 file changed

+44
-0
lines changed
  • tests/ClangSharp.PInvokeGenerator.UnitTests

1 file changed

+44
-0
lines changed

tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,50 @@ public partial struct MyStruct
6666
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard);
6767
}
6868

69+
[Test]
70+
public Task EnumTest()
71+
{
72+
var inputContents = @"enum {
73+
VALUE1 = 0,
74+
VALUE2,
75+
VALUE3
76+
};
77+
78+
struct MyStruct {
79+
enum {
80+
VALUEA = 0,
81+
VALUEB,
82+
VALUEC
83+
} field;
84+
};
85+
";
86+
var expectedOutputContents = @"namespace ClangSharp.Test
87+
{
88+
public partial struct MyStruct
89+
{
90+
[NativeTypeName(""__AnonymousEnum_ClangUnsavedFile_L8_C5"")]
91+
public int field;
92+
93+
public const int VALUEA = 0;
94+
public const int VALUEB = 1;
95+
public const int VALUEC = 2;
96+
}
97+
98+
public static partial class Methods
99+
{
100+
public const int VALUE1 = 0;
101+
public const int VALUE2 = 1;
102+
public const int VALUE3 = 2;
103+
}
104+
}
105+
";
106+
var diagnostics = new[] {
107+
new Diagnostic(DiagnosticLevel.Info, "Found anonymous enum: __AnonymousEnum_ClangUnsavedFile_L1_C1. Mapping values as constants in: Methods", "Line 1, Column 1 in ClangUnsavedFile.h"),
108+
new Diagnostic(DiagnosticLevel.Info, "Found anonymous enum: __AnonymousEnum_ClangUnsavedFile_L8_C5. Mapping values as constants in: Methods", "Line 8, Column 5 in ClangUnsavedFile.h")
109+
};
110+
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, expectedDiagnostics: diagnostics, language: "c", languageStandard: DefaultCStandard);
111+
}
112+
69113
[Test]
70114
public Task StructTest()
71115
{

0 commit comments

Comments
 (0)