public void GetMatchingSyntaxNodesForCSharpNonMatchingFilterReturnsNoMatches() { // Given SyntaxTreeDeclarationFilter filter = new SyntaxTreeDeclarationFilter("NoMatch"); SyntaxTree syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(CSharpTestCode); // When IEnumerable<SyntaxNode> matchingNodes = filter.GetMatchingSyntaxNodes(syntaxTree); // Then CollectionAssert.IsEmpty(matchingNodes); }
public void GetMatchingSyntaxNodesForVbEmptyFilterReturnsRoot() { // Given SyntaxTreeDeclarationFilter filter = new SyntaxTreeDeclarationFilter(string.Empty); SyntaxTree syntaxTree = Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.ParseText(VisualBasicTestCode); // When IEnumerable<SyntaxNode> matchingNodes = filter.GetMatchingSyntaxNodes(syntaxTree); // Then Assert.AreEqual(1, matchingNodes.Count()); Assert.AreEqual(matchingNodes.First(), syntaxTree.GetRoot()); }
public void GetMatchingSyntaxNodesForCSharpNullFilterReturnsRoot() { // Given SyntaxTreeDeclarationFilter filter = new SyntaxTreeDeclarationFilter(null); SyntaxTree syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(CSharpTestCode); // When IEnumerable<SyntaxNode> matchingNodes = filter.GetMatchingSyntaxNodes(syntaxTree); // Then Assert.AreEqual(1, matchingNodes.Count()); Assert.AreEqual(matchingNodes.First(), syntaxTree.GetRoot()); }
public void GetMatchingSyntaxNodesForVbVariableFilterReturnsNoMatches() { // Given SyntaxTreeDeclarationFilter filter = new SyntaxTreeDeclarationFilter("number"); SyntaxTree syntaxTree = Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.ParseText(VisualBasicTestCode); // When IEnumerable<SyntaxNode> matchingNodes = filter.GetMatchingSyntaxNodes(syntaxTree); // Then CollectionAssert.IsEmpty(matchingNodes); }
public void GetMatchingSyntaxNodesForVbPropertyFilterReturnsPropertyMatches() { // Given SyntaxTreeDeclarationFilter filter = new SyntaxTreeDeclarationFilter("Number"); SyntaxTree syntaxTree = Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.ParseText(VisualBasicTestCode); // When IEnumerable<SyntaxNode> matchingNodes = filter.GetMatchingSyntaxNodes(syntaxTree); // Then Assert.AreEqual(2, matchingNodes.Count()); Assert.IsInstanceOf<Microsoft.CodeAnalysis.VisualBasic.Syntax.PropertyBlockSyntax>(matchingNodes.First()); Assert.AreEqual(((Microsoft.CodeAnalysis.VisualBasic.Syntax.PropertyBlockSyntax)matchingNodes.First()).PropertyStatement.Identifier.ValueText, "Number"); }
public void GetMatchingSyntaxNodesForCSharpClassFilterReturnsClassMatch() { // Given SyntaxTreeDeclarationFilter filter = new SyntaxTreeDeclarationFilter("TestClass"); SyntaxTree syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(CSharpTestCode); // When IEnumerable<SyntaxNode> matchingNodes = filter.GetMatchingSyntaxNodes(syntaxTree); // Then Assert.AreEqual(1, matchingNodes.Count()); Assert.IsInstanceOf<Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax>(matchingNodes.First()); Assert.AreEqual(((Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax)matchingNodes.First()).Identifier.ValueText, "TestClass"); }