diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/EnumDeclarationTest.cs index e0676c10..00ff4fac 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/EnumDeclarationTest.cs @@ -63,6 +63,12 @@ public abstract class EnumDeclarationTest : PInvokeGeneratorTest [Test] public Task WithTypeStarOverrideTest() => WithTypeStarOverrideTestImpl(); + [Test] + public Task WithAnonymousEnumTest() => WithAnonymousEnumTestImpl(); + + [Test] + public Task WithReferenceToAnonymousEnumEnumeratorTest() => WithReferenceToAnonymousEnumEnumeratorTestImpl(); + protected abstract Task BasicTestImpl(); protected abstract Task BasicValueTestImpl(); @@ -73,6 +79,7 @@ public abstract class EnumDeclarationTest : PInvokeGeneratorTest protected abstract Task ExplicitTypedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType); + protected abstract Task RemapTestImpl(); protected abstract Task WithAttributeTestImpl(); @@ -96,4 +103,8 @@ public abstract class EnumDeclarationTest : PInvokeGeneratorTest protected abstract Task WithTypeStarTestImpl(); protected abstract Task WithTypeStarOverrideTestImpl(); + + protected abstract Task WithAnonymousEnumTestImpl(); + + protected abstract Task WithReferenceToAnonymousEnumEnumeratorTestImpl(); } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/EnumDeclarationTest.cs index 35f7554e..60f6421a 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/EnumDeclarationTest.cs @@ -550,4 +550,61 @@ public enum MyEnum2 : uint }; return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @"using static ClangSharp.Test.Methods; + +namespace ClangSharp.Test +{ + public enum MyEnum2 + { + MyEnum2_Value1 = MyEnum1_Value1, + } + + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + } +} +"; + + 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") }; + return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + + [NativeTypeName(""const int"")] + public const int MyEnum2_Value1 = (int)(MyEnum1_Value1) + 1; + } +} +"; + 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") }; + return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/EnumDeclarationTest.cs index fcb6938a..7d07fefd 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/EnumDeclarationTest.cs @@ -550,4 +550,62 @@ public enum MyEnum2 : uint }; return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @"using static ClangSharp.Test.Methods; + +namespace ClangSharp.Test +{ + public enum MyEnum2 + { + MyEnum2_Value1 = MyEnum1_Value1, + } + + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + } +} +"; + + 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") }; + return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + + [NativeTypeName(""const int"")] + public const int MyEnum2_Value1 = (int)(MyEnum1_Value1) + 1; + } +} +"; + 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") }; + return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/EnumDeclarationTest.cs index 4aa0b602..ada29394 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/EnumDeclarationTest.cs @@ -550,4 +550,62 @@ public enum MyEnum2 : uint }; return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @"using static ClangSharp.Test.Methods; + +namespace ClangSharp.Test +{ + public enum MyEnum2 + { + MyEnum2_Value1 = MyEnum1_Value1, + } + + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + } +} +"; + + 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") }; + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + + [NativeTypeName(""const int"")] + public const int MyEnum2_Value1 = (int)(MyEnum1_Value1) + 1; + } +} +"; + 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") }; + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/EnumDeclarationTest.cs index c2f9afe1..abbb6b17 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/EnumDeclarationTest.cs @@ -550,4 +550,61 @@ public enum MyEnum2 : uint }; return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @"using static ClangSharp.Test.Methods; + +namespace ClangSharp.Test +{ + public enum MyEnum2 + { + MyEnum2_Value1 = MyEnum1_Value1, + } + + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + } +} +"; + + 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") }; + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + + [NativeTypeName(""const int"")] + public const int MyEnum2_Value1 = (int)(MyEnum1_Value1) + 1; + } +} +"; + 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") }; + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/EnumDeclarationTest.cs index de68287b..f83cbbe6 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/EnumDeclarationTest.cs @@ -224,7 +224,7 @@ public enum MyEnum2 "; var withAttributes = new Dictionary> - { + { ["MyEnum1"] = new List() { "Flags" } }; return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withAttributes: withAttributes); @@ -550,4 +550,62 @@ public enum MyEnum2 : uint }; return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @"using static ClangSharp.Test.Methods; + +namespace ClangSharp.Test +{ + public enum MyEnum2 + { + MyEnum2_Value1 = MyEnum1_Value1, + } + + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + } +} +"; + + 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") }; + return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + + [NativeTypeName(""const int"")] + public const int MyEnum2_Value1 = (int)(MyEnum1_Value1) + 1; + } +} +"; + 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") }; + return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/EnumDeclarationTest.cs index baf2a46d..d6fee03f 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/EnumDeclarationTest.cs @@ -550,4 +550,62 @@ public enum MyEnum2 : uint }; return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @"using static ClangSharp.Test.Methods; + +namespace ClangSharp.Test +{ + public enum MyEnum2 + { + MyEnum2_Value1 = MyEnum1_Value1, + } + + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + } +} +"; + + 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") }; + return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public static partial class Methods + { + public const int MyEnum1_Value1 = 1; + + [NativeTypeName(""const int"")] + public const int MyEnum2_Value1 = (int)(MyEnum1_Value1) + 1; + } +} +"; + 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") }; + return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/EnumDeclarationTest.cs index b7e01d3b..e407bb54 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/EnumDeclarationTest.cs @@ -652,4 +652,79 @@ enum MyEnum2 : int }; return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @" + + + + int + + int + + MyEnum1_Value1 + + + + + + int + + 1 + + + + + +"; + + 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") }; + return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @" + + + + + int + + 1 + + + + int + + (int)(MyEnum1_Value1) + 1 + + + + + +"; + 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") }; + return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/EnumDeclarationTest.cs index 48b4cb82..7dcc7ac9 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/EnumDeclarationTest.cs @@ -652,4 +652,79 @@ enum MyEnum2 : int }; return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @" + + + + int + + int + + MyEnum1_Value1 + + + + + + int + + 1 + + + + + +"; + + 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") }; + return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @" + + + + + int + + 1 + + + + int + + (int)(MyEnum1_Value1) + 1 + + + + + +"; + 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") }; + return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/EnumDeclarationTest.cs index c1cdf5e8..cfb68edf 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/EnumDeclarationTest.cs @@ -652,4 +652,79 @@ enum MyEnum2 : int }; return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @" + + + + int + + int + + MyEnum1_Value1 + + + + + + int + + 1 + + + + + +"; + + 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") }; + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @" + + + + + int + + 1 + + + + int + + (int)(MyEnum1_Value1) + 1 + + + + + +"; + 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") }; + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/EnumDeclarationTest.cs index 7759d613..d7a426b1 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/EnumDeclarationTest.cs @@ -652,4 +652,79 @@ enum MyEnum2 : int }; return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @" + + + + int + + int + + MyEnum1_Value1 + + + + + + int + + 1 + + + + + +"; + + 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") }; + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @" + + + + + int + + 1 + + + + int + + (int)(MyEnum1_Value1) + 1 + + + + + +"; + 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") }; + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/EnumDeclarationTest.cs index c98a649e..9d6ce193 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/EnumDeclarationTest.cs @@ -652,4 +652,79 @@ enum MyEnum2 : int }; return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @" + + + + int + + int + + MyEnum1_Value1 + + + + + + int + + 1 + + + + + +"; + + 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") }; + return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @" + + + + + int + + 1 + + + + int + + (int)(MyEnum1_Value1) + 1 + + + + + +"; + 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") }; + return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/EnumDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/EnumDeclarationTest.cs index a35b008f..4334e19e 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/EnumDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/EnumDeclarationTest.cs @@ -652,4 +652,79 @@ enum MyEnum2 : int }; return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, withTypes: withTypes); } + + protected override Task WithAnonymousEnumTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +enum MyEnum2 : int +{ + MyEnum2_Value1 = MyEnum1_Value1, +}; +"; + + var expectedOutputContents = @" + + + + int + + int + + MyEnum1_Value1 + + + + + + int + + 1 + + + + + +"; + + 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") }; + return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } + + protected override Task WithReferenceToAnonymousEnumEnumeratorTestImpl() + { + var inputContents = @"enum +{ + MyEnum1_Value1 = 1, +}; + +const int MyEnum2_Value1 = MyEnum1_Value1 + 1; +"; + + var expectedOutputContents = @" + + + + + int + + 1 + + + + int + + (int)(MyEnum1_Value1) + 1 + + + + + +"; + 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") }; + return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + } }