Skip to content

Commit 124535b

Browse files
Merge pull request #497 from tannergooding/main
Add a test covering a nested anonymous union
2 parents ad8fb60 + 451803c commit 124535b

File tree

1 file changed

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

1 file changed

+73
-0
lines changed

tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,79 @@ 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+
string expectedOutputContents;
87+
88+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
89+
{
90+
expectedOutputContents = @"namespace ClangSharp.Test
91+
{
92+
public partial struct MyStruct
93+
{
94+
[NativeTypeName(""__AnonymousEnum_ClangUnsavedFile_L8_C5"")]
95+
public int field;
96+
97+
public const int VALUEA = 0;
98+
public const int VALUEB = 1;
99+
public const int VALUEC = 2;
100+
}
101+
102+
public static partial class Methods
103+
{
104+
public const int VALUE1 = 0;
105+
public const int VALUE2 = 1;
106+
public const int VALUE3 = 2;
107+
}
108+
}
109+
";
110+
}
111+
else
112+
{
113+
expectedOutputContents = @"namespace ClangSharp.Test
114+
{
115+
public partial struct MyStruct
116+
{
117+
[NativeTypeName(""__AnonymousEnum_ClangUnsavedFile_L8_C5"")]
118+
public uint field;
119+
120+
public const uint VALUEA = 0;
121+
public const uint VALUEB = 1;
122+
public const uint VALUEC = 2;
123+
}
124+
125+
public static partial class Methods
126+
{
127+
public const uint VALUE1 = 0;
128+
public const uint VALUE2 = 1;
129+
public const uint VALUE3 = 2;
130+
}
131+
}
132+
";
133+
}
134+
135+
var diagnostics = new[] {
136+
new Diagnostic(DiagnosticLevel.Info, "Found anonymous enum: __AnonymousEnum_ClangUnsavedFile_L1_C1. Mapping values as constants in: Methods", "Line 1, Column 1 in ClangUnsavedFile.h"),
137+
new Diagnostic(DiagnosticLevel.Info, "Found anonymous enum: __AnonymousEnum_ClangUnsavedFile_L8_C5. Mapping values as constants in: Methods", "Line 8, Column 5 in ClangUnsavedFile.h")
138+
};
139+
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, expectedDiagnostics: diagnostics, language: "c", languageStandard: DefaultCStandard);
140+
}
141+
69142
[Test]
70143
public Task StructTest()
71144
{

0 commit comments

Comments
 (0)