Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RGen] Add some extra tests for properties. #21992

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading