Skip to content

Commit cd99e2f

Browse files
committed
Added more tests
1 parent 1ba0ce3 commit cd99e2f

File tree

1 file changed

+120
-3
lines changed

1 file changed

+120
-3
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1514UnitTests.cs

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,64 @@ public class TestClass
11861186
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
11871187
}
11881188

1189+
[Fact]
1190+
public async Task TestClassInNamespaceAsync()
1191+
{
1192+
var testCode = @"
1193+
namespace TestNamespace
1194+
{
1195+
/// <summary>
1196+
/// X.
1197+
/// </summary>
1198+
public class TestClass
1199+
{
1200+
}
1201+
}
1202+
";
1203+
1204+
var expected = DiagnosticResult.EmptyDiagnosticResults;
1205+
1206+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1207+
}
1208+
1209+
[Fact]
1210+
public async Task TestClassInNamespaceWithCommentAsync()
1211+
{
1212+
var testCode = @"
1213+
namespace TestNamespace
1214+
{
1215+
// Normal comment
1216+
{|#0:///|} <summary>
1217+
/// X.
1218+
/// </summary>
1219+
public class TestClass
1220+
{
1221+
}
1222+
}
1223+
";
1224+
1225+
var fixedCode = @"
1226+
namespace TestNamespace
1227+
{
1228+
// Normal comment
1229+
1230+
/// <summary>
1231+
/// X.
1232+
/// </summary>
1233+
public class TestClass
1234+
{
1235+
}
1236+
}
1237+
";
1238+
1239+
var expected = new[]
1240+
{
1241+
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
1242+
};
1243+
1244+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
1245+
}
1246+
11891247
[Fact]
11901248
public async Task TestClassInGlobalNamespaceWithCommentAsync()
11911249
{
@@ -1197,14 +1255,25 @@ public async Task TestClassInGlobalNamespaceWithCommentAsync()
11971255
public class TestClass
11981256
{
11991257
}
1258+
";
1259+
1260+
var fixedCode = @"
1261+
// Normal comment
1262+
1263+
/// <summary>
1264+
/// X.
1265+
/// </summary>
1266+
public class TestClass
1267+
{
1268+
}
12001269
";
12011270

12021271
var expected = new[]
12031272
{
12041273
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
12051274
};
12061275

1207-
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1276+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
12081277
}
12091278

12101279
[Fact]
@@ -1219,14 +1288,62 @@ public async Task TestClassInGlobalNamespaceWithPreprocessorDirectiveAsync()
12191288
public class TestClass
12201289
{
12211290
}
1291+
";
1292+
1293+
var fixedCode = @"
1294+
#if DEBUG
1295+
#endif
1296+
1297+
/// <summary>
1298+
/// X.
1299+
/// </summary>
1300+
public class TestClass
1301+
{
1302+
}
12221303
";
12231304

12241305
var expected = new[]
12251306
{
1226-
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
1307+
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
12271308
};
12281309

1229-
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1310+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
1311+
}
1312+
1313+
[Fact]
1314+
public async Task TestClassInGlobalNamespaceWithMultilineCommentAsync()
1315+
{
1316+
var testCode = @"
1317+
/* Normal
1318+
* multiline
1319+
* comment */
1320+
{|#0:///|} <summary>
1321+
/// X.
1322+
/// </summary>
1323+
public class TestClass
1324+
{
1325+
}
1326+
";
1327+
1328+
var fixedCode = @"
1329+
/* Normal
1330+
* multiline
1331+
* comment */
1332+
1333+
/// <summary>
1334+
/// X.
1335+
/// </summary>
1336+
public class TestClass
1337+
{
1338+
}
1339+
";
1340+
1341+
var expected = new[]
1342+
{
1343+
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
1344+
};
1345+
1346+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
12301347
}
12311348
}
12321349
}

0 commit comments

Comments
 (0)