Skip to content

Commit

Permalink
Use Assert.Empty (#76862)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Jan 22, 2025
2 parents 390b425 + af41d67 commit 9cab90a
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void TestRemove()
Assert.Equal(1, map.Count);

map = map.Remove("5");
Assert.Equal(0, map.Count);
Assert.Empty(map);
}

[Fact]
Expand Down Expand Up @@ -116,7 +116,7 @@ public void TestPathology()
Assert.Equal(1, map.Count);

map = map.Remove("5");
Assert.Equal(0, map.Count);
Assert.Empty(map);
}

private class PathologicalComparer<T> : IEqualityComparer<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public void PushReverse1()
Assert.Equal(1, stack.Pop());
Assert.Equal(2, stack.Pop());
Assert.Equal(3, stack.Pop());
Assert.Equal(0, stack.Count);
Assert.Empty(stack);
}

[Fact]
public void PushReverse2()
{
var stack = new Stack<int>();
stack.PushReverse(Array.Empty<int>());
Assert.Equal(0, stack.Count);
Assert.Empty(stack);
}

[Fact]
Expand All @@ -41,6 +41,6 @@ public void PushReverse3()
Assert.Equal(1, stack.Pop());
Assert.Equal(2, stack.Pop());
Assert.Equal(3, stack.Pop());
Assert.Equal(0, stack.Count);
Assert.Empty(stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task<MetadataAsSourceFile> GenerateSourceAsync(
// Get an ISymbol corresponding to the metadata name
var compilation = await project.GetRequiredCompilationAsync(CancellationToken.None);
var diagnostics = compilation.GetDiagnostics().ToArray();
Assert.Equal(0, diagnostics.Length);
Assert.Empty(diagnostics);
var symbol = await ResolveSymbolAsync(symbolMetadataName, compilation);
Contract.ThrowIfNull(symbol);

Expand Down Expand Up @@ -172,7 +172,7 @@ public void Dispose()
{
compilation = await this.DefaultProject.GetRequiredCompilationAsync(CancellationToken.None);
var diagnostics = compilation.GetDiagnostics().ToArray();
Assert.Equal(0, diagnostics.Length);
Assert.Empty(diagnostics);
}

foreach (var reference in compilation.References)
Expand Down
8 changes: 4 additions & 4 deletions src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
(Await document.GetSyntaxRootAsync()).FullSpan,
CancellationToken.None)

Assert.Equal(0, fixes.Length)
Assert.Empty(fixes)

' Verify available codefix with a global fixer + a project fixer
' We will use this assembly as a project fixer provider.
Expand All @@ -102,7 +102,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
(Await document.GetSyntaxRootAsync()).FullSpan,
CancellationToken.None)

Assert.Equal(0, fixes.Length)
Assert.Empty(fixes)
End Using
End Function

Expand Down Expand Up @@ -150,7 +150,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
(Await document.GetSyntaxRootAsync()).FullSpan,
CancellationToken.None)

Assert.Equal(0, fixes.Length)
Assert.Empty(fixes)

' Verify no codefix with a global fixer + a project fixer
' We will use this assembly as a project fixer provider.
Expand All @@ -165,7 +165,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
(Await document.GetSyntaxRootAsync()).FullSpan,
CancellationToken.None)

Assert.Equal(0, fixes.Length)
Assert.Empty(fixes)
End Using
End Function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests
includeSuppressedDiagnostics:=False, includeLocalDocumentDiagnostics:=True, includeNonLocalDocumentDiagnostics:=True, CancellationToken.None).Result

If diagnostics Is Nothing Then
Assert.Equal(0, actualDiagnostics.Length)
Assert.Empty(actualDiagnostics)
Else
Dim expectedDiagnostics = GetExpectedDiagnostics(workspace, diagnostics)

Expand Down
14 changes: 7 additions & 7 deletions src/EditorFeatures/Test2/Diagnostics/DiagnosticServiceTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests
project = project.WithCompilationOptions(newCompilationOptions)
document = project.Documents.Single()
diagnostics = Await GetDiagnosticsForSpanAsync(diagnosticService, document, span)
Assert.Equal(0, diagnostics.Length)
Assert.Empty(diagnostics)

Dim changeSeverityDiagOptions = New Dictionary(Of String, ReportDiagnostic)
changeSeverityDiagOptions.Add(workspaceDiagnosticAnalyzer.DiagDescriptor.Id, ReportDiagnostic.Error)
Expand Down Expand Up @@ -350,7 +350,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests

Dim hostAnalyzers = solution.SolutionState.Analyzers
Dim workspaceDescriptors = hostAnalyzers.GetDiagnosticDescriptorsPerReference(diagnosticService.AnalyzerInfoCache)
Assert.Equal(0, workspaceDescriptors.Count)
Assert.Empty(workspaceDescriptors)

Dim descriptors1 = hostAnalyzers.GetDiagnosticDescriptorsPerReference(diagnosticService.AnalyzerInfoCache, p1)
Assert.Equal("XX0001", descriptors1.Single().Value.Single().Id)
Expand Down Expand Up @@ -494,14 +494,14 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests
Dim descriptorsMap = solution.SolutionState.Analyzers.GetDiagnosticDescriptorsPerReference(diagnosticService.AnalyzerInfoCache, project)
Assert.Equal(1, descriptorsMap.Count)
Dim descriptors = descriptorsMap.First().Value
Assert.Equal(0, descriptors.Length)
Assert.Empty(descriptors)

Dim document = project.Documents.Single()

Dim incrementalAnalyzer = diagnosticService.CreateIncrementalAnalyzer(workspace)
Dim diagnostics = Await GetDiagnosticsForDocumentAsync(diagnosticService, document)

Assert.Equal(0, diagnostics.Length)
Assert.Empty(diagnostics)
End Using
End Function

Expand Down Expand Up @@ -534,7 +534,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests
Dim incrementalAnalyzer = diagnosticService.CreateIncrementalAnalyzer(workspace)
Dim root = Await document.GetSyntaxRootAsync().ConfigureAwait(False)
Dim diagnostics = Await GetDiagnosticsForSpanAsync(diagnosticService, document, root.FullSpan)
Assert.Equal(0, diagnostics.Length)
Assert.Empty(diagnostics)

diagnostics = Await diagnosticService.GetDiagnosticsForIdsAsync(
project.Solution, projectId:=Nothing, documentId:=Nothing, diagnosticIds:=Nothing, shouldIncludeAnalyzer:=Nothing,
Expand Down Expand Up @@ -2096,7 +2096,7 @@ class MyClass
Dim document = project.Documents.Single()
Dim diagnostics = Await GetDiagnosticsForDocumentAsync(diagnosticService, document)

Assert.Equal(0, diagnostics.Length)
Assert.Empty(diagnostics)
End Using
End Function

Expand Down Expand Up @@ -2237,7 +2237,7 @@ class C
Dim diagnostics = Await diagnosticService.GetDiagnosticsForIdsAsync(
project.Solution, project.Id, documentId:=Nothing, diagnosticIds:=Nothing, shouldIncludeAnalyzer:=Nothing,
includeSuppressedDiagnostics:=False, includeLocalDocumentDiagnostics:=True, includeNonLocalDocumentDiagnostics:=True, CancellationToken.None)
Assert.Equal(0, diagnostics.Length)
Assert.Empty(diagnostics)
End Using
End Function

Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/TestUtilities/Rename/RenamerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected async Task TestRenameDocument(
}

AssertEx.EqualOrDiff(endDocument.Text, (await updatedDocument.GetTextAsync()).ToString());
Assert.Equal(0, remainingErrors.Count);
Assert.Empty(remainingErrors);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Recommendations
.OrderBy(Function(recommendation) recommendation) _
.ToArray()

Assert.Equal(0, recommendedKeywords.Length)
Assert.Empty(recommendedKeywords)
End Sub

Private Function GetSourceCodeKind(testSource As XElement) As SourceCodeKind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ int G()
string typeName;
var assembly = context.CompileGetLocals(locals, argumentsOnly: false, typeName: out typeName, testData: testData);
Assert.NotNull(assembly);
Assert.Equal(0, assembly.Count);
Assert.Equal(0, locals.Count);
Assert.Empty(assembly);
Assert.Empty(locals);
locals.Free();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static void M()
string typeName;
var assembly = context.CompileGetLocals(locals, argumentsOnly: false, typeName: out typeName, testData: testData);
Assert.NotNull(assembly);
Assert.Equal(0, assembly.Count);
Assert.Equal(0, locals.Count);
Assert.Empty(assembly);
Assert.Empty(locals);
locals.Free();
});
}
Expand Down Expand Up @@ -2491,7 +2491,7 @@ static void M(A a, B b, C c)
Diagnostic(ErrorCode.ERR_NoTypeDef).WithArguments("A", "Comp1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(1, 1)
]);

Assert.Equal(0, locals.Count);
Assert.Empty(locals);
locals.Free();
});
}
Expand Down Expand Up @@ -2535,7 +2535,7 @@ static void M<T>(object o) where T : I
Diagnostic(ErrorCode.ERR_NoTypeDef).WithArguments("I", "Comp1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(1, 1)
]);

Assert.Equal(0, locals.Count);
Assert.Empty(locals);
locals.Free();
});
}
Expand Down Expand Up @@ -5116,7 +5116,7 @@ private static void GetLocals(RuntimeInstance runtime, string methodName, bool a
Assert.NotNull(assembly);
if (count == 0)
{
Assert.Equal(0, assembly.Count);
Assert.Empty(assembly);
}
else
{
Expand Down Expand Up @@ -5156,7 +5156,7 @@ private static void GetLocals(RuntimeInstance runtime, string methodName, Method
Assert.NotNull(assembly);
if (count == 0)
{
Assert.Equal(0, assembly.Count);
Assert.Empty(assembly);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ public void BadPdb_ForwardChain()

importStrings = CustomDebugInfoReader.GetCSharpGroupedImportStrings(methodToken2, 0, getMethodCustomDebugInfo, getMethodImportStrings, out externAliasStrings);
Assert.Equal(importString, importStrings.Single().Single());
Assert.Equal(0, externAliasStrings.Length);
Assert.Empty(externAliasStrings);

importStrings = CustomDebugInfoReader.GetCSharpGroupedImportStrings(methodToken2, 0, getMethodCustomDebugInfo, getMethodImportStrings, out externAliasStrings);
Assert.Equal(importString, importStrings.Single().Single());
Assert.Equal(0, externAliasStrings.Length);
Assert.Empty(externAliasStrings);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ End Class"
Dim typeName As String = Nothing
Dim assembly = context.CompileGetLocals(locals, argumentsOnly:=False, typeName:=typeName, testData:=testData)
Assert.NotNull(assembly)
Assert.Equal(0, assembly.Count)
Assert.Equal(0, locals.Count)
Assert.Empty(assembly)
Assert.Empty(locals)
locals.Free()
End Sub)
End Sub
Expand Down Expand Up @@ -1789,7 +1789,7 @@ End Class"
Diagnostic(ERRID.ERR_TypeRefResolutionError3, "a").WithArguments("A", "Test.dll").WithLocation(1, 1)
})

Assert.Equal(0, locals.Count)
Assert.Empty(locals)
locals.Free()
End Sub)
End Sub
Expand Down Expand Up @@ -3373,7 +3373,7 @@ End Class"

Assert.NotNull(assembly)
If count = 0 Then
Assert.Equal(0, assembly.Count)
Assert.Empty(assembly)
Else
Assert.InRange(assembly.Count, 0, Integer.MaxValue)
End If
Expand Down Expand Up @@ -3408,7 +3408,7 @@ End Class"

Assert.NotNull(assembly)
If count = 0 Then
Assert.Equal(0, assembly.Count)
Assert.Empty(assembly)
Else
Assert.InRange(assembly.Count, 0, Integer.MaxValue)
End If
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ class A {

var results = await RunGetWorkspacePullDiagnosticsAsync(testLspServer, useVSDiagnostics: true, includeTaskListItems: false, category: PullDiagnosticCategories.Task);

Assert.Equal(0, results.Length);
Assert.Empty(results);
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -1115,7 +1115,7 @@ class A {

var results = await RunGetWorkspacePullDiagnosticsAsync(testLspServer, useVSDiagnostics: true, includeTaskListItems: false, category: PullDiagnosticCategories.Task);

Assert.Equal(0, results.Length);
Assert.Empty(results);
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -2115,7 +2115,7 @@ public async Task TestWorkspaceDiagnosticsForClosedFilesSwitchFSAFromOffToOn(boo

var results = await RunGetWorkspacePullDiagnosticsAsync(testLspServer, useVSDiagnostics);

Assert.Equal(0, results.Length);
Assert.Empty(results);

var options = testLspServer.TestWorkspace.ExportProvider.GetExportedValue<IGlobalOptionService>();
options.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.CSharp, BackgroundAnalysisScope.FullSolution);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Y
project.Documents.First().GetURI(),
useProgress: useProgress);

Assert.Equal(0, results.Length);
Assert.Empty(results);
}

[Theory, CombinatorialData]
Expand Down
8 changes: 4 additions & 4 deletions src/Scripting/CoreTest.Desktop/GlobalAssemblyCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ public void GetAssemblyIdentities()
}

names = gac.GetAssemblyIdentities("x\u0002").ToArray();
Assert.Equal(0, names.Length);
Assert.Empty(names);

names = gac.GetAssemblyIdentities("\0").ToArray();
Assert.Equal(0, names.Length);
Assert.Empty(names);

names = gac.GetAssemblyIdentities("xxxx\0xxxxx").ToArray();
Assert.Equal(0, names.Length);
Assert.Empty(names);

// fusion API CreateAssemblyEnum returns S_FALSE for this name
names = gac.GetAssemblyIdentities("nonexistingassemblyname" + Guid.NewGuid().ToString()).ToArray();
Assert.Equal(0, names.Length);
Assert.Empty(names);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public async Task TestSearchDocumentSymbolData()

// No search results found
searchedSymbols = DocumentOutlineViewModel.SearchDocumentSymbolData(model.DocumentSymbolData, "xyz", CancellationToken.None);
Assert.Equal(0, searchedSymbols.Length);
Assert.Empty(searchedSymbols);
}

[WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/66012")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1966,15 +1966,15 @@ public void TestAddAttributesToAccessors()
private void CheckAddRemoveAttribute(SyntaxNode declaration)
{
var initialAttributes = Generator.GetAttributes(declaration);
Assert.Equal(0, initialAttributes.Count);
Assert.Empty(initialAttributes);

var withAttribute = Generator.AddAttributes(declaration, Generator.Attribute("a"));
var attrsAdded = Generator.GetAttributes(withAttribute);
Assert.Equal(1, attrsAdded.Count);

var withoutAttribute = Generator.RemoveNode(withAttribute, attrsAdded[0]);
var attrsRemoved = Generator.GetAttributes(withoutAttribute);
Assert.Equal(0, attrsRemoved.Count);
Assert.Empty(attrsRemoved);
}

[Fact]
Expand Down Expand Up @@ -3662,7 +3662,7 @@ public void TestGetBaseAndInterfaceTypes()

var baseListN = Generator.GetBaseAndInterfaceTypes(classN);
Assert.NotNull(baseListN);
Assert.Equal(0, baseListN.Count);
Assert.Empty(baseListN);
}

[Fact]
Expand Down
Loading

0 comments on commit 9cab90a

Please sign in to comment.