提交 2126aa1b 编写于 作者: G Gen Lu

Add IReturnStatement tests for C#

上级 1df2455a
......@@ -67,6 +67,7 @@
<Compile Include="IOperation\IOperationTests_IFieldReferenceExpression.cs" />
<Compile Include="IOperation\IOperationTests_IObjectCreationExpression.cs" />
<Compile Include="IOperation\IOperationTests_IParameterReferenceExpression.cs" />
<Compile Include="IOperation\IOperationTests_IReturnStatement.cs" />
<Compile Include="IOperation\IOperationTests_ISymbolInitializer.cs" />
<Compile Include="IOperation\IOperationTests_InvalidExpression.cs" />
<Compile Include="IOperation\IOperationTests_InvalidStatement.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Semantics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public partial class IOperationTests : SemanticModelTestBase
{
[Fact]
public void SimpleReturnFromRegularMethod()
{
string source = @"
class C
{
static void Method()
{
/*<bind>*/return;/*</bind>*/
}
}
";
string expectedOperationTree = @"IReturnStatement (OperationKind.ReturnStatement) (Syntax: 'return;')
";
var expectedDiagnostics = DiagnosticDescription.None;
VerifyOperationTreeAndDiagnosticsForTest<ReturnStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
[Fact]
public void ReturnWithValueFromRegularMethod()
{
string source = @"
class C
{
static bool Method()
{
/*<bind>*/return true;/*</bind>*/
}
}
";
string expectedOperationTree = @"IReturnStatement (OperationKind.ReturnStatement) (Syntax: 'return true;')
ILiteralExpression (OperationKind.LiteralExpression, Type: System.Boolean, Constant: True) (Syntax: 'true')
";
var expectedDiagnostics = DiagnosticDescription.None;
VerifyOperationTreeAndDiagnosticsForTest<ReturnStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
[Fact]
public void YieldReturnFromRegularMethod()
{
string source = @"
using System.Collections.Generic;
class C
{
static IEnumerable<int> Method()
{
/*<bind>*/yield return 0;/*</bind>*/
}
}
";
string expectedOperationTree = @"IReturnStatement (OperationKind.YieldReturnStatement) (Syntax: 'yield return 0;')
ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')";
var expectedDiagnostics = DiagnosticDescription.None;
VerifyOperationTreeAndDiagnosticsForTest<YieldStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
[Fact]
public void YieldBreakFromRegularMethod()
{
string source = @"
using System.Collections.Generic;
class C
{
static IEnumerable<int> Method()
{
yield return 0;
/*<bind>*/yield break;/*</bind>*/
}
}
";
string expectedOperationTree = @"IReturnStatement (OperationKind.YieldBreakStatement) (Syntax: 'yield break;')";
var expectedDiagnostics = DiagnosticDescription.None;
VerifyOperationTreeAndDiagnosticsForTest<YieldStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
}
}
\ No newline at end of file
......@@ -420,7 +420,7 @@ public override void VisitBranchStatement(IBranchStatement operation)
public override void VisitYieldBreakStatement(IReturnStatement operation)
{
LogString("YieldBreakStatement");
LogString(nameof(IReturnStatement));
LogCommonPropertiesAndNewLine(operation);
base.VisitYieldBreakStatement(operation);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册