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

Commit 9a28bc1

Browse files
committed
Regression test for private field rename
Added a regression test to ensure that private fields used off of a non-this instance are renamed correctly during a field rename. closes #69
1 parent 401149c commit 9a28bc1

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,40 @@ class C
146146

147147
Verify(text, expected, runFormatter: false);
148148
}
149+
150+
/// <summary>
151+
/// Ensure that Roslyn properly renames private fields when accessed through a non-this
152+
/// instance within the same type.
153+
/// </summary>
154+
[Fact]
155+
public void Issue69()
156+
{
157+
var text = @"
158+
class C
159+
{
160+
int field;
161+
162+
int M(C p)
163+
{
164+
int x = p.field;
165+
return x;
166+
}
167+
}";
168+
169+
var expected = @"
170+
class C
171+
{
172+
int _field;
173+
174+
int M(C p)
175+
{
176+
int x = p._field;
177+
return x;
178+
}
179+
}";
180+
181+
Verify(text, expected);
182+
}
149183
}
150184

151185
private sealed class VisualBasicFields : PrivateFieldNamingRuleTests
@@ -221,6 +255,32 @@ End Sub
221255

222256
Verify(text, expected, runFormatter: false, languageName: LanguageNames.VisualBasic);
223257
}
258+
259+
[Fact]
260+
public void Issue69()
261+
{
262+
var text = @"
263+
Class C1
264+
Private Field As Integer
265+
266+
Function M(p As C1) As Integer
267+
Dim x = p.Field
268+
Return x
269+
End Function
270+
End Class";
271+
272+
var expected = @"
273+
Class C1
274+
Private _field As Integer
275+
276+
Function M(p As C1) As Integer
277+
Dim x = p._field
278+
Return x
279+
End Function
280+
End Class";
281+
282+
Verify(text, expected, languageName: LanguageNames.VisualBasic);
283+
}
224284
}
225285
}
226286
}

0 commit comments

Comments
 (0)