Пример #1
0
 public void ExceptionFilterErrors(
     string document,
     StatementBlock expectedStatement,
     RazorError[] expectedErrors)
 {
     // Act & Assert
     ParseBlockTest(document, expectedStatement, expectedErrors);
 }
Пример #2
0
 public void ExceptionFilters(string document, StatementBlock expectedStatement)
 {
     // Act & Assert
     ParseBlockTest(document, expectedStatement);
 }
Пример #3
0
        public void ParseBlock_WithUnexpectedTransitionsInAttributeValue_Throws()
        {
            // Arrange
            var expected = new StatementBlock(
                Factory.MetaCode("{").Accepts(AcceptedCharacters.None),
                new MarkupBlock(
                    new MarkupTagBlock(
                        Factory.Markup("<span"),
                        new MarkupBlock(
                        new AttributeBlockChunkGenerator("foo", new LocationTagged<string>(" foo='", 6, 0, 6), new LocationTagged<string>("'", 15, 0, 15)),
                        Factory.Markup(" foo='").With(SpanChunkGenerator.Null),
                        new MarkupBlock(
                            new DynamicAttributeBlockChunkGenerator(new LocationTagged<string>(string.Empty, 12, 0, 12), 12, 0, 12),
                            new ExpressionBlock(
                                Factory.CodeTransition(),
                                Factory.EmptyCSharp().AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace))),
                        new MarkupBlock(
                            new DynamicAttributeBlockChunkGenerator(new LocationTagged<string>(" ", 13, 0, 13), 13, 0, 13),
                            Factory.Markup(" ").With(SpanChunkGenerator.Null),
                            new ExpressionBlock(
                                Factory.CodeTransition(),
                                Factory.EmptyCSharp().AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace))),
                        Factory.Markup("'").With(SpanChunkGenerator.Null)),
                    Factory.Markup(" />").Accepts(AcceptedCharacters.None))),
                Factory.EmptyCSharp().AsStatement(),
                Factory.MetaCode("}").Accepts(AcceptedCharacters.None));
            var expectedErrors = new RazorError[]
            {
                new RazorError(@"A space or line break was encountered after the ""@"" character.  Only valid identifiers, keywords, comments, ""("" and ""{"" are valid at the start of a code block and they must occur immediately following ""@"" with no space in between.", new SourceLocation(13, 0, 13)),
                new RazorError(@"""' />}"" is not valid at the start of a code block.  Only identifiers, keywords, comments, ""("" and ""{"" are valid.", new SourceLocation(15, 0, 15)),
            };

            // Act & Assert
            ParseBlockTest("{<span foo='@ @' />}", expected, expectedErrors);
        }
Пример #4
0
        public void ParseBlock_WithDoubleTransition_DoesNotThrow()
        {
            // Arrange
            var testTemplateWithDoubleTransitionCode = " @<p foo='@@'>Foo #@item</p>";
            var testTemplateWithDoubleTransition = new TemplateBlock(
                new MarkupBlock(
                    Factory.MarkupTransition(),
                    new MarkupTagBlock(
                        Factory.Markup("<p"),
                        new MarkupBlock(
                            new AttributeBlockCodeGenerator("foo", new LocationTagged<string>(" foo='", 46, 0, 46), new LocationTagged<string>("'", 54, 0, 54)),
                            Factory.Markup(" foo='").With(SpanCodeGenerator.Null),
                             new MarkupBlock(
                                Factory.Markup("@").With(new LiteralAttributeCodeGenerator(new LocationTagged<string>(string.Empty, 52, 0, 52), new LocationTagged<string>("@", 52, 0, 52))).Accepts(AcceptedCharacters.None),
                                Factory.Markup("@").With(SpanCodeGenerator.Null).Accepts(AcceptedCharacters.None)),
                            Factory.Markup("'").With(SpanCodeGenerator.Null)),
                        Factory.Markup(">").Accepts(AcceptedCharacters.None)),
                    Factory.Markup("Foo #"),
                    new ExpressionBlock(
                        Factory.CodeTransition(),
                        Factory.Code("item")
                            .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                            .Accepts(AcceptedCharacters.NonWhiteSpace)
                        ),
                    new MarkupTagBlock(
                        Factory.Markup("</p>").Accepts(AcceptedCharacters.None))
                    )
                );

            var expected = new StatementBlock(
                    Factory.MetaCode("{").Accepts(AcceptedCharacters.None),
                    Factory.Code(" var foo = bar; Html.ExecuteTemplate(foo, ")
                        .AsStatement()
                        .AutoCompleteWith(autoCompleteString: null),
                    testTemplateWithDoubleTransition,
                    Factory.Code("); ").AsStatement(),
                    Factory.MetaCode("}").Accepts(AcceptedCharacters.None));

            // Act & Assert
            ParseBlockTest("{ var foo = bar; Html.ExecuteTemplate(foo," + testTemplateWithDoubleTransitionCode + "); }", expected);
        }
Пример #5
0
        public void ParseBlock_WithDoubleTransition_EndOfFile_Throws()
        {
            // Arrange
            var expected = new StatementBlock(
                Factory.MetaCode("{").Accepts(AcceptedCharacters.None),
                new MarkupBlock(
                    new MarkupTagBlock(
                        Factory.Markup("<span"),
                        new MarkupBlock(
                        new AttributeBlockChunkGenerator("foo", new LocationTagged<string>(" foo='", 6, 0, 6), new LocationTagged<string>(string.Empty, 14, 0, 14)),
                        Factory.Markup(" foo='").With(SpanChunkGenerator.Null),
                        new MarkupBlock(
                            Factory.Markup("@").With(new LiteralAttributeChunkGenerator(new LocationTagged<string>(string.Empty, 12, 0, 12), new LocationTagged<string>("@", 12, 0, 12))).Accepts(AcceptedCharacters.None),
                            Factory.Markup("@").With(SpanChunkGenerator.Null).Accepts(AcceptedCharacters.None)))),
                Factory.EmptyHtml()));
            var expectedErrors = new RazorError[]
            {
                new RazorError(@"End of file or an unexpected character was reached before the ""span"" tag could be parsed.  Elements inside markup blocks must be complete. They must either be self-closing (""<br />"") or have matching end tags (""<p>Hello</p>"").  If you intended to display a ""<"" character, use the ""&lt;"" HTML entity.", new SourceLocation(1, 0, 1)),
                new RazorError(@"The code block is missing a closing ""}"" character.  Make sure you have a matching ""}"" character for all the ""{"" characters within this block, and that none of the ""}"" characters are being interpreted as markup.", new SourceLocation(0, 0, 0)),
            };

            // Act & Assert
            ParseBlockTest("{<span foo='@@", expected, expectedErrors);
        }