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

Add simple lambda sync generator and test #894

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ private ExpressionSyntax Transform( ExpressionSyntax expr )
.WithExpression( Transform( pattExpr.Expression ) )
.WithPattern( Transform( pattExpr.Pattern ) ),

SimpleLambdaExpressionSyntax lambExpr => lambExpr
.WithModifiers( RemoveAsyncModifier( lambExpr.Modifiers ) )
.WithParameter( Transform( lambExpr.Parameter ) )
.WithExpressionBody( lambExpr.ExpressionBody != null ? Transform( lambExpr.ExpressionBody ) : null ),

_ => UnhandledSyntax( expr )
};

Expand Down Expand Up @@ -314,6 +319,9 @@ private ArgumentListSyntax Transform( ArgumentListSyntax argList )
private ArgumentSyntax Transform( ArgumentSyntax argument )
=> argument.WithExpression( Transform( argument.Expression ) );

private ParameterSyntax Transform( ParameterSyntax parameter )
=> parameter.WithIdentifier(RemoveAsyncSuffix( parameter.Identifier, optional: true ) );

private CatchClauseSyntax Transform( CatchClauseSyntax catchClause ) {
return catchClause
.WithDeclaration( catchClause.Declaration != null ? Transform( catchClause.Declaration ) : null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public void Using() {
Assert.AreEqual( "[Blocking] void Bar() { using( var foo = m_bar.Get( qux )) { return ( this as IBarProvider ).Bars(); }}", actual.Value.ToFullString() );
}

[Test]
public void SimpleLambda() {
var actual = Transform( @"[GenerateSync] async Task BarAsync() { Func<int, Task> bazAsync = async quuxAsync => await fredAsync.Delay( 2*y ); }" );

Assert.IsTrue( actual.Success );
Assert.IsEmpty( actual.Diagnostics );
Assert.AreEqual( "[Blocking] void Bar() { Func<int, Task> baz = quux => fred.Delay( 2*y ); }", actual.Value.ToFullString() );
}

[Test]
public void TryCatch() {
var actual = Transform( @"[GenerateSync]
Expand Down
Loading