Esempio n. 1
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")));
        }
Esempio n. 2
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")));
        }
Esempio n. 3
0
        public void Clone_ClonesBlock()
        {
            // Arrange
            var blockBuilder = new BlockBuilder()
            {
                ChunkGenerator = new DynamicAttributeBlockChunkGenerator(new LocationTagged <string>("class=\"", SourceLocation.Zero), 0, 0, 0),
                Type           = BlockKindInternal.Expression,
            };

            blockBuilder.Children.Add(new SpanBuilder(new SourceLocation(1, 2, 3)).Build());
            var block = blockBuilder.Build();

            // Act
            var copy = (Block)block.Clone();

            // Assert
            ParserTestBase.EvaluateParseTree(copy, block);
            Assert.NotSame(block, copy);
        }
Esempio n. 4
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")));
        }
Esempio n. 5
0
        public void Clone_ClonesTagHelperSourceEndTag()
        {
            // Arrange
            var tagHelper = (TagHelperBlock) new TagHelperBlockBuilder(
                "p",
                TagMode.StartTagAndEndTag,
                attributes: new List <TagHelperAttributeNode>(),
                children: Enumerable.Empty <SyntaxTreeNode>())
            {
                SourceEndTag = new BlockBuilder()
                {
                    Type           = BlockKindInternal.Comment,
                    ChunkGenerator = new RazorCommentChunkGenerator()
                }.Build()
            }.Build();

            // Act
            var copy = (TagHelperBlock)tagHelper.Clone();

            // Assert
            ParserTestBase.EvaluateParseTree(copy, tagHelper);
            Assert.NotSame(tagHelper.SourceEndTag, copy.SourceEndTag);
        }
Esempio n. 6
0
        public void Clone_ClonesTagHelperAttributes()
        {
            // Arrange
            var tagHelper = (TagHelperBlock) new TagHelperBlockBuilder(
                "p",
                TagMode.StartTagAndEndTag,
                attributes: new List <TagHelperAttributeNode>()
            {
                new TagHelperAttributeNode("class", new SpanBuilder(SourceLocation.Zero).Build(), AttributeStructure.NoQuotes),
                new TagHelperAttributeNode("checked", new SpanBuilder(SourceLocation.Undefined).Build(), AttributeStructure.NoQuotes)
            },
                children: Enumerable.Empty <SyntaxTreeNode>()).Build();

            // Act
            var copy = (TagHelperBlock)tagHelper.Clone();

            // Assert
            ParserTestBase.EvaluateParseTree(copy, tagHelper);
            Assert.Collection(
                copy.Attributes,
                attribute => Assert.NotSame(tagHelper.Attributes[0], attribute),
                attribute => Assert.NotSame(tagHelper.Attributes[1], attribute));
        }
Esempio n. 7
0
        public void Clone_ClonesTagHelperChildren()
        {
            // Arrange
            var tagHelper = new TagHelperBlockBuilder(
                "p",
                TagMode.StartTagAndEndTag,
                attributes: new List <TagHelperAttributeNode>(),
                children: new[]
            {
                new SpanBuilder(SourceLocation.Zero).Build(),
                new SpanBuilder(new SourceLocation(0, 1, 2)).Build(),
            }).Build();

            // Act
            var copy = (TagHelperBlock)tagHelper.Clone();

            // Assert
            ParserTestBase.EvaluateParseTree(copy, tagHelper);
            Assert.Collection(
                copy.Children,
                child => Assert.NotSame(tagHelper.Children[0], child),
                child => Assert.NotSame(tagHelper.Children[1], child));
        }