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 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 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());
        }
Ejemplo n.º 4
0
 public void SetRoots(string declarationFilter)
 {
     _textBox.Text = string.Empty;
     PopulateGraph(null);
     SyntaxWrapper[] roots = new SyntaxTreeDeclarationFilter(declarationFilter)
                             .GetMatchingSyntaxNodes(_syntaxTree)
                             .Select(x => SyntaxWrapper.Get(x))
                             .ToArray();
     _treeList.Roots = roots;
     if (roots.Length != 0)
     {
         _treeList.ExpandAll();
         _textBox.Text = string.Join(
             Environment.NewLine + Environment.NewLine + "-" + Environment.NewLine + Environment.NewLine,
             roots.Select(x => x.GetSyntaxObject().ToString()));
         PopulateGraph();
     }
 }
        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");
        }
 public void SetRoots(string declarationFilter)
 {
     _textBox.Text = string.Empty;
     PopulateGraph(null);
     SyntaxWrapper[] roots = new SyntaxTreeDeclarationFilter(declarationFilter)
         .GetMatchingSyntaxNodes(_syntaxTree)
         .Select(x => SyntaxWrapper.Get(x))
         .ToArray();
     _treeList.Roots = roots;
     if(roots.Length != 0)
     {
         _treeList.ExpandAll();
         _textBox.Text = string.Join(
             Environment.NewLine + Environment.NewLine + "-" + Environment.NewLine + Environment.NewLine,
             roots.Select(x => x.GetSyntaxObject().ToString()));
         PopulateGraph();
     }
 }