-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rge] Implement the code in the transformer to parse Export attrs.
Add the code that will parse an attribute data for a Foundation.ExportAttribute.
- Loading branch information
1 parent
05a3831
commit e28dd68
Showing
4 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/rgen/Microsoft.Macios.Transformer.Tests/DataModel/ExportDataTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.Macios.Transformer.Attributes; | ||
using Xamarin.Tests; | ||
using Xamarin.Utils; | ||
using Microsoft.Macios.Generator.Extensions; | ||
using ObjCRuntime; | ||
|
||
namespace Microsoft.Macios.Transformer.Tests.DataModel; | ||
|
||
public class ExportDataTests : BaseTransformerTestClass { | ||
|
||
|
||
class TestDataTryCreate : IEnumerable<object []> { | ||
public IEnumerator<object []> GetEnumerator () | ||
{ | ||
const string selectorOnly = @" | ||
using System; | ||
using Foundation; | ||
using ObjCRuntime; | ||
using UIKit; | ||
namespace Test; | ||
[NoTV] | ||
[MacCatalyst (13, 1)] | ||
[DisableDefaultCtor] | ||
[Abstract] | ||
[BaseType (typeof (NSObject))] | ||
interface UIFeedbackGenerator : UIInteraction { | ||
[Export (""prepare"")] | ||
void Prepare (); | ||
} | ||
"; | ||
yield return [(Source: selectorOnly, Path: "/some/random/path.cs"), new ExportData (selector: "prepare")]; | ||
|
||
const string selectorWithArgumentSemantic = @" | ||
using System; | ||
using Foundation; | ||
using ObjCRuntime; | ||
using UIKit; | ||
namespace Test; | ||
[NoTV] | ||
[MacCatalyst (13, 1)] | ||
[DisableDefaultCtor] | ||
[Abstract] | ||
[BaseType (typeof (NSObject))] | ||
interface UIFeedbackGenerator : UIInteraction { | ||
[Export (""prepare"", ArgumentSemantic.Retain)] | ||
void Prepare (); | ||
} | ||
"; | ||
yield return [(Source: selectorWithArgumentSemantic, Path: "/some/random/path.cs"), new ExportData (selector: "prepare", argumentSemantic: ArgumentSemantic.Retain)]; | ||
|
||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator () => GetEnumerator (); | ||
} | ||
|
||
[Theory] | ||
[AllSupportedPlatformsClassData<TestDataTryCreate>] | ||
public void TryeCreateTests (ApplePlatform platform, (string Source, string Path) source, ExportData expectedData) | ||
{ | ||
// create a compilation used to create the transformer | ||
var compilation = CreateCompilation (platform, sources: source); | ||
var syntaxTree = compilation.SyntaxTrees.FirstOrDefault (); | ||
Assert.NotNull (syntaxTree); | ||
|
||
var semanticModel = compilation.GetSemanticModel (syntaxTree); | ||
Assert.NotNull (semanticModel); | ||
|
||
var declaration = syntaxTree.GetRoot () | ||
.DescendantNodes ().OfType<MethodDeclarationSyntax> () | ||
.FirstOrDefault (); | ||
Assert.NotNull (declaration); | ||
|
||
var symbol = semanticModel.GetDeclaredSymbol (declaration); | ||
Assert.NotNull (symbol); | ||
var exportData = symbol.GetAttribute<ExportData> (AttributesNames.ExportAttribute, ExportData.TryParse); | ||
Assert.Equal (expectedData, exportData); | ||
} | ||
} |