Exemplo 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")));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
        }