Skip to content

Commit

Permalink
Merge pull request #497 from tannergooding/main
Browse files Browse the repository at this point in the history
Add a test covering a nested anonymous union
  • Loading branch information
tannergooding authored Nov 19, 2023
2 parents ad8fb60 + 451803c commit 124535b
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,79 @@ public partial struct MyStruct
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard);
}

[Test]
public Task EnumTest()
{
var inputContents = @"enum {
VALUE1 = 0,
VALUE2,
VALUE3
};
struct MyStruct {
enum {
VALUEA = 0,
VALUEB,
VALUEC
} field;
};
";
string expectedOutputContents;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct
{
[NativeTypeName(""__AnonymousEnum_ClangUnsavedFile_L8_C5"")]
public int field;
public const int VALUEA = 0;
public const int VALUEB = 1;
public const int VALUEC = 2;
}
public static partial class Methods
{
public const int VALUE1 = 0;
public const int VALUE2 = 1;
public const int VALUE3 = 2;
}
}
";
}
else
{
expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct
{
[NativeTypeName(""__AnonymousEnum_ClangUnsavedFile_L8_C5"")]
public uint field;
public const uint VALUEA = 0;
public const uint VALUEB = 1;
public const uint VALUEC = 2;
}
public static partial class Methods
{
public const uint VALUE1 = 0;
public const uint VALUE2 = 1;
public const uint VALUE3 = 2;
}
}
";
}

var diagnostics = new[] {
new Diagnostic(DiagnosticLevel.Info, "Found anonymous enum: __AnonymousEnum_ClangUnsavedFile_L1_C1. Mapping values as constants in: Methods", "Line 1, Column 1 in ClangUnsavedFile.h"),
new Diagnostic(DiagnosticLevel.Info, "Found anonymous enum: __AnonymousEnum_ClangUnsavedFile_L8_C5. Mapping values as constants in: Methods", "Line 8, Column 5 in ClangUnsavedFile.h")
};
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, expectedDiagnostics: diagnostics, language: "c", languageStandard: DefaultCStandard);
}

[Test]
public Task StructTest()
{
Expand Down

0 comments on commit 124535b

Please sign in to comment.