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

Fix file scoped namespace rude edits #55178

Merged
merged 1 commit into from
Jul 28, 2021
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 @@ -5204,8 +5204,8 @@ public void Namespace_Insert()

edits.VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Insert, "namespace C", FeaturesResources.namespace_));

}

[Fact]
public void Namespace_InsertNested()
{
Expand All @@ -5222,7 +5222,7 @@ public void Namespace_InsertNested()
}

[Fact]
public void NamespaceDelete()
public void Namespace_DeleteNested()
{
var src1 = @"namespace C { namespace D { } }";
var src2 = @"namespace C { }";
Expand All @@ -5237,7 +5237,7 @@ public void NamespaceDelete()
}

[Fact]
public void NamespaceMove1()
public void Namespace_Move()
{
var src1 = @"namespace C { namespace D { } }";
var src2 = @"namespace C { } namespace D { }";
Expand All @@ -5252,7 +5252,7 @@ public void NamespaceMove1()
}

[Fact]
public void NamespaceReorder1()
public void Namespace_Reorder1()
{
var src1 = @"namespace C { namespace D { } class T { } namespace E { } }";
var src2 = @"namespace C { namespace E { } class T { } namespace D { } }";
Expand All @@ -5267,7 +5267,7 @@ public void NamespaceReorder1()
}

[Fact]
public void NamespaceReorder2()
public void Namespace_Reorder2()
{
var src1 = @"namespace C { namespace D1 { } namespace D2 { } namespace D3 { } class T { } namespace E { } }";
var src2 = @"namespace C { namespace E { } class T { } namespace D1 { } namespace D2 { } namespace D3 { } }";
Expand All @@ -5281,6 +5281,36 @@ public void NamespaceReorder2()
edits.VerifyRudeDiagnostics();
}

[Fact]
public void Namespace_FileScoped_Insert()
{
var src1 = @"";
var src2 = @"namespace C;";

var edits = GetTopEdits(src1, src2);

edits.VerifyEdits(
"Insert [namespace C;]@0");

edits.VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Insert, "namespace C", FeaturesResources.namespace_));
}

[Fact]
public void Namespace_FileScoped_Delete()
{
var src1 = @"namespace C;";
var src2 = @"";

var edits = GetTopEdits(src1, src2);

edits.VerifyEdits(
"Delete [namespace C;]@0");

edits.VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Delete, null, FeaturesResources.namespace_));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since file scoped namespaces can't appear with top level code, can't be nested, and can't have multiple in a file, these two tests count as full coverage 😛

#endregion

#region Members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ join newVariable in newVariables on oldVariable.Identifier.Text equals newVariab
SemanticModel model,
CancellationToken cancellationToken)
{
if (node.IsKind(SyntaxKind.UsingDirective, SyntaxKind.NamespaceDeclaration))
if (node.IsKind(SyntaxKind.UsingDirective, SyntaxKind.NamespaceDeclaration, SyntaxKind.FileScopedNamespaceDeclaration))
{
return null;
}
Expand Down Expand Up @@ -1915,6 +1915,7 @@ internal override string GetDisplayName(IMethodSymbol symbol)
return CSharpFeaturesResources.using_directive;

case SyntaxKind.NamespaceDeclaration:
case SyntaxKind.FileScopedNamespaceDeclaration:
return FeaturesResources.namespace_;

case SyntaxKind.ClassDeclaration:
Expand Down