Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 3cd238b

Browse files
committed
Test for multiple namespaces
Add a test that verifies we don't do any moves when there are multiple namespaces in the file. There is no way to safely move a using in this case using only syntax information. This move effectively adds new namespaces at a global level which used to be local to a namespace. This means extension methods and types from this namespace will affect compilation in all namespaces. This can introduce both compilation errors or even worse silently change overload resolution in the file.
1 parent 5a43307 commit 3cd238b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Microsoft.DotNet.CodeFormatting.Tests/Rules/UsingLocationRuleTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@ class C1 { }
3636
Verify(source, expected);
3737
}
3838

39+
/// <summary>
40+
/// There is no safe way to move a using outside a namespace when there are
41+
/// multiple namespaces. The rule should punt on this scenario.
42+
/// </summary>
43+
[Fact]
44+
public void SimpleMoveMultipleNamespaces()
45+
{
46+
var source = @"
47+
using NS1;
48+
namespace NS2
49+
{
50+
using NS3;
51+
class C1 { }
52+
}
53+
54+
namespace NS3
55+
{
56+
using NS4;
57+
class C1 { }
58+
}";
59+
60+
Verify(source, source);
61+
}
62+
3963
[Fact]
4064
public void SimpleMoveWithComment()
4165
{

0 commit comments

Comments
 (0)