-
Notifications
You must be signed in to change notification settings - Fork 231
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
SyntaxNodeExtensions: increase GetBody coverage #8639
base: master
Are you sure you want to change the base?
Conversation
analyzers/tests/SonarAnalyzer.Test/Extensions/SyntaxNodeExtensionsTest.cs
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Extensions/SyntaxNodeExtensionsTest.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Extensions/SyntaxNodeExtensionsTest.cs
Outdated
Show resolved
Hide resolved
public void GetBody_PropertyDeclaration_SingleAccessor() | ||
{ | ||
var code = "class AClass { int AProperty { get => 42; } }"; | ||
ExtensionsCS.GetBody(CSharpSyntaxTree.ParseText(code).Single<PropertyDeclarationSyntax>()).Should().BeNull(); |
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.
ExtensionsCS.GetBody(CSharpSyntaxTree.ParseText(code).Single<T>
is repeated very often. Extract a helper
BlockSyntax ParseForBlockSyntax<T>(string code) where T: CSharpSyntaxNode
=> ExtensionsCS.GetBody(CSharpSyntaxTree.ParseText(code).Single<T>());
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
@@ -230,7 +281,7 @@ public void CreateCfg_FieldInitializerWithoutOperation_ReturnsCfg_CS() | |||
const string code = """ | |||
public class Sample | |||
{ | |||
private string field = null!; // null! itself doens't have operation, and we can still generate CFG for it from the equals clause | |||
private string field = null!; // null! itself doesn't have operation, and we can still generate CFG for it from the equals clause |
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.
have an operation
Cover
SyntaxNodeExtensions.GetBody
, introduced in #8584 but not covered.