Skip to content

Commit ab114e8

Browse files
Switch \n and \r\n to Environment.NewLine
1 parent 5a8edff commit ab114e8

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class AAttribute : Attribute
120120
}
121121
}";
122122

123-
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(12, 6));
123+
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(12, 6));
124124
}
125125

126126
[TestMethod]
@@ -146,7 +146,7 @@ static void Main()
146146
}
147147
}
148148
}";
149-
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(15, 13));
149+
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(15, 13));
150150
}
151151

152152
[TestMethod]
@@ -172,7 +172,7 @@ static void Main()
172172
}
173173
}
174174
}";
175-
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(13, 13));
175+
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(13, 13));
176176
}
177177

178178
[TestMethod]
@@ -200,7 +200,7 @@ static void Main()
200200
int Prop {get;set;}
201201
}
202202
}";
203-
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(19, 13));
203+
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(19, 13));
204204
}
205205

206206
[TestMethod]
@@ -221,7 +221,7 @@ [A]static void Main()
221221
}
222222
}
223223
}";
224-
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(11, 10));
224+
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(11, 10));
225225
}
226226

227227
[TestMethod]
@@ -242,7 +242,7 @@ static void Main()
242242
}
243243
}
244244
}";
245-
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(9, 6));
245+
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(9, 6));
246246
}
247247

248248
[TestMethod]
@@ -265,7 +265,7 @@ static void Main()
265265
[A]int Prop {get;set;}
266266
}
267267
}";
268-
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(15, 10));
268+
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(15, 10));
269269
}
270270

271271
[TestMethod]
@@ -291,7 +291,7 @@ static void Main()
291291
}
292292
}
293293
}";
294-
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(11, 10));
294+
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(11, 10));
295295
}
296296

297297
[TestMethod]

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/DiagnosticVerifier.cs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
4-
/* Unmerged change from project 'IntelliTect.Analyzer.Tests (net6.0)'
5-
Before:
6-
using Microsoft.CodeAnalysis.CSharp;
7-
using Microsoft.CodeAnalysis.Diagnostics;
8-
using Microsoft.VisualStudio.TestTools.UnitTesting;
9-
After:
10-
using Microsoft.Linq;
11-
using System.Text;
12-
using Microsoft.CodeAnalysis;
13-
using Microsoft.CodeAnalysis.CSharp;
14-
*/
153
using System.Linq;
164
using System.Text;
175
using Microsoft.CodeAnalysis;
@@ -117,7 +105,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
117105
{
118106
int expectedCount = expectedResults.Length;
119107
int actualCount = actualResults.Count();
120-
Assert.AreEqual(expectedCount, actualCount, $"Mismatch between number of diagnostics returned, expected \" {expectedCount} \" actual \" {actualCount} \"\r\n\r\nDiagnostics:\r\n{(actualResults.Any() ? FormatDiagnostics(analyzer, actualResults.ToArray()) : "NONE.")}\r\n");
108+
Assert.AreEqual(expectedCount, actualCount, $"Mismatch between number of diagnostics returned, expected \" {expectedCount} \" actual \" {actualCount} \"{Environment.NewLine}{Environment.NewLine}Diagnostics:{Environment.NewLine}{(actualResults.Any() ? FormatDiagnostics(analyzer, actualResults.ToArray()) : "NONE.")}{Environment.NewLine}");
121109

122110
for (int i = 0; i < expectedResults.Length; i++)
123111
{
@@ -128,7 +116,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
128116
{
129117
Assert.AreEqual(actual.Location,
130118
Location.None,
131-
string.Format($"Expected:\nA project diagnostic with No location\nActual:\n{FormatDiagnostics(analyzer, actual)}"));
119+
string.Format($"Expected:{Environment.NewLine}A project diagnostic with No location{Environment.NewLine}Actual:{Environment.NewLine}{FormatDiagnostics(analyzer, actual)}"));
132120
}
133121
else
134122
{
@@ -137,7 +125,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
137125

138126
Assert.AreEqual(additionalLocations.Length,
139127
expected.Locations.Length - 1,
140-
$"Expected {expected.Locations.Length - 1} additional locations but got {additionalLocations.Length} for Diagnostic:\r\n {FormatDiagnostics(analyzer, actual)}\r\n");
128+
$"Expected {expected.Locations.Length - 1} additional locations but got {additionalLocations.Length} for Diagnostic:{Environment.NewLine} {FormatDiagnostics(analyzer, actual)}{Environment.NewLine}");
141129

142130
for (int j = 0; j < additionalLocations.Length; ++j)
143131
{
@@ -146,15 +134,15 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
146134
}
147135
Assert.AreEqual(actual.Id,
148136
expected.Id,
149-
$"Expected diagnostic id to be \"{expected.Id}\" was \"{actual.Id}\"\r\n\r\nDiagnostic:\r\n {FormatDiagnostics(analyzer, actual)}\r\n");
137+
$"Expected diagnostic id to be \"{expected.Id}\" was \"{actual.Id}\"{Environment.NewLine}{Environment.NewLine}Diagnostic:{Environment.NewLine} {FormatDiagnostics(analyzer, actual)}{Environment.NewLine}");
150138

151139
Assert.AreEqual(actual.Severity,
152140
expected.Severity,
153-
$"Expected diagnostic severity to be \"{expected.Severity}\" was \"{actual.Severity}\"\r\n\r\nDiagnostic:\r\n {FormatDiagnostics(analyzer, actual)}\r\n");
141+
$"Expected diagnostic severity to be \"{expected.Severity}\" was \"{actual.Severity}\"{Environment.NewLine}{Environment.NewLine}Diagnostic:{Environment.NewLine} {FormatDiagnostics(analyzer, actual)}{Environment.NewLine}");
154142

155143
Assert.AreEqual(actual.GetMessage(),
156144
expected.Message,
157-
"Expected diagnostic message to be \"{expected.Message}\" was \"{actual.GetMessage()}\"\r\n\r\nDiagnostic:\r\n {FormatDiagnostics(analyzer, actual)}\r\n");
145+
$"Expected diagnostic message to be \"{expected.Message}\" was \"{actual.GetMessage()}\"{Environment.NewLine}{Environment.NewLine}Diagnostic:{Environment.NewLine} {FormatDiagnostics(analyzer, actual)}{Environment.NewLine}");
158146
}
159147
}
160148

@@ -172,8 +160,7 @@ private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagno
172160
Assert.IsTrue(actualSpan.Path == expected.Path || (actualSpan.Path != null
173161
&& actualSpan.Path.Contains("Test0.", StringComparison.Ordinal)
174162
&& expected.Path.Contains("Test.", StringComparison.Ordinal)),
175-
string.Format("Expected diagnostic to be in file \"{0}\" was actually in file \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
176-
expected.Path, actualSpan.Path, FormatDiagnostics(analyzer, diagnostic)));
163+
$"Expected diagnostic to be in file \"{expected.Path}\" was actually in file \"{actualSpan.Path}\"{Environment.NewLine}{Environment.NewLine}Diagnostic:{Environment.NewLine} {FormatDiagnostics(analyzer, diagnostic)}{Environment.NewLine}");
177164

178165
Microsoft.CodeAnalysis.Text.LinePosition actualLinePosition = actualSpan.StartLinePosition;
179166

@@ -182,15 +169,15 @@ private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagno
182169
{
183170
Assert.AreEqual(actualLinePosition.Line + 1,
184171
expected.Line,
185-
$"Expected diagnostic to be on line \"{expected.Line}\" was actually on line \"{actualLinePosition.Line + 1}\"\r\n\r\nDiagnostic:\r\n {FormatDiagnostics(analyzer, diagnostic)}\r\n");
172+
$"Expected diagnostic to be on line \"{expected.Line}\" was actually on line \"{actualLinePosition.Line + 1}\"{Environment.NewLine}{Environment.NewLine}Diagnostic:{Environment.NewLine} {FormatDiagnostics(analyzer, diagnostic)}{Environment.NewLine}");
186173
}
187174

188175
// Only check column position if there is an actual column position in the real diagnostic
189176
if (actualLinePosition.Character > 0)
190177
{
191178
Assert.AreEqual(actualLinePosition.Character + 1,
192179
expected.Column,
193-
"Expected diagnostic to start at column \"{expected.Column}\" was actually at column \"{actualLinePosition.Character + 1}\"\r\n\r\nDiagnostic:\r\n {FormatDiagnostics(analyzer, diagnostic)}\r\n");
180+
$"Expected diagnostic to start at column \"{expected.Column}\" was actually at column \"{actualLinePosition.Character + 1}\"{Environment.NewLine}{Environment.NewLine}Diagnostic:{Environment.NewLine} {FormatDiagnostics(analyzer, diagnostic)}{Environment.NewLine}");
194181
}
195182
}
196183
#endregion
@@ -224,7 +211,7 @@ private static string FormatDiagnostics(DiagnosticAnalyzer analyzer, params Diag
224211
else
225212
{
226213
Assert.IsTrue(location.IsInSource,
227-
$"Test base does not currently handle diagnostics in metadata locations. Diagnostic in metadata: {diagnostics[i]}\r\n");
214+
$"Test base does not currently handle diagnostics in metadata locations. Diagnostic in metadata: {diagnostics[i]}{Environment.NewLine}");
228215

229216
string resultMethodName = diagnostics[i].Location.SourceTree.FilePath.EndsWith(".cs", StringComparison.Ordinal) ? "GetCSharpResultAt" : "GetBasicResultAt";
230217
Microsoft.CodeAnalysis.Text.LinePosition linePosition = diagnostics[i].Location.GetLineSpan().StartLinePosition;

0 commit comments

Comments
 (0)