public void Visit()
        {
            string sourceFormat   = File.ReadAllText(m_targetWithAttributeFormat);
            string sourceNoFormat = File.ReadAllText(m_targetWithAttributeNoFormat);

            SyntaxNode node = SyntaxFactory.ParseSyntaxTree(sourceNoFormat).GetRoot();

            var rewriter = new CodeGenerateRewriterFormatAttributeList();

            node = rewriter.Visit(node);

            string result = node.ToFullString();

            Assert.AreEqual(sourceFormat, result);
        }
Exemplo n.º 2
0
        public void Visit()
        {
            string sourceWith    = File.ReadAllText(m_targetWithAttribute);
            string sourceWithout = File.ReadAllText(m_targetWithoutAttribute);

            ITypeSymbol typeSymbol = m_compilation.GetTypeByMetadataName(typeof(TestAttribute).FullName);
            SyntaxNode  attribute  = m_generator.Attribute(m_generator.TypeExpression(typeSymbol));
            SyntaxNode  node       = SyntaxFactory.ParseSyntaxTree(sourceWithout).GetRoot();

            var rewriter = new CodeGenerateRewriterAddAttributeToNode(CodeAnalysisEditorUtility.Generator, attribute, syntaxNode => syntaxNode.Kind() == SyntaxKind.ClassDeclaration);
            var format   = new CodeGenerateRewriterFormatAttributeList();

            node = rewriter.Visit(node);
            node = format.Visit(node);

            string result = node.ToFullString();

            Assert.AreEqual(sourceWith, result);
        }