Пример #1
0
        public void ExpressionInCode(string expression, bool isImplicit)
        {
            ExpressionBlock expressionBlock;
            if (isImplicit)
            {
                expressionBlock =
                    new ExpressionBlock(
                        Factory.CodeTransition(),
                        Factory.Code(expression)
                               .AsImplicitExpression(VBCodeParser.DefaultKeywords, acceptTrailingDot: true)
                               .Accepts(AcceptedCharacters.NonWhiteSpace));
            }
            else
            {
                expressionBlock =
                    new ExpressionBlock(
                        Factory.CodeTransition(),
                        Factory.MetaCode("(").Accepts(AcceptedCharacters.None),
                        Factory.Code(expression).AsExpression(),
                        Factory.MetaCode(")").Accepts(AcceptedCharacters.None));
            }

            string code;
            if (isImplicit)
            {
                code = "If foo IsNot Nothing Then" + Environment.NewLine
                     + "    @" + expression + Environment.NewLine
                     + "End If";
            }
            else
            {
                code = "If foo IsNot Nothing Then" + Environment.NewLine
                     + "    @(" + expression + ")" + Environment.NewLine
                     + "End If";
            }

            ParseBlockTest(code,
                new StatementBlock(
                    Factory.Code("If foo IsNot Nothing Then\r\n    ")
                           .AsStatement(),
                    expressionBlock,
                    Factory.Code("\r\nEnd If")
                           .AsStatement()
                           .Accepts(AcceptedCharacters.None)));
        }
Пример #2
0
        public void AddRemoveTagHelperChunk_AddsChunkToTopLevelCodeTree()
        {
            // Arrange
            var spanFactory = SpanFactory.CreateCsHtml();
            var builder = new CodeTreeBuilder();
            var block = new ExpressionBlock();
            var removeTagHelperDirective = spanFactory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword + " ");

            // Act
            builder.StartChunkBlock<ExpressionBlockChunk>(block);
            builder.AddRemoveTagHelperChunk("some text", removeTagHelperDirective);
            builder.EndChunkBlock();

            // Assert
            Assert.Equal(2, builder.CodeTree.Chunks.Count);

            var chunkBlock = Assert.IsType<ExpressionBlockChunk>(builder.CodeTree.Chunks.First());
            Assert.Empty(chunkBlock.Children);

            var removeTagHelperChunk = Assert.IsType<RemoveTagHelperChunk>(builder.CodeTree.Chunks.Last());
            Assert.Equal(removeTagHelperChunk.LookupText, "some text");
        }
Пример #3
0
        public void AddAddTagHelperChunk_AddsChunkToTopLevelChunkTree()
        {
            // Arrange
            var spanFactory = SpanFactory.CreateCsHtml();
            var builder = new ChunkTreeBuilder();
            var block = new ExpressionBlock();
            var addTagHelperDirective = spanFactory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ");

            // Act
            builder.StartParentChunk<ExpressionBlockChunk>(block);
            builder.AddAddTagHelperChunk("some text", addTagHelperDirective);
            builder.EndParentChunk();

            // Assert
            Assert.Equal(2, builder.Root.Children.Count);

            var parentChunk = Assert.IsType<ExpressionBlockChunk>(builder.Root.Children.First());
            Assert.Empty(parentChunk.Children);

            var addTagHelperChunk = Assert.IsType<AddTagHelperChunk>(builder.Root.Children.Last());
            Assert.Equal(addTagHelperChunk.LookupText, "some text");
        }