Skip to content

Commit

Permalink
[RGen] Add some extra tests for properties. (#21992)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mandel-macaque and GitHub Actions Autoformatter authored Jan 16, 2025
1 parent 90bb415 commit 37de8a9
Showing 1 changed file with 156 additions and 0 deletions.
156 changes: 156 additions & 0 deletions tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down

0 comments on commit 37de8a9

Please sign in to comment.