Exemplo n.º 1
0
        public void FlattenFlattensStartAndEndTagTagHelpers()
        {
            // Arrange
            var spanFactory  = new SpanFactory();
            var blockFactory = new BlockFactory(spanFactory);
            var tagHelper    = (TagHelperBlock)blockFactory.TagHelperBlock(
                tagName: "div",
                tagMode: TagMode.StartTagAndEndTag,
                start: SourceLocation.Zero,
                startTag: blockFactory.MarkupTagBlock("<div>"),
                children: new SyntaxTreeNode[0],
                endTag: blockFactory.MarkupTagBlock("</div>"));

            spanFactory.Reset();
            var expectedStartTag = spanFactory.Markup("<div>");
            var expectedEndTag   = spanFactory.Markup("</div>");

            // Act
            var flattenedNodes = tagHelper.Flatten();

            // Assert
            Assert.Collection(
                flattenedNodes,
                first =>
            {
                Assert.True(first.EquivalentTo(expectedStartTag));
            },
                second =>
            {
                Assert.True(second.EquivalentTo(expectedEndTag));
            });
        }
Exemplo n.º 2
0
        public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block()
        {
            // Arrange
            var factory = new SpanFactory();
            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();

            // Act
            var rewritten = rewriter.Rewrite(start);

            factory.Reset();

            // Assert
            ParserTestBase.EvaluateParseTree(
                rewritten,
                new MarkupBlock(
                    factory.Markup("test"),
                    factory.Markup("    "),
                    new ExpressionBlock(
                        factory.CodeTransition(SyntaxConstants.TransitionString),
                        factory.Code("foo").AsExpression()),
                    factory.Markup("test")));
        }
Exemplo n.º 3
0
        public static HtmlCommentBlock HtmlCommentBlock(SpanFactory factory, Func <SpanFactory, IEnumerable <SyntaxTreeNode> > nodesBuilder = null)
        {
            var nodes = new List <SyntaxTreeNode>();

            nodes.Add(factory.Markup("<!--").Accepts(AcceptedCharactersInternal.None));
            if (nodesBuilder != null)
            {
                nodes.AddRange(nodesBuilder(factory));
            }
            nodes.Add(factory.Markup("-->").Accepts(AcceptedCharactersInternal.None));

            return(new HtmlCommentBlock(nodes.ToArray()));
        }
Exemplo n.º 4
0
        public static void RunSingleAtEscapeTest(Action <string, Block> testMethod, AcceptedCharactersInternal lastSpanAcceptedCharacters = AcceptedCharactersInternal.None)
        {
            var factory = new SpanFactory();

            testMethod("<foo>@@bar</foo>",
                       new MarkupBlock(
                           new MarkupTagBlock(
                               factory.Markup("<foo>").Accepts(lastSpanAcceptedCharacters)),
                           factory.Markup("@").Hidden(),
                           factory.Markup("@bar"),
                           new MarkupTagBlock(
                               factory.Markup("</foo>").Accepts(lastSpanAcceptedCharacters))));
        }
Exemplo n.º 5
0
        public void ParseMethodCallsParseDocumentOnMarkupParserAndReturnsResults()
        {
            // Arrange
            var factory = new SpanFactory();
            var parser  = new RazorParser();

            // Act/Assert
            ParserTestBase.EvaluateResults(parser.Parse(TestRazorSourceDocument.Create("foo @bar baz")),
                                           new MarkupBlock(
                                               factory.Markup("foo "),
                                               new ExpressionBlock(
                                                   factory.CodeTransition(),
                                                   factory.Code("bar")
                                                   .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                                                   .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                                               factory.Markup(" baz")));
        }
Exemplo n.º 6
0
        public Block EscapedMarkupTagBlock(
            string prefix,
            string suffix,
            AcceptedCharactersInternal acceptedCharacters,
            params SyntaxTreeNode[] children)
        {
            var newChildren = new List <SyntaxTreeNode>(
                new SyntaxTreeNode[]
            {
                _factory.Markup(prefix),
                _factory.BangEscape(),
                _factory.Markup(suffix).Accepts(acceptedCharacters)
            });

            newChildren.AddRange(children);

            return(new MarkupTagBlock(newChildren.ToArray()));
        }
Exemplo n.º 7
0
        public void ParseMethodUsesProvidedParserListenerIfSpecified()
        {
            // Arrange
            var factory = new SpanFactory();
            var parser  = new RazorParser();

            // Act
            var results = parser.Parse(TestRazorSourceDocument.Create("foo @bar baz"));

            // Assert
            ParserTestBase.EvaluateResults(results,
                                           new MarkupBlock(
                                               factory.Markup("foo "),
                                               new ExpressionBlock(
                                                   factory.CodeTransition(),
                                                   factory.Code("bar")
                                                   .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                                                   .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                                               factory.Markup(" baz")));
        }
Exemplo n.º 8
0
        public void FlattenFlattensSelfClosingTagHelpers()
        {
            // Arrange
            var spanFactory  = new SpanFactory();
            var blockFactory = new BlockFactory(spanFactory);
            var tagHelper    = (TagHelperBlock)blockFactory.TagHelperBlock(
                tagName: "input",
                tagMode: TagMode.SelfClosing,
                start: SourceLocation.Zero,
                startTag: blockFactory.MarkupTagBlock("<input />"),
                children: new SyntaxTreeNode[0],
                endTag: null);

            spanFactory.Reset();
            var expectedNode = spanFactory.Markup("<input />");

            // Act
            var flattenedNodes = tagHelper.Flatten();

            // Assert
            var node = Assert.Single(flattenedNodes);

            Assert.True(node.EquivalentTo(expectedNode));
        }
Exemplo n.º 9
0
        public static void RunMultiAtEscapeTest(Action <string, Block> testMethod, AcceptedCharactersInternal lastSpanAcceptedCharacters = AcceptedCharactersInternal.None)
        {
            var factory = new SpanFactory();

            testMethod("<foo>@@@@@bar</foo>",
                       new MarkupBlock(
                           new MarkupTagBlock(
                               factory.Markup("<foo>").Accepts(lastSpanAcceptedCharacters)),
                           factory.Markup("@").Hidden(),
                           factory.Markup("@"),
                           factory.Markup("@").Hidden(),
                           factory.Markup("@"),
                           new ExpressionBlock(
                               factory.CodeTransition(),
                               factory.Code("bar")
                               .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                               .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                           new MarkupTagBlock(
                               factory.Markup("</foo>").Accepts(lastSpanAcceptedCharacters))));
        }