public void ParseBlockOutputsZeroLengthCodeSpanIfInvalidCharacterFollowsTransition() { ParseBlockTest("@/", new ExpressionBlock( Factory.CodeTransition(), Factory.EmptyCSharp() .AsImplicitExpression(KeywordSet) .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), RazorDiagnosticFactory.CreateParsing_UnexpectedCharacterAtStartOfCodeBlock( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "/")); }
public void ParseBlockIgnoresSingleSlashAtStart() { ParseBlockTest("@/ foo", new ExpressionBlock( Factory.CodeTransition(), Factory.EmptyCSharp() .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), RazorDiagnosticFactory.CreateParsing_UnexpectedCharacterAtStartOfCodeBlock( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "/")); }
public void ParseBlockMethodParsesNothingIfFirstCharacterIsNotIdentifierStartOrParenOrBrace() { ParseBlockTest("@!!!", new ExpressionBlock( Factory.CodeTransition(), Factory.EmptyCSharp() .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), RazorDiagnosticFactory.CreateParsing_UnexpectedCharacterAtStartOfCodeBlock( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "!")); }
public void ParseBlockHandlesQuotesAfterTransition() { ParseBlockTest("@\"", new ExpressionBlock( Factory.CodeTransition(), Factory.EmptyCSharp() .AsImplicitExpression(KeywordSet) .Accepts(AcceptedCharactersInternal.NonWhiteSpace) ), RazorDiagnosticFactory.CreateParsing_UnexpectedCharacterAtStartOfCodeBlock( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "\"")); }
public void CSharpDocument_Runtime_PreservesParserErrors() { // Arrange var engine = RazorEngine.Create(); var document = RazorCodeDocument.Create(TestRazorSourceDocument.Create("@!!!", fileName: "test.cshtml")); var expected = RazorDiagnosticFactory.CreateParsing_UnexpectedCharacterAtStartOfCodeBlock( new SourceSpan(new SourceLocation("test.cshtml", 1, 0, 1), contentLength: 1), "!"); // Act engine.Process(document); // Assert var csharpDocument = document.GetCSharpDocument(); var error = Assert.Single(csharpDocument.Diagnostics); Assert.Equal(expected, error); }
public void CSharpDocument_Runtime_PreservesParserErrors() { // Arrange var projectEngine = CreateProjectEngine(); var projectItem = new TestRazorProjectItem("test.cshtml") { Content = "@!!!" }; var expected = RazorDiagnosticFactory.CreateParsing_UnexpectedCharacterAtStartOfCodeBlock( new SourceSpan(new SourceLocation("test.cshtml", 1, 0, 1), contentLength: 1), "!"); // Act var codeDocument = projectEngine.Process(projectItem); // Assert var csharpDocument = codeDocument.GetCSharpDocument(); var error = Assert.Single(csharpDocument.Diagnostics); Assert.Equal(expected, error); }
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[] { RazorDiagnosticFactory.CreateParsing_UnexpectedCharacterAtStartOfCodeBlock( new SourceSpan(new SourceLocation(2, 0, 2), contentLength: 1), ".") }); }