-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use !! in AddParameterCheck refactoring #57934
Changes from 1 commit
0b0ea12
2cc5e6c
0c54df5
08ce98f
e050285
828a71d
9053d0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,33 @@ public async Task TestEmptyFile() | |
|
||
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)] | ||
public async Task TestSimpleReferenceType() | ||
{ | ||
await new VerifyCS.Test | ||
{ | ||
LanguageVersion = LanguageVersion.Preview, | ||
TestCode = @" | ||
using System; | ||
|
||
class C | ||
{ | ||
public C([||]string s) | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
} | ||
}", | ||
FixedCode = @" | ||
using System; | ||
|
||
class C | ||
{ | ||
public C(string s!!) | ||
{ | ||
} | ||
}" | ||
}.RunAsync(); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)] | ||
public async Task TestSimpleReferenceType_CSharp8() | ||
{ | ||
await VerifyCS.VerifyRefactoringAsync( | ||
@" | ||
|
@@ -210,6 +237,28 @@ public async Task TestNotOnPartialMethodDefinition1() | |
var code = @" | ||
using System; | ||
|
||
partial class C | ||
{ | ||
partial void M([||]string s); | ||
|
||
partial void M(string s) | ||
{ | ||
} | ||
}"; | ||
await new VerifyCS.Test | ||
{ | ||
LanguageVersion = LanguageVersion.Preview, | ||
TestCode = code, | ||
FixedCode = code | ||
}.RunAsync(); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)] | ||
public async Task TestNotOnPartialMethodDefinition1_CSharp8() | ||
{ | ||
var code = @" | ||
using System; | ||
|
||
partial class C | ||
{ | ||
partial void M([||]string s); | ||
|
@@ -249,6 +298,28 @@ public async Task TestNotOnPartialMethodDefinition2() | |
var code = @" | ||
using System; | ||
|
||
partial class C | ||
{ | ||
partial void M(string s) | ||
{ | ||
} | ||
|
||
partial void M([||]string s); | ||
}"; | ||
await new VerifyCS.Test | ||
{ | ||
LanguageVersion = LanguageVersion.Preview, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the cases where the test is the same other than changing language version, consider using a xUnit theory instead of a fact to avoid all the extra duplication. |
||
TestCode = code, | ||
FixedCode = code | ||
}.RunAsync(); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)] | ||
public async Task TestNotOnPartialMethodDefinition2_CSharp8() | ||
{ | ||
var code = @" | ||
using System; | ||
|
||
partial class C | ||
{ | ||
partial void M(string s) | ||
|
@@ -284,6 +355,37 @@ public partial void M(string s) | |
|
||
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)] | ||
public async Task TestOnPartialMethodImplementation1() | ||
{ | ||
await new VerifyCS.Test | ||
{ | ||
LanguageVersion = LanguageVersion.Preview, | ||
TestCode = @" | ||
using System; | ||
|
||
partial class C | ||
{ | ||
partial void M(string s); | ||
|
||
partial void M([||]string s) | ||
{ | ||
} | ||
}", | ||
FixedCode = @" | ||
using System; | ||
|
||
partial class C | ||
{ | ||
partial void M(string s); | ||
|
||
partial void M(string s!!) | ||
{ | ||
} | ||
}" | ||
}.RunAsync(); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)] | ||
public async Task TestOnPartialMethodImplementation1_CSharp8() | ||
{ | ||
await VerifyCS.VerifyRefactoringAsync( | ||
@" | ||
|
@@ -351,6 +453,37 @@ public partial void M(string s) | |
|
||
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)] | ||
public async Task TestOnPartialMethodImplementation2() | ||
{ | ||
await new VerifyCS.Test | ||
{ | ||
LanguageVersion = LanguageVersion.Preview, | ||
TestCode = @" | ||
using System; | ||
|
||
partial class C | ||
{ | ||
partial void M([||]string s) | ||
{ | ||
} | ||
|
||
partial void M(string s); | ||
}", | ||
FixedCode = @" | ||
using System; | ||
|
||
partial class C | ||
{ | ||
partial void M(string s!!) | ||
{ | ||
} | ||
|
||
partial void M(string s); | ||
}" | ||
}.RunAsync(); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)] | ||
public async Task TestOnPartialMethodImplementation2_CSharp9() | ||
{ | ||
await VerifyCS.VerifyRefactoringAsync( | ||
@" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5775,6 +5775,28 @@ static object F() | |
await AssertFormatAsync(expectedCode, code); | ||
} | ||
|
||
[Fact] | ||
[Trait(Traits.Feature, Traits.Features.Formatting)] | ||
public async Task SpacingInNullCheckedParameter() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to also test/handle the syntax normalize (SyntaxNormalizerTests.cs) which generally needs similar fixing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't see a similar test in SyntaxNormalizerTests for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wasn't clear to me what needs to be done here. |
||
{ | ||
var code = | ||
@"class C | ||
{ | ||
static object F(string s !!) | ||
{ | ||
} | ||
}"; | ||
var expectedCode = | ||
@"class C | ||
{ | ||
static object F(string s!!) | ||
{ | ||
} | ||
}"; | ||
|
||
await AssertFormatAsync(expectedCode, code); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(545335, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545335")] | ||
[Trait(Traits.Feature, Traits.Features.Formatting)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -478,6 +478,13 @@ SyntaxKind.ImplicitObjectCreationExpression or | |
return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine); | ||
} | ||
|
||
// paramName!! | ||
if (currentToken.Kind() == SyntaxKind.ExclamationExclamationToken && | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
currentToken.Parent.IsKind(SyntaxKind.Parameter)) | ||
{ | ||
return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider also adding a test to |
||
|
||
// pointer case for regular pointers | ||
if (currentToken.Kind() == SyntaxKind.AsteriskToken && currentToken.Parent is PointerTypeSyntax) | ||
{ | ||
|
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.
Why is this
Preview
and not the newCSharpNext
? I understand both are equivalent, butCSharpNext
should help updating this to CSharp11 when released.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.
It's an oversight. Thanks for catching it.