-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Adding Unit tests for IfStatement #18060
Conversation
private void M() | ||
/*<bind>*/{ | ||
bool condition=false; | ||
if (true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably make the test more targeted by just binding the if statement instead of entire method body.
IInvocationExpression (static void System.Console.WriteLine(System.String value)) (OperationKind.InvocationExpression, Type: System.Void) | ||
IArgument (Matching Parameter: value) (OperationKind.Argument) | ||
ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: Result1) | ||
IIfStatement (OperationKind.IfStatement) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be the case where if... elseif.. else
has been converted into if... else (if... else)
due to lowering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does IOperation allow to represent this in a different form? #Closed
Partial Public Class IOperationTests | ||
Inherits SemanticModelTestBase | ||
|
||
<Fact(), WorkItem(17601, "https://github.com/dotnet/roslyn/issues/17601")> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also port the C# tests where you have a constant expression for the if condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes , will do once we figure out the mutiblock issue
|
||
VerifyOperationTreeForTest(Of SingleLineIfStatementSyntax)(source, expectedOperationTree) | ||
End Sub | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please port the test for ElseIf
from C# to VB.
As a general guideline, it is recommended that you try to port all the C# tests to VB or vice versa for equivalent features.
|
||
namespace Microsoft.CodeAnalysis.CSharp.UnitTests | ||
{ | ||
public partial class IOperationTests : SemanticModelTestBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOperationTests [](start = 25, length = 15)
Consider also testing scenarios:
- with embedded statements that are not blocks;
- with conditions declaring variables (out or pattern);
- with embedded statements declaring variables (out or pattern). #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jinujoseph I still don't see the unit test with constant if condition ported over. Apart from that, LGTM.
thanks manish, i added few constant checks |
private void M() | ||
{ | ||
bool condition=false; | ||
/*<bind>*/if (true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you test whether binding all nodes belong to if statement works? like condition, body and etc.
"; | ||
string expectedOperationTree = @" | ||
IIfStatement (OperationKind.IfStatement) | ||
Condition: IOperation: (OperationKind.None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not supported C# 7 feature yet I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes , we have a workitem tracking that
seems fine to me, but @mavasani is more expert on language than me so, you probably want him to take a look. |
@AlekseyTs tagging you to relook this. |
IExpressionStatement (OperationKind.ExpressionStatement) | ||
IInvocationExpression (static void System.Console.WriteLine(System.String value)) (OperationKind.InvocationExpression, Type: System.Void) | ||
IArgument (Matching Parameter: value) (OperationKind.Argument) | ||
IOperation: (OperationKind.None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOperation: (OperationKind.None) [](start = 8, length = 33)
It looks like string interpolations are not supported, please create an issue to track that, unless we already have one. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filed issue #18300
IArgument (Matching Parameter: s) (OperationKind.Argument) | ||
ILocalReferenceExpression: s (OperationKind.LocalReferenceExpression, Type: System.String) | ||
IArgument (Matching Parameter: result) (OperationKind.Argument) | ||
ILocalReferenceExpression: i (OperationKind.LocalReferenceExpression, Type: System.Int32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ILocalReferenceExpression: i (OperationKind.LocalReferenceExpression, Type: System.Int32) [](start = 8, length = 89)
Design issue - should we have a special node for this declaration? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filed issue #18303
private void M() | ||
{ | ||
/*<bind>*/if (true) | ||
A(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A(); [](start = 12, length = 4)
Please add a test where embedded statements declare out or pattern variables. #Closed
returnValue = count | ||
End If" | ||
returnValue = count | ||
End If |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code intentional? #Closed
Dim n As Integer = 7 | ||
If (m > 20) Then'BIND:"If (m > 20) Then" | ||
Console.WriteLine("Result1") | ||
ElseIf (n > 10) Then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ElseIf (n > 10) Then [](start = 8, length = 20)
Consider testing similar scenario for line if. #Closed
Done with review pass. #Closed |
Thanks @AlekseyTs , have addressed the feedback |
|
||
VerifyOperationTreeForTest(Of SingleLineIfStatementSyntax)(source, expectedOperationTree) | ||
End Sub | ||
<Fact(), WorkItem(17601, "https://github.com/dotnet/roslyn/issues/17601")> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Fact(), WorkItem(17601, "https://github.com/dotnet/roslyn/issues/17601")> [](start = 8, length = 74)
Please add an empty line between the methods. #Closed
retest windows_eta_open_prtest please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
eta failure due to #18250 |
Fixes #17601 This adds couple of unit tests for Ifstatements
On the VB side i don't get Ioperation for IfStatment, There seems to be an ioperation for SingleLineIfStatement and MultiLineIfBlock.
Issues discovered
#18300
#18303
Tagging @dotnet/analyzer-ioperation @AlekseyTs for review.