public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block()
        {
            // Arrange
            var factory = SpanFactory.CreateCsHtml();
            var start   = new MarkupBlock(
                factory.Markup("test"),
                new ExpressionBlock(
                    factory.Code("    ").AsExpression(),
                    factory.CodeTransition(SyntaxConstants.TransitionString),
                    factory.Code("foo").AsExpression()
                    ),
                factory.Markup("test")
                );
            var rewriter         = new WhiteSpaceRewriter(new HtmlMarkupParser().BuildSpan);
            var rewritingContext = new RewritingContext(start, new ErrorSink());

            // Act
            rewriter.Rewrite(rewritingContext);

            factory.Reset();

            // Assert
            ParserTestBase.EvaluateParseTree(rewritingContext.SyntaxTree, new MarkupBlock(
                                                 factory.Markup("test"),
                                                 factory.Markup("    "),
                                                 new ExpressionBlock(
                                                     factory.CodeTransition(SyntaxConstants.TransitionString),
                                                     factory.Code("foo").AsExpression()
                                                     ),
                                                 factory.Markup("test")
                                                 ));
        }
Exemplo n.º 2
0
        public RazorSyntaxTree Execute(RazorCodeDocument codeDocument, RazorSyntaxTree syntaxTree)
        {
            if (codeDocument == null)
            {
                throw new ArgumentNullException(nameof(codeDocument));
            }

            if (syntaxTree == null)
            {
                throw new ArgumentNullException(nameof(syntaxTree));
            }

            var conditionalAttributeCollapser = new ConditionalAttributeCollapser();
            var rewritten = conditionalAttributeCollapser.Rewrite(syntaxTree.Root);

            var whitespaceRewriter = new WhiteSpaceRewriter();

            rewritten = whitespaceRewriter.Rewrite(rewritten);

            var rewrittenSyntaxTree = RazorSyntaxTree.Create(rewritten, syntaxTree.Source, syntaxTree.Diagnostics, syntaxTree.Options);

            return(rewrittenSyntaxTree);
        }