From 37de8a9b76ab744d1e83e41a979f6f52c5057481 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Thu, 16 Jan 2025 14:18:38 -0500 Subject: [PATCH] [RGen] Add some extra tests for properties. (#21992) Add some extra tests to cover more properties combinations. PS: I thought we had a bug, we didn't but is always nice to cover more cases. --------- Co-authored-by: GitHub Actions Autoformatter --- .../DataModel/PropertyTests.cs | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests.cs index 32e042499885..fe49121168bb 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests.cs @@ -1025,6 +1025,162 @@ public Utils.MyClass Name { ), ]) ]; + + const string autoPropertyGetterWithAttribute = @" +using System.Runtime.Versioning; +using ObjCBindings; + +namespace Test; + +public class TestClass { + const string name = ""Test""; + + [SupportedOSPlatform (""ios"")] + public string Name { + [SupportedOSPlatform (""ios17.0"")] + get; + set; + } +} +"; + getterAvailabilityBuilder.Clear (); + getterAvailabilityBuilder.Add (supportedPlatform: new SupportedOSPlatformData (platformName: "ios17.0")); + yield return [ + autoPropertyGetterWithAttribute, + new Property ( + name: "Name", + returnType: ReturnTypeForString (), + symbolAvailability: propertyAvailabilityBuilder.ToImmutable (), + attributes: [ + new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios"]), + ], + modifiers: [ + SyntaxFactory.Token (kind: SyntaxKind.PublicKeyword), + ], + accessors: [ + new ( + accessorKind: AccessorKind.Getter, + symbolAvailability: getterAvailabilityBuilder.ToImmutable (), + exportPropertyData: null, + attributes: [ + new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios17.0"]), + ], + modifiers: [] + ), + new ( + accessorKind: AccessorKind.Setter, + symbolAvailability: propertyAvailabilityBuilder.ToImmutable (), + exportPropertyData: null, + attributes: [], + modifiers: [] + ), + ]) + ]; + + const string staticAutoPropertyGetterWithAttribute = @" +using System.Runtime.Versioning; +using ObjCBindings; + +namespace Test; + +public class TestClass { + const string name = ""Test""; + + [SupportedOSPlatform (""ios"")] + public static string Name { + [SupportedOSPlatform (""ios17.0"")] + get; + set; + } +} +"; + getterAvailabilityBuilder.Clear (); + getterAvailabilityBuilder.Add (supportedPlatform: new SupportedOSPlatformData (platformName: "ios17.0")); + yield return [ + staticAutoPropertyGetterWithAttribute, + new Property ( + name: "Name", + returnType: ReturnTypeForString (), + symbolAvailability: propertyAvailabilityBuilder.ToImmutable (), + attributes: [ + new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios"]), + ], + modifiers: [ + SyntaxFactory.Token (kind: SyntaxKind.PublicKeyword), + SyntaxFactory.Token (kind: SyntaxKind.StaticKeyword), + ], + accessors: [ + new ( + accessorKind: AccessorKind.Getter, + symbolAvailability: getterAvailabilityBuilder.ToImmutable (), + exportPropertyData: null, + attributes: [ + new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios17.0"]), + ], + modifiers: [] + ), + new ( + accessorKind: AccessorKind.Setter, + symbolAvailability: propertyAvailabilityBuilder.ToImmutable (), + exportPropertyData: null, + attributes: [], + modifiers: [] + ), + ]) + ]; + + const string partialStaticAutoPropertyGetterWithAttribute = @" +using System.Runtime.Versioning; +using ObjCBindings; + +namespace Test; + +public class TestClass { + const string name = ""Test""; + + [SupportedOSPlatform (""ios"")] + public static partial string Name { + [SupportedOSPlatform (""ios17.0"")] + get; + set; + } +} +"; + getterAvailabilityBuilder.Clear (); + getterAvailabilityBuilder.Add (supportedPlatform: new SupportedOSPlatformData (platformName: "ios17.0")); + yield return [ + partialStaticAutoPropertyGetterWithAttribute, + new Property ( + name: "Name", + returnType: ReturnTypeForString (), + symbolAvailability: propertyAvailabilityBuilder.ToImmutable (), + attributes: [ + new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios"]), + ], + modifiers: [ + SyntaxFactory.Token (kind: SyntaxKind.PublicKeyword), + SyntaxFactory.Token (kind: SyntaxKind.StaticKeyword), + SyntaxFactory.Token (kind: SyntaxKind.PartialKeyword), + ], + accessors: [ + new ( + accessorKind: AccessorKind.Getter, + symbolAvailability: getterAvailabilityBuilder.ToImmutable (), + exportPropertyData: null, + attributes: [ + new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios17.0"]), + ], + modifiers: [] + ), + new ( + accessorKind: AccessorKind.Setter, + symbolAvailability: propertyAvailabilityBuilder.ToImmutable (), + exportPropertyData: null, + attributes: [], + modifiers: [] + ), + ]) + ]; } IEnumerator IEnumerable.GetEnumerator ()