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

Commit 045b5f9

Browse files
committed
Add some regression tests
1 parent e72bb35 commit 045b5f9

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

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

+64
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,69 @@ public void RequiredRuntimeAttribute()
357357
ToggleRule(UsingLocationRule.Name, enabled: true);
358358
Verify(source, expected);
359359
}
360+
361+
[Fact]
362+
public void Issue268()
363+
{
364+
var text = @"
365+
using System.Collections.Generic;
366+
367+
internal class C
368+
{
369+
private void M<TValue>()
370+
{
371+
Dictionary<string, Stack<TValue>> dict = new Dictionary<string, Stack<TValue>>();
372+
dict.TryGetValue(""key"", out Stack<TValue> stack);
373+
}
374+
}";
375+
376+
Verify(text, expected:text);
377+
}
378+
379+
[Fact]
380+
public void Issue272()
381+
{
382+
var text = @"
383+
using System.Collections.Generic;
384+
385+
internal class C
386+
{
387+
388+
private object myVariable;
389+
390+
private void M()
391+
{
392+
Dictionary<string, object> dict = new Dictionary<string, object>()
393+
{
394+
{ ""key"", new object() }
395+
};
396+
397+
dict.TryGetValue(""key"", out object myVariable);
398+
399+
this.myVariable = myVariable;
400+
}
401+
}";
402+
var expected = @"
403+
using System.Collections.Generic;
404+
405+
internal class C
406+
{
407+
private object _myVariable;
408+
409+
private void M()
410+
{
411+
Dictionary<string, object> dict = new Dictionary<string, object>()
412+
{
413+
{ ""key"", new object() }
414+
};
415+
416+
dict.TryGetValue(""key"", out object myVariable);
417+
418+
_myVariable = myVariable;
419+
}
420+
}";
421+
422+
Verify(text, expected);
423+
}
360424
}
361425
}

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

+52
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,58 @@ int M(C p)
211211

212212
Verify(text, expected);
213213
}
214+
215+
[Fact]
216+
public void Issue258()
217+
{
218+
var text = @"
219+
class C
220+
{
221+
private (string name, string value) myTuple;
222+
}
223+
";
224+
var expected = @"
225+
class C
226+
{
227+
private (string name, string value) _myTuple;
228+
}
229+
";
230+
231+
Verify(text, expected, runFormatter: false);
232+
}
233+
234+
[Fact]
235+
public void Issue241()
236+
{
237+
var text = @"
238+
class C
239+
{
240+
private bool streamObjects;
241+
242+
/// <summary>
243+
/// A collection in which objects that are written using the WriteError
244+
/// method are accumulated if <see cref=""streamObjects"" /> is false.
245+
/// </summary>
246+
private List<string> errors;
247+
248+
}
249+
";
250+
var expected = @"
251+
class C
252+
{
253+
private bool _streamObjects;
254+
255+
/// <summary>
256+
/// A collection in which objects that are written using the WriteError
257+
/// method are accumulated if <see cref=""_streamObjects"" /> is false.
258+
/// </summary>
259+
private List<string> _errors;
260+
261+
}
262+
";
263+
264+
Verify(text, expected, runFormatter: false);
265+
}
214266
}
215267

216268
public sealed class VisualBasicFields : PrivateFieldNamingRuleTests

0 commit comments

Comments
 (0)