From 9fd43467d28520ca2302ba4700e4accab7d57e4a Mon Sep 17 00:00:00 2001 From: Christian Sauer Date: Fri, 24 Jan 2025 11:13:12 +0100 Subject: [PATCH 1/7] feat: Add byte enum to method params --- .../AutomaticInterface/Builder.cs | 3 +- .../AutomaticInterface/InterfaceBuilder.cs | 2 + AutomaticInterface/Tests/GeneratorTests.cs | 44 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 9b167ca..5f838ed 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -15,7 +15,8 @@ private static string InheritDoc(ISymbol source) => private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormat = new( genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, - memberOptions: SymbolDisplayMemberOptions.IncludeParameters, + memberOptions: SymbolDisplayMemberOptions.IncludeParameters + | SymbolDisplayMemberOptions.IncludeContainingType, parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeParamsRefOut | SymbolDisplayParameterOptions.IncludeDefaultValue diff --git a/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs b/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs index 2e60a05..b43b128 100644 --- a/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs +++ b/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs @@ -121,7 +121,9 @@ public string Build() cb.Indent(); foreach (var method in methodInfos) + { BuildMethod(cb, method); + } cb.Dedent(); diff --git a/AutomaticInterface/Tests/GeneratorTests.cs b/AutomaticInterface/Tests/GeneratorTests.cs index 1ee64b7..0af181e 100644 --- a/AutomaticInterface/Tests/GeneratorTests.cs +++ b/AutomaticInterface/Tests/GeneratorTests.cs @@ -2025,4 +2025,48 @@ public partial interface IDemoClass """; GenerateCode(code).Should().Be(expected); } + + [Fact] + public void WorksWithByteEnums() + { + const string code = """ + + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample; + + public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 }; + + [GenerateAutomaticInterface] + public class DemoClass + { + public void MethodWithDefaultParameter(EnumWithByteType a = EnumWithByteType.B) { } + } + + """; + + const string expected = """ + //-------------------------------------------------------------------------------------------------- + // + // This code was generated by a tool. + // + // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. + // + //-------------------------------------------------------------------------------------------------- + + namespace AutomaticInterfaceExample + { + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } + } + + """; + GenerateCode(code).Should().Be(expected); + } } From 8263c385e362e5cdde85d5f9cf2cf5e7cb671918 Mon Sep 17 00:00:00 2001 From: Christian Sauer Date: Fri, 24 Jan 2025 11:30:24 +0100 Subject: [PATCH 2/7] wip: fix tests --- .../AutomaticInterface/Builder.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 5f838ed..5340341 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -28,6 +28,24 @@ private static string InheritDoc(ISymbol source) => | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers ); + /// + /// We do need to be able to group shadowing and new methods/events into a single entry, hence this is missing SymbolDisplayMemberOptions.IncludeContainingType + /// + private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormatForGrouping = + new( + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + memberOptions: SymbolDisplayMemberOptions.IncludeParameters, + parameterOptions: SymbolDisplayParameterOptions.IncludeType + | SymbolDisplayParameterOptions.IncludeParamsRefOut + | SymbolDisplayParameterOptions.IncludeDefaultValue + | SymbolDisplayParameterOptions.IncludeName, + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers + ); + public static string BuildInterfaceFor(ITypeSymbol typeSymbol) { if ( @@ -92,7 +110,7 @@ private static void AddMethodsToInterface(List members, InterfaceBuilde .Where(x => x.MethodKind == MethodKind.Ordinary) .Where(x => x.ContainingType.Name != nameof(Object)) .Where(x => !HasIgnoreAttribute(x)) - .GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormat)) + .GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormatForGrouping)) .Select(g => g.First()) .ToList() .ForEach(method => AddMethod(codeGenerator, method)); @@ -183,7 +201,7 @@ private static void AddEventsToInterface(List members, InterfaceBuilder members .Where(x => x.Kind == SymbolKind.Event) .OfType() - .GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormat)) + .GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormatForGrouping)) .Select(g => g.First()) .ToList() .ForEach(evt => From 7890658db6f3dbc0c4172cc2429ff441137e17aa Mon Sep 17 00:00:00 2001 From: Christian Sauer Date: Mon, 27 Jan 2025 08:53:55 +0100 Subject: [PATCH 3/7] feat: add more tests for enums --- AutomaticInterface/Tests/GeneratorTests.cs | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/AutomaticInterface/Tests/GeneratorTests.cs b/AutomaticInterface/Tests/GeneratorTests.cs index 0af181e..4e624f6 100644 --- a/AutomaticInterface/Tests/GeneratorTests.cs +++ b/AutomaticInterface/Tests/GeneratorTests.cs @@ -2069,4 +2069,92 @@ public partial interface IDemoClass """; GenerateCode(code).Should().Be(expected); } + + [Fact] + public void WorksWithByteEnumsAsReturnType() + { + const string code = """ + + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample; + + public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 }; + + [GenerateAutomaticInterface] + public class DemoClass + { + public EnumWithByteType MethodWithDefaultParameter(EnumWithByteType a = EnumWithByteType.B) { return a; } + } + + """; + + const string expected = """ + //-------------------------------------------------------------------------------------------------- + // + // This code was generated by a tool. + // + // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. + // + //-------------------------------------------------------------------------------------------------- + + namespace AutomaticInterfaceExample + { + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + global::AutomaticInterfaceExample.EnumWithByteType MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } + } + + """; + GenerateCode(code).Should().Be(expected); + } + + [Fact] + public void WorksWithByteEnumsProperties() + { + const string code = """ + + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample; + + public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 }; + + [GenerateAutomaticInterface] + public class DemoClass + { + public EnumWithByteType SomeProperty { get; set; } + } + + """; + + const string expected = """ + //-------------------------------------------------------------------------------------------------- + // + // This code was generated by a tool. + // + // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. + // + //-------------------------------------------------------------------------------------------------- + + namespace AutomaticInterfaceExample + { + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + global::AutomaticInterfaceExample.EnumWithByteType SomeProperty { get; set; } + + } + } + + """; + GenerateCode(code).Should().Be(expected); + } } From d71d9d8a04bb931c4313d5689a4e30117b74a47e Mon Sep 17 00:00:00 2001 From: Christian Sauer Date: Mon, 27 Jan 2025 09:37:12 +0100 Subject: [PATCH 4/7] feat: docs --- .../AutomaticInterface/AutomaticInterface.csproj | 2 +- README.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj b/AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj index e03d7d7..5efb0d5 100644 --- a/AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj +++ b/AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj @@ -25,7 +25,7 @@ MIT True latest-Recommended - 5.1.1 + 5.1.2 README.md true 1701;1702;NU5128 diff --git a/README.md b/README.md index 8dd6a58..ff4b57e 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,10 @@ Should be simply a build and run Tests ## Changelog +### 5.1.2 + +- Fixing enums in method signatures + ### 5.1.1 - Emit `new()` type constraints on generic type parameters; emit `params` keyword for method parameters. Thanks, @simonmckenzie! From 6f7f480eda599980156ed94cb287f16a90a49eeb Mon Sep 17 00:00:00 2001 From: Christian Sauer Date: Tue, 28 Jan 2025 09:00:32 +0100 Subject: [PATCH 5/7] feat: tests using verify --- .../Enums.WorksWithByteEnums.verified.txt | 18 +++++ ...orksWithByteEnumsAsReturnType.verified.txt | 18 +++++ ....WorksWithByteEnumsProperties.verified.txt | 18 +++++ AutomaticInterface/Tests/Enums/Enums.cs | 73 +++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnums.verified.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnumsAsReturnType.verified.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnumsProperties.verified.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.cs diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnums.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnums.verified.txt new file mode 100644 index 0000000..90b8ad7 --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnums.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnumsAsReturnType.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnumsAsReturnType.verified.txt new file mode 100644 index 0000000..3f0a56c --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnumsAsReturnType.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + global::AutomaticInterfaceExample.EnumWithByteType MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnumsProperties.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnumsProperties.verified.txt new file mode 100644 index 0000000..d3cdbdd --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithByteEnumsProperties.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + global::AutomaticInterfaceExample.EnumWithByteType SomeProperty { get; set; } + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.cs b/AutomaticInterface/Tests/Enums/Enums.cs new file mode 100644 index 0000000..fa27833 --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.cs @@ -0,0 +1,73 @@ +namespace Tests.Enums; + +public class Enums +{ + [Fact] + public async Task WorksWithByteEnums() + { + const string code = """ + + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample; + + public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 }; + + [GenerateAutomaticInterface] + public class DemoClass + { + public void MethodWithDefaultParameter(EnumWithByteType a = EnumWithByteType.B) { } + } + + """; + + await Verify(Infrastructure.GenerateCode(code)); + } + + [Fact] + public async Task WorksWithByteEnumsAsReturnType() + { + const string code = """ + + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample; + + public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 }; + + [GenerateAutomaticInterface] + public class DemoClass + { + public EnumWithByteType MethodWithDefaultParameter(EnumWithByteType a = EnumWithByteType.B) { return a; } + } + + """; + + await Verify(Infrastructure.GenerateCode(code)); + } + + [Fact] + public async Task WorksWithByteEnumsProperties() + { + const string code = """ + + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample; + + public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 }; + + [GenerateAutomaticInterface] + public class DemoClass + { + public EnumWithByteType SomeProperty { get; set; } + } + + """; + + await Verify(Infrastructure.GenerateCode(code)); + } +} From f2ea6e3044a496c5b81936e938b865d77ace0309 Mon Sep 17 00:00:00 2001 From: Christian Sauer Date: Tue, 28 Jan 2025 09:01:50 +0100 Subject: [PATCH 6/7] feat: Use simons idea on how to avoid having two similar SymbolDisplayFormats --- .../AutomaticInterface/Builder.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 5340341..0a61b40 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -33,17 +33,13 @@ private static string InheritDoc(ISymbol source) => /// private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormatForGrouping = new( - genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, - memberOptions: SymbolDisplayMemberOptions.IncludeParameters, - parameterOptions: SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeParamsRefOut - | SymbolDisplayParameterOptions.IncludeDefaultValue - | SymbolDisplayParameterOptions.IncludeName, - typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier - | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers + genericsOptions: FullyQualifiedDisplayFormat.GenericsOptions, + memberOptions: FullyQualifiedDisplayFormat.MemberOptions + & ~SymbolDisplayMemberOptions.IncludeContainingType, + parameterOptions: FullyQualifiedDisplayFormat.ParameterOptions, + typeQualificationStyle: FullyQualifiedDisplayFormat.TypeQualificationStyle, + globalNamespaceStyle: FullyQualifiedDisplayFormat.GlobalNamespaceStyle, + miscellaneousOptions: FullyQualifiedDisplayFormat.MiscellaneousOptions ); public static string BuildInterfaceFor(ITypeSymbol typeSymbol) From df5a1c07273a0b3315929dd12256633ec29defba Mon Sep 17 00:00:00 2001 From: Christian Sauer Date: Tue, 28 Jan 2025 09:21:47 +0100 Subject: [PATCH 7/7] feat: better enum testing --- .../Enums.WorksWithEnum-byte.verified.txt | 18 ++++++++++ .../Enums.WorksWithEnum-int.verified.txt | 18 ++++++++++ .../Enums.WorksWithEnum-long.verified.txt | 18 ++++++++++ .../Enums/Enums.WorksWithEnum.received.txt | 18 ++++++++++ .../Enums/Enums.WorksWithEnum.verified.txt | 1 + ...ms.WorksWithEnumsAsReturnType.verified.txt | 18 ++++++++++ .../Enums.WorksWithFlagEnum.verified.txt | 18 ++++++++++ AutomaticInterface/Tests/Enums/Enums.cs | 36 ++++++++++++++++--- 8 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-byte.verified.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-int.verified.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-long.verified.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.received.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.verified.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithEnumsAsReturnType.verified.txt create mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithFlagEnum.verified.txt diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-byte.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-byte.verified.txt new file mode 100644 index 0000000..90b8ad7 --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-byte.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-int.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-int.verified.txt new file mode 100644 index 0000000..90b8ad7 --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-int.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-long.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-long.verified.txt new file mode 100644 index 0000000..90b8ad7 --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum-long.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.received.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.received.txt new file mode 100644 index 0000000..90b8ad7 --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.received.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithEnumsAsReturnType.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnumsAsReturnType.verified.txt new file mode 100644 index 0000000..3f0a56c --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnumsAsReturnType.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + global::AutomaticInterfaceExample.EnumWithByteType MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithFlagEnum.verified.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithFlagEnum.verified.txt new file mode 100644 index 0000000..90b8ad7 --- /dev/null +++ b/AutomaticInterface/Tests/Enums/Enums.WorksWithFlagEnum.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface IDemoClass + { + /// + void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); + + } +} diff --git a/AutomaticInterface/Tests/Enums/Enums.cs b/AutomaticInterface/Tests/Enums/Enums.cs index fa27833..cbced1e 100644 --- a/AutomaticInterface/Tests/Enums/Enums.cs +++ b/AutomaticInterface/Tests/Enums/Enums.cs @@ -2,8 +2,35 @@ public class Enums { + [Theory] + [InlineData("byte")] + [InlineData("int")] + [InlineData("long")] + public async Task WorksWithEnum(string enumName) + { + var code = $$""" + + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample; + + public enum EnumWithByteType : {{enumName}} { A = 1, B = 2, C = 3 }; + + [GenerateAutomaticInterface] + public class DemoClass + { + public void MethodWithDefaultParameter(EnumWithByteType a = EnumWithByteType.B) { } + } + + """; + + await Verify(Infrastructure.GenerateCode(code)) + .UseMethodName($"{nameof(WorksWithEnum)}-{enumName}"); + } + [Fact] - public async Task WorksWithByteEnums() + public async Task WorksWithFlagEnum() { const string code = """ @@ -12,7 +39,8 @@ public async Task WorksWithByteEnums() namespace AutomaticInterfaceExample; - public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 }; + [Flags] + public enum EnumWithByteType { A = 1, B = 2, C = 3 }; [GenerateAutomaticInterface] public class DemoClass @@ -26,7 +54,7 @@ public void MethodWithDefaultParameter(EnumWithByteType a = EnumWithByteType.B) } [Fact] - public async Task WorksWithByteEnumsAsReturnType() + public async Task WorksWithEnumsAsReturnType() { const string code = """ @@ -35,7 +63,7 @@ public async Task WorksWithByteEnumsAsReturnType() namespace AutomaticInterfaceExample; - public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 }; + public enum EnumWithByteType { A = 1, B = 2, C = 3 }; [GenerateAutomaticInterface] public class DemoClass