Exemple #1
0
 public void ParseBlockHandlesOpenAngleAtEof()
 {
     ParseDocumentTest("@{" + Environment.NewLine
                       + "<",
                       new MarkupBlock(
                           Factory.EmptyHtml(),
                           new StatementBlock(
                               Factory.CodeTransition(),
                               Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                               Factory.Code(Environment.NewLine)
                               .AsStatement()
                               .AutoCompleteWith("}"),
                               new MarkupBlock(
                                   new MarkupTagBlock(
                                       Factory.Markup("<"))))),
                       RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                           new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"));
 }
        public void FunctionsDirectiveAutoCompleteAtStartOfFile()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(FunctionsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                    new SourceSpan(new SourceLocation(10, 0, 10), contentLength: 1), "functions", "}", "{"));

            // Act & Assert
            ParseBlockTest(
                "@functions{" + Environment.NewLine + "foo",
                new[] { FunctionsDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.CodeTransition(),
                                   Factory.MetaCode("functions").Accepts(AcceptedCharactersInternal.None),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None),
                                   Factory.Code(Environment.NewLine + "foo").AsStatement()));
        }
Exemple #3
0
        public void ParseBlockDoesNoErrorRecoveryForFunctionsBlock()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(FunctionsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                    new SourceSpan(new SourceLocation(10, 0, 10), contentLength: 1), "functions", "}", "{"));

            // Act & Assert
            ParseBlockTest(
                "functions { { { { { } zoop",
                new[] { FunctionsDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.MetaCode("functions").Accepts(AcceptedCharactersInternal.None),
                                   Factory.Span(SpanKindInternal.Markup, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None),
                                   Factory.Code(" { { { { } zoop").AsStatement()));
        }
Exemple #4
0
        public void CSharpDocument_DesignTime_PreservesParserErrors()
        {
            // Arrange
            var engine = RazorEngine.CreateDesignTime();

            var document = RazorCodeDocument.Create(TestRazorSourceDocument.Create("@{", fileName: "test.cshtml"));

            var expected = RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                new SourceSpan(new SourceLocation("test.cshtml", 1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{");

            // Act
            engine.Process(document);

            // Assert
            var csharpDocument = document.GetCSharpDocument();
            var error          = Assert.Single(csharpDocument.Diagnostics);

            Assert.Equal(expected, error);
        }
Exemple #5
0
 public void RazorCommentInVerbatimBlock()
 {
     ParseDocumentTest("@{" + Environment.NewLine
                       + "    <text" + Environment.NewLine
                       + "    @**@" + Environment.NewLine
                       + "}",
                       new MarkupBlock(
                           Factory.EmptyHtml(),
                           new StatementBlock(
                               Factory.CodeTransition(),
                               Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                               Factory.Code($"{Environment.NewLine}    ")
                               .AsStatement()
                               .AutoCompleteWith("}"),
                               new MarkupBlock(
                                   new MarkupTagBlock(
                                       Factory.MarkupTransition("<text").Accepts(AcceptedCharactersInternal.Any)),
                                   Factory.Markup(Environment.NewLine).Accepts(AcceptedCharactersInternal.None),
                                   Factory.Markup("    ").With(SpanChunkGenerator.Null),
                                   new CommentBlock(
                                       Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition)
                                       .Accepts(AcceptedCharactersInternal.None),
                                       Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar)
                                       .Accepts(AcceptedCharactersInternal.None),
                                       Factory.Span(SpanKindInternal.Comment, new HtmlSymbol(
                                                        string.Empty,
                                                        HtmlSymbolType.Unknown))
                                       .Accepts(AcceptedCharactersInternal.Any),
                                       Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar)
                                       .Accepts(AcceptedCharactersInternal.None),
                                       Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition)
                                       .Accepts(AcceptedCharactersInternal.None)),
                                   Factory.Markup(Environment.NewLine).With(SpanChunkGenerator.Null),
                                   Factory.Markup("}")))),
                       RazorDiagnosticFactory.CreateParsing_TextTagCannotContainAttributes(
                           new SourceSpan(new SourceLocation(7 + Environment.NewLine.Length, 1, 5), contentLength: 4)),
                       RazorDiagnosticFactory.CreateParsing_MissingEndTag(
                           new SourceSpan(new SourceLocation(7 + Environment.NewLine.Length, 1, 5), contentLength: 4), "text"),
                       RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                           new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"));
 }
        public void CSharpDocument_DesignTime_PreservesParserErrors()
        {
            // Arrange
            var projectEngine = CreateProjectEngine();
            var projectItem   = new TestRazorProjectItem("test.cshtml")
            {
                Content = "@{"
            };

            var expected = RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                new SourceSpan(new SourceLocation("test.cshtml", 1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{");

            // Act
            var codeDocument = projectEngine.ProcessDesignTime(projectItem);

            // Assert
            var csharpDocument = codeDocument.GetCSharpDocument();
            var error          = Assert.Single(csharpDocument.Diagnostics);

            Assert.Equal(expected, error);
        }
Exemple #7
0
 public void ParseBlockMethodProducesErrorIfEOFAfterTransitionInEmbeddedExpression()
 {
     ParseBlockTest("{" + Environment.NewLine
                    + "    @",
                    new StatementBlock(
                        Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                        Factory.Code(Environment.NewLine + "    ")
                        .AsStatement()
                        .AutoCompleteWith("}"),
                        new ExpressionBlock(
                            Factory.CodeTransition(),
                            Factory.EmptyCSharp()
                            .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
                            .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                        Factory.EmptyCSharp().AsStatement()
                        ),
                    RazorDiagnosticFactory.CreateParsing_UnexpectedEndOfFileAtStartOfCodeBlock(
                        new SourceSpan(new SourceLocation(6 + Environment.NewLine.Length, 1, 5), contentLength: 1)),
                    RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                        new SourceSpan(SourceLocation.Zero, contentLength: 1), Resources.BlockName_Code, "}", "{"));
 }
Exemple #8
0
 public void UnterminatedRazorCommentInVerbatimBlock()
 {
     ParseDocumentTest("@{@*",
                       new MarkupBlock(
                           Factory.EmptyHtml(),
                           new StatementBlock(
                               Factory.CodeTransition(),
                               Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                               Factory.EmptyCSharp()
                               .AsStatement()
                               .AutoCompleteWith("}"),
                               new CommentBlock(
                                   Factory.CodeTransition(CSharpSymbolType.RazorCommentTransition)
                                   .Accepts(AcceptedCharactersInternal.None),
                                   Factory.MetaCode("*", CSharpSymbolType.RazorCommentStar)
                                   .Accepts(AcceptedCharactersInternal.None),
                                   Factory.Span(SpanKindInternal.Comment, new CSharpSymbol(string.Empty, CSharpSymbolType.Unknown))
                                   .Accepts(AcceptedCharactersInternal.Any)))),
                       RazorDiagnosticFactory.CreateParsing_RazorCommentNotTerminated(
                           new SourceSpan(new SourceLocation(2, 0, 2), contentLength: 2)),
                       RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                           new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"));
 }
        public void SectionDirectiveAutoCompleteAtEOF()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(SectionDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                    new SourceSpan(new SourceLocation(16, 0, 16), contentLength: 1), "section", "}", "{"));

            // Act & Assert
            ParseBlockTest(
                "@section Header {",
                new[] { SectionDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.CodeTransition(),
                                   Factory.MetaCode("section").Accepts(AcceptedCharactersInternal.None),
                                   Factory.Span(SpanKindInternal.Code, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.WhiteSpace),
                                   Factory.Span(SpanKindInternal.Code, "Header", CSharpSymbolType.Identifier)
                                   .AsDirectiveToken(SectionDirective.Directive.Tokens.First()),
                                   Factory.Span(SpanKindInternal.Markup, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None),
                                   new MarkupBlock(
                                       Factory.EmptyHtml())));
        }
 public void VerbatimBlockAutoCompleteAtStartOfFile()
 {
     ParseBlockTest(
         "@{" + Environment.NewLine + "<p></p>",
         new StatementBlock(
             Factory.CodeTransition(),
             Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
             Factory.Code(Environment.NewLine)
             .AsStatement()
             .With(new AutoCompleteEditHandler(CSharpLanguageCharacteristics.Instance.TokenizeString)
     {
         AutoCompleteString = "}"
     }),
             new MarkupBlock(
                 new MarkupTagBlock(
                     Factory.Markup("<p>").Accepts(AcceptedCharactersInternal.None)),
                 new MarkupTagBlock(
                     Factory.Markup("</p>").Accepts(AcceptedCharactersInternal.None))),
             Factory.Span(SpanKindInternal.Code, new CSharpSymbol(string.Empty, CSharpSymbolType.Unknown))
             .With(new StatementChunkGenerator())
             ),
         RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
             new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"));
 }