Esempio n. 1
0
        public void AddLiteralChunk_AddsChunkToCodeTree_IfPreviousChunkWasNotLiteral()
        {
            // Arrange
            var spanFactory = SpanFactory.CreateCsHtml();
            var codeSpan    = spanFactory.Code("int a = 10;")
                              .AsStatement()
                              .Builder.Build();
            var literalSpan = spanFactory.Markup("<p>").Builder.Build();
            var builder     = new CodeTreeBuilder();

            // Act
            builder.AddStatementChunk("int a = 10;", codeSpan);
            builder.AddLiteralChunk("<p>", literalSpan);

            // Assert
            var chunks = builder.CodeTree.Chunks;

            Assert.Equal(2, chunks.Count);
            var statementChunk = Assert.IsType <StatementChunk>(chunks[0]);

            Assert.Equal("int a = 10;", statementChunk.Code);
            Assert.Same(codeSpan, statementChunk.Association);
            var literalChunk = Assert.IsType <LiteralChunk>(chunks[1]);

            Assert.Equal("<p>", literalChunk.Text);
            Assert.Same(literalSpan, literalChunk.Association);
        }
Esempio n. 2
0
        public void AddLiteralChunk_AppendsToPreviousChunk_IfChunkWasLiteral()
        {
            // Arrange
            var spanFactory  = SpanFactory.CreateCsHtml();
            var previousSpan = spanFactory.Markup("<a>").Builder.Build();
            var newSpan      = spanFactory.Markup("<p>").Builder.Build();
            var builder      = new CodeTreeBuilder();

            // Act
            builder.AddLiteralChunk("<a>", previousSpan);
            builder.AddLiteralChunk("<p>", newSpan);

            // Assert
            var chunk        = Assert.Single(builder.CodeTree.Chunks);
            var literalChunk = Assert.IsType <LiteralChunk>(chunk);

            Assert.Equal("<a><p>", literalChunk.Text);
            var span = Assert.IsType <Span>(literalChunk.Association);

            Assert.Equal(previousSpan.Symbols.Concat(newSpan.Symbols), span.Symbols);
        }
Esempio n. 3
0
        public void AddLiteralChunk_AddsChunkToCodeTree()
        {
            // Arrange
            var spanFactory = SpanFactory.CreateCsHtml();
            var previousSpan = spanFactory.EmptyHtml().Builder.Build();
            var builder = new CodeTreeBuilder();

            // Act
            builder.AddLiteralChunk("some text", previousSpan);

            // Assert
            var chunk = Assert.Single(builder.CodeTree.Chunks);
            var literalChunk = Assert.IsType<LiteralChunk>(chunk);
            Assert.Equal("some text", literalChunk.Text);
            Assert.Same(previousSpan, literalChunk.Association);
        }
Esempio n. 4
0
        public void AddLiteralChunk_AddsChunkToCodeTree()
        {
            // Arrange
            var spanFactory  = SpanFactory.CreateCsHtml();
            var previousSpan = spanFactory.EmptyHtml().Builder.Build();
            var builder      = new CodeTreeBuilder();

            // Act
            builder.AddLiteralChunk("some text", previousSpan);

            // Assert
            var chunk        = Assert.Single(builder.CodeTree.Chunks);
            var literalChunk = Assert.IsType <LiteralChunk>(chunk);

            Assert.Equal("some text", literalChunk.Text);
            Assert.Same(previousSpan, literalChunk.Association);
        }
Esempio n. 5
0
        public void AddLiteralChunk_AppendsToPreviousChunk_IfChunkWasLiteral()
        {
            // Arrange
            var spanFactory = SpanFactory.CreateCsHtml();
            var previousSpan = spanFactory.Markup("<a>").Builder.Build();
            var newSpan = spanFactory.Markup("<p>").Builder.Build();
            var builder = new CodeTreeBuilder();

            // Act
            builder.AddLiteralChunk("<a>", previousSpan);
            builder.AddLiteralChunk("<p>", newSpan);

            // Assert
            var chunk = Assert.Single(builder.CodeTree.Chunks);
            var literalChunk = Assert.IsType<LiteralChunk>(chunk);
            Assert.Equal("<a><p>", literalChunk.Text);
            var span = Assert.IsType<Span>(literalChunk.Association);
            Assert.Equal(previousSpan.Symbols.Concat(newSpan.Symbols), span.Symbols);
        }
Esempio n. 6
0
        public void AddLiteralChunk_AddsChunkToCodeTree_IfPreviousChunkWasNotLiteral()
        {
            // Arrange
            var spanFactory = SpanFactory.CreateCsHtml();
            var codeSpan = spanFactory.Code("int a = 10;")
                                      .AsStatement()
                                      .Builder.Build();
            var literalSpan = spanFactory.Markup("<p>").Builder.Build();
            var builder = new CodeTreeBuilder();

            // Act
            builder.AddStatementChunk("int a = 10;", codeSpan);
            builder.AddLiteralChunk("<p>", literalSpan);

            // Assert
            var chunks = builder.CodeTree.Chunks;
            Assert.Equal(2, chunks.Count);
            var statementChunk = Assert.IsType<StatementChunk>(chunks[0]);
            Assert.Equal("int a = 10;", statementChunk.Code);
            Assert.Same(codeSpan, statementChunk.Association);
            var literalChunk = Assert.IsType<LiteralChunk>(chunks[1]);
            Assert.Equal("<p>", literalChunk.Text);
            Assert.Same(literalSpan, literalChunk.Association);
        }