Exemplo n.º 1
0
 public void ParseBlockOutputsZeroLengthCodeSpanIfInvalidCharacterFollowsTransition()
 {
     ParseBlockTest("@/",
                    new ExpressionBlock(
                        Factory.CodeTransition(),
                        Factory.EmptyCSharp()
                        .AsImplicitExpression(KeywordSet)
                        .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                    new RazorError(
                        LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("/"),
                        new SourceLocation(1, 0, 1),
                        length: 1));
 }
Exemplo n.º 2
0
 public void ParseBlockMethodParsesNothingIfFirstCharacterIsNotIdentifierStartOrParenOrBrace()
 {
     ParseBlockTest("@!!!",
                    new ExpressionBlock(
                        Factory.CodeTransition(),
                        Factory.EmptyCSharp()
                        .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                        .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                    new RazorError(
                        LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("!"),
                        new SourceLocation(1, 0, 1),
                        length: 1));
 }
Exemplo n.º 3
0
 public void ParseBlockIgnoresSingleSlashAtStart()
 {
     ParseBlockTest("@/ foo",
                    new ExpressionBlock(
                        Factory.CodeTransition(),
                        Factory.EmptyCSharp()
                        .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                        .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                    new RazorError(
                        LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("/"),
                        new SourceLocation(1, 0, 1),
                        length: 1));
 }
Exemplo n.º 4
0
 public void ParseBlockHandlesQuotesAfterTransition()
 {
     ParseBlockTest("@\"",
                    new ExpressionBlock(
                        Factory.CodeTransition(),
                        Factory.EmptyCSharp()
                        .AsImplicitExpression(KeywordSet)
                        .Accepts(AcceptedCharactersInternal.NonWhiteSpace)
                        ),
                    new RazorError(
                        LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS('"'),
                        new SourceLocation(1, 0, 1),
                        length: 1));
 }
Exemplo n.º 5
0
        public void CSharpDocument_Runtime_PreservesParserErrors()
        {
            // Arrange
            var engine = RazorEngine.Create();

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

            var expected = RazorDiagnostic.Create(new RazorError(
                                                      LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("!"),
                                                      new SourceLocation("test.cshtml", 1, 0, 1),
                                                      length: 1));

            // Act
            engine.Process(document);

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

            Assert.Equal(expected, error);
        }
Exemplo n.º 6
0
 public void InnerImplicitExpressionDoesNotAcceptDotAfterAt()
 {
     ParseBlockTest("{@.}",
                    new StatementBlock(
                        Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                        Factory.EmptyCSharp()
                        .AsStatement()
                        .AutoCompleteWith(autoCompleteString: null),
                        new ExpressionBlock(
                            Factory.CodeTransition(),
                            Factory.EmptyCSharp().AsImplicitExpression(KeywordSet, acceptTrailingDot: true).Accepts(AcceptedCharactersInternal.NonWhiteSpace)
                            ),
                        Factory.Code(".").AsStatement(),
                        Factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
                    designTime: true,
                    expectedErrors: new[]
     {
         new RazorError(
             LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("."),
             new SourceLocation(2, 0, 2),
             length: 1)
     });
 }