public void ParseBlockThrowsExceptionIfBlockDoesNotStartWithTag() { ParseBlockTest("foo bar <baz>", new MarkupBlock(), RazorDiagnosticFactory.CreateParsing_MarkupBlockMustStartWithTag( new SourceSpan(SourceLocation.Zero, contentLength: 3))); }
private bool TryParseCssValueComparison(RequiredAttributeDescriptorBuilder builder, out RequiredAttributeDescriptor.ValueComparisonMode valueComparison) { Debug.Assert(!AtEnd); if (CssValueComparisons.TryGetValue(Current, out valueComparison)) { var op = Current; _index++; if (op != '=' && At('=')) { // Two length operator (ex: ^=). Move past the second piece _index++; } else if (op != '=') // We're at an incomplete operator (ex: [foo^] { var diagnostic = RazorDiagnosticFactory.CreateTagHelper_PartialRequiredAttributeOperator(op, _requiredAttributes); builder.Diagnostics.Add(diagnostic); return(false); } } else if (!At(']')) { var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRequiredAttributeOperator(Current, _requiredAttributes); builder.Diagnostics.Add(diagnostic); return(false); } builder.ValueComparisonMode = valueComparison; return(true); }
public void RazorCommentInImplicitExpressionMethodCall() { ParseDocumentTest("@foo(" + Environment.NewLine + "@**@" + Environment.NewLine, new MarkupBlock( Factory.EmptyHtml(), new ExpressionBlock( Factory.CodeTransition(), Factory.Code("foo(" + Environment.NewLine) .AsImplicitExpression(CSharpCodeParser.DefaultKeywords), 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), Factory.MetaCode("*", CSharpSymbolType.RazorCommentStar) .Accepts(AcceptedCharactersInternal.None), Factory.CodeTransition(CSharpSymbolType.RazorCommentTransition) .Accepts(AcceptedCharactersInternal.None)), Factory.Code(Environment.NewLine) .AsImplicitExpression(CSharpCodeParser.DefaultKeywords))), RazorDiagnosticFactory.CreateParsing_ExpectedCloseBracketBeforeEOF( new SourceSpan(new SourceLocation(4, 0, 4), contentLength: 1), "(", ")")); }
public void ParseBlockHandlesOpenAngleWithProperTagFollowingIt() { ParseDocumentTest("@{" + Environment.NewLine + "<" + Environment.NewLine + "</html>", 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("<" + Environment.NewLine)) ), new MarkupBlock( new MarkupTagBlock( Factory.Markup("</html>").Accepts(AcceptedCharactersInternal.None)) ), Factory.EmptyCSharp().AsStatement() ) ), designTime: true, expectedErrors: new[] { RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag( new SourceSpan(new SourceLocation(5 + Environment.NewLine.Length * 2, 2, 2), contentLength: 4), "html"), RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"), }); }
private HashSet <RazorDiagnostic> Validate() { HashSet <RazorDiagnostic> diagnostics = null; if (string.IsNullOrWhiteSpace(Name)) { var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidBoundAttributeParameterNullOrWhitespace(_parent.Name); diagnostics ??= new(); diagnostics.Add(diagnostic); } else { foreach (var character in Name) { if (char.IsWhiteSpace(character) || HtmlConventions.IsInvalidNonWhitespaceHtmlCharacters(character)) { var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidBoundAttributeParameterName( _parent.Name, Name, character); diagnostics ??= new(); diagnostics.Add(diagnostic); } } } return(diagnostics); }
public void ParseAddOrRemoveDirective_CreatesErrorIfInvalidLookupText_DoesNotThrow(string directiveText, int errorLength) { // Arrange var source = TestRazorSourceDocument.Create(); var options = RazorParserOptions.CreateDefault(); var context = new ParserContext(source, options); var parser = new CSharpCodeParser(context); var directive = new CSharpCodeParser.ParsedDirective() { DirectiveText = directiveText }; var diagnostics = new List <RazorDiagnostic>(); var expectedError = RazorDiagnosticFactory.CreateParsing_InvalidTagHelperLookupText( new SourceSpan(new SourceLocation(1, 2, 3), errorLength), directiveText); // Act var result = parser.ParseAddOrRemoveDirective(directive, new SourceLocation(1, 2, 3), diagnostics); // Assert Assert.Same(directive, result); var error = Assert.Single(diagnostics); Assert.Equal(expectedError, error); }
private void ValidateParentAllowsContent(SyntaxNode child) { if (HasAllowedChildren()) { var isDisallowedContent = true; if (_featureFlags.AllowHtmlCommentsInTagHelpers) { isDisallowedContent = !IsComment(child) && !child.IsTransitionSpanKind() && !child.IsCodeSpanKind(); } if (isDisallowedContent) { var content = child.GetContent(); if (!string.IsNullOrWhiteSpace(content)) { var trimmedStart = content.TrimStart(); var whitespace = content.Substring(0, content.Length - trimmedStart.Length); var errorStart = SourceLocationTracker.Advance(child.GetSourceLocation(_source), whitespace); var length = trimmedStart.TrimEnd().Length; var allowedChildren = CurrentTagHelperTracker.AllowedChildren; var allowedChildrenString = string.Join(", ", allowedChildren); _errorSink.OnError( RazorDiagnosticFactory.CreateTagHelper_CannotHaveNonTagContent( new SourceSpan(errorStart, length), CurrentTagHelperTracker.TagName, allowedChildrenString)); } } } }
private void ConfigureBoundAttribute( BoundAttributeDescriptorBuilder builder, IPropertySymbol property, INamedTypeSymbol containingType) { var attributeNameAttribute = property .GetAttributes() .Where(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, _htmlAttributeNameAttributeSymbol)) .FirstOrDefault(); bool hasExplicitName; string attributeName; if (attributeNameAttribute == null || attributeNameAttribute.ConstructorArguments.Length == 0 || string.IsNullOrEmpty((string)attributeNameAttribute.ConstructorArguments[0].Value)) { hasExplicitName = false; attributeName = HtmlConventions.ToHtmlCase(property.Name); } else { hasExplicitName = true; attributeName = (string)attributeNameAttribute.ConstructorArguments[0].Value; } var hasPublicSetter = property.SetMethod != null && property.SetMethod.DeclaredAccessibility == Accessibility.Public; var typeName = GetFullName(property.Type); builder.TypeName = typeName; builder.SetPropertyName(property.Name); if (hasPublicSetter) { builder.Name = attributeName; if (property.Type.TypeKind == TypeKind.Enum) { builder.IsEnum = true; } if (IncludeDocumentation) { var xml = property.GetDocumentationCommentXml(); if (!string.IsNullOrEmpty(xml)) { builder.Documentation = xml; } } } else if (hasExplicitName && !IsPotentialDictionaryProperty(property)) { // Specified HtmlAttributeNameAttribute.Name though property has no public setter. var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidAttributeNameNullOrEmpty(GetFullName(containingType), property.Name); builder.Diagnostics.Add(diagnostic); } ConfigureDictionaryBoundAttribute(builder, property, containingType, attributeNameAttribute, attributeName, hasPublicSetter); }
private HashSet <RazorDiagnostic> Validate() { HashSet <RazorDiagnostic> diagnostics = null; if (string.IsNullOrWhiteSpace(Name)) { var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRestrictedChildNullOrWhitespace(_parent.GetDisplayName()); diagnostics ??= new(); diagnostics.Add(diagnostic); } else if (Name != TagHelperMatchingConventions.ElementCatchAllName) { foreach (var character in Name) { if (char.IsWhiteSpace(character) || HtmlConventions.IsInvalidNonWhitespaceHtmlCharacters(character)) { var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRestrictedChild(_parent.GetDisplayName(), Name, character); diagnostics ??= new(); diagnostics.Add(diagnostic); } } } return(diagnostics); }
public void SectionDirectiveAutoCompleteAtStartOfFile() { // 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 {" + Environment.NewLine + "<p>Foo</p>", 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.Markup(Environment.NewLine), new MarkupTagBlock( Factory.Markup("<p>")), Factory.Markup("Foo"), new MarkupTagBlock( Factory.Markup("</p>"))))); }
public void ParseBlockRequiresControlFlowStatementsToHaveBraces() { var expectedMessage = Resources.FormatParseError_SingleLine_ControlFlowStatements_Not_Allowed("{", "<"); ParseBlockTest("if(foo) <p>Bar</p> else if(bar) <p>Baz</p> else <p>Boz</p>", new StatementBlock( Factory.Code("if(foo) ").AsStatement(), new MarkupBlock( BlockFactory.MarkupTagBlock("<p>", AcceptedCharactersInternal.None), Factory.Markup("Bar"), BlockFactory.MarkupTagBlock("</p>", AcceptedCharactersInternal.None), Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None)), Factory.Code("else if(bar) ").AsStatement(), new MarkupBlock( BlockFactory.MarkupTagBlock("<p>", AcceptedCharactersInternal.None), Factory.Markup("Baz"), BlockFactory.MarkupTagBlock("</p>", AcceptedCharactersInternal.None), Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None)), Factory.Code("else ").AsStatement(), new MarkupBlock( BlockFactory.MarkupTagBlock("<p>", AcceptedCharactersInternal.None), Factory.Markup("Boz"), BlockFactory.MarkupTagBlock("</p>", AcceptedCharactersInternal.None)), Factory.EmptyCSharp().AsStatement() ), RazorDiagnosticFactory.CreateParsing_SingleLineControlFlowStatementsNotAllowed( new SourceSpan(new SourceLocation(8, 0, 8), contentLength: 1), "{", "<"), RazorDiagnosticFactory.CreateParsing_SingleLineControlFlowStatementsNotAllowed( new SourceSpan(new SourceLocation(32, 0, 32), contentLength: 1), "{", "<"), RazorDiagnosticFactory.CreateParsing_SingleLineControlFlowStatementsNotAllowed( new SourceSpan(new SourceLocation(48, 0, 48), contentLength: 1), "{", "<")); }
private StateResult QuotedLiteral(char quote, Func <char, bool> isEndQuotedLiteral, SyntaxKind literalType) { TakeUntil(isEndQuotedLiteral); if (CurrentCharacter == '\\') { TakeCurrent(); // Take the '\' // If the next char is the same quote that started this if (CurrentCharacter == quote || CurrentCharacter == '\\') { TakeCurrent(); // Take it so that we don't prematurely end the literal. } return(Stay()); } else if (EndOfFile || ParserHelpers.IsNewLine(CurrentCharacter)) { CurrentErrors.Add( RazorDiagnosticFactory.CreateParsing_UnterminatedStringLiteral( new SourceSpan(CurrentStart, contentLength: 1 /* " */))); } else { TakeCurrent(); // No-op if at EOF } return(Transition(CSharpTokenizerState.Data, EndToken(literalType))); }
public void Execute_ErrorsForRazorBlockFileScopedSinglyOccurringDirectives() { // Arrange var directive = DirectiveDescriptor.CreateRazorBlockDirective("custom", b => b.Usage = DirectiveUsage.FileScopedSinglyOccurring); var phase = new DefaultRazorIntermediateNodeLoweringPhase(); var engine = RazorProjectEngine.CreateEmpty(b => { b.Phases.Add(phase); b.Features.Add(new DefaultRazorCodeGenerationOptionsFeature(designTime: false)); b.AddDirective(directive); }); var options = RazorParserOptions.Create(builder => builder.Directives.Add(directive)); var importSource = TestRazorSourceDocument.Create("@custom { }", filePath: "import.cshtml"); var codeDocument = TestRazorCodeDocument.Create("<p>NonDirective</p>"); codeDocument.SetSyntaxTree(RazorSyntaxTree.Parse(codeDocument.Source, options)); codeDocument.SetImportSyntaxTrees(new[] { RazorSyntaxTree.Parse(importSource, options) }); var expectedDiagnostic = RazorDiagnosticFactory.CreateDirective_BlockDirectiveCannotBeImported("custom"); // Act phase.Execute(codeDocument); // Assert var documentNode = codeDocument.GetDocumentIntermediateNode(); var directives = documentNode.Children.OfType <DirectiveIntermediateNode>(); Assert.Empty(directives); var diagnostic = Assert.Single(documentNode.GetAllDiagnostics()); Assert.Equal(expectedDiagnostic, diagnostic); }
private void ValidateBinding( TagHelperBinding bindingResult, string tagName, MarkupStartTagSyntax tagBlock) { // Ensure that all descriptors associated with this tag have appropriate TagStructures. Cannot have // multiple descriptors that expect different TagStructures (other than TagStructure.Unspecified). TagHelperDescriptor baseDescriptor = null; TagStructure? baseStructure = null; foreach (var descriptor in bindingResult.Descriptors) { var boundRules = bindingResult.Mappings[descriptor]; foreach (var rule in boundRules) { if (rule.TagStructure != TagStructure.Unspecified) { // Can't have a set of TagHelpers that expect different structures. if (baseStructure.HasValue && baseStructure != rule.TagStructure) { _errorSink.OnError( RazorDiagnosticFactory.CreateTagHelper_InconsistentTagStructure( new SourceSpan(tagBlock.GetSourceLocation(_source), tagBlock.FullWidth), baseDescriptor.DisplayName, descriptor.DisplayName, tagName)); } baseDescriptor = descriptor; baseStructure = rule.TagStructure; } } } }
public void ParseBlockTerminatesNormalStringAtEndOfFile() { SingleSpanBlockTest("if(foo) { var foo = \"blah blah blah blah blah", BlockKindInternal.Statement, SpanKindInternal.Code, RazorDiagnosticFactory.CreateParsing_UnterminatedStringLiteral( new SourceSpan(new SourceLocation(20, 0, 20), contentLength: 1)), RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF( new SourceSpan(SourceLocation.Zero, contentLength: 1), "if", "}", "{")); }
public void ParseBlockStopsBalancingParenthesesAtEOF() { ImplicitExpressionTest( "foo(()", "foo(()", acceptedCharacters: AcceptedCharactersInternal.Any, errors: RazorDiagnosticFactory.CreateParsing_ExpectedCloseBracketBeforeEOF( new SourceSpan(new SourceLocation(4, 0, 4), contentLength: 1), "(", ")")); }
protected RazorCommentBlockSyntax ParseRazorComment() { if (!Language.KnowsTokenType(KnownTokenType.CommentStart) || !Language.KnowsTokenType(KnownTokenType.CommentStar) || !Language.KnowsTokenType(KnownTokenType.CommentBody)) { throw new InvalidOperationException(Resources.Language_Does_Not_Support_RazorComment); } RazorCommentBlockSyntax commentBlock; using (PushSpanContextConfig(CommentSpanContextConfig)) { EnsureCurrent(); var start = CurrentStart; Debug.Assert(At(SyntaxKind.RazorCommentTransition)); var startTransition = EatExpectedToken(SyntaxKind.RazorCommentTransition); var startStar = EatExpectedToken(SyntaxKind.RazorCommentStar); var comment = GetOptionalToken(SyntaxKind.RazorCommentLiteral); if (comment == null) { comment = SyntaxFactory.MissingToken(SyntaxKind.RazorCommentLiteral); } var endStar = GetOptionalToken(SyntaxKind.RazorCommentStar); if (endStar == null) { var diagnostic = RazorDiagnosticFactory.CreateParsing_RazorCommentNotTerminated( new SourceSpan(start, contentLength: 2 /* @* */)); endStar = SyntaxFactory.MissingToken(SyntaxKind.RazorCommentStar, diagnostic); Context.ErrorSink.OnError(diagnostic); } var endTransition = GetOptionalToken(SyntaxKind.RazorCommentTransition); if (endTransition == null) { if (!endStar.IsMissing) { var diagnostic = RazorDiagnosticFactory.CreateParsing_RazorCommentNotTerminated( new SourceSpan(start, contentLength: 2 /* @* */)); Context.ErrorSink.OnError(diagnostic); endTransition = SyntaxFactory.MissingToken(SyntaxKind.RazorCommentTransition, diagnostic); } endTransition = SyntaxFactory.MissingToken(SyntaxKind.RazorCommentTransition); } commentBlock = SyntaxFactory.RazorCommentBlock(startTransition, startStar, comment, endStar, endTransition); // Make sure we generate a marker symbol after a comment if necessary. if (!comment.IsMissing || !endStar.IsMissing || !endTransition.IsMissing) { Context.LastAcceptedCharacters = AcceptedCharactersInternal.None; } } InitializeContext(SpanContext); return(commentBlock); }
public void ParseBlockStopsParsingMidEmptyTagIfEOFReached() { ParseBlockTest("<br/", new MarkupBlock( new MarkupTagBlock( Factory.Markup("<br/"))), RazorDiagnosticFactory.CreateParsing_UnfinishedTag( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 2), "br")); }
public void ParseBlockReportsErrorIfFinallyBlockUnterminatedAtEOF() { ParseBlockTest("try { baz(); } finally { var foo = bar; if(foo != null) { bar(); } ", new StatementBlock( Factory.Code("try { baz(); } finally { var foo = bar; if(foo != null) { bar(); } ").AsStatement() ), RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF( new SourceSpan(new SourceLocation(15, 0, 15), contentLength: 1), "finally", "}", "{")); }
public void ReservedWords(string word) { ParseBlockTest(word, new DirectiveBlock( Factory.MetaCode(word).Accepts(AcceptedCharactersInternal.None) ), RazorDiagnosticFactory.CreateParsing_ReservedWord( new SourceSpan(SourceLocation.Zero, word.Length), word)); }
public void ParseBlockIncludesUnexpectedCharacterInSingleStatementControlFlowStatementError() { ParseBlockTest("if(foo)) { var bar = foo; }", new StatementBlock( Factory.Code("if(foo)) { var bar = foo; }").AsStatement() ), RazorDiagnosticFactory.CreateParsing_SingleLineControlFlowStatementsNotAllowed( new SourceSpan(new SourceLocation(7, 0, 7), contentLength: 1), "{", ")")); }
public void ParseBlockTerminatesAtEOF() { ParseBlockTest("<foo>", new MarkupBlock( new MarkupTagBlock( Factory.Markup("<foo>").Accepts(AcceptedCharactersInternal.None))), RazorDiagnosticFactory.CreateParsing_MissingEndTag( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 3), "foo")); }
public void ParseBlockReportsErrorIfDoBlockUnterminatedAtEOF() { ParseBlockTest("do { var foo = bar; if(foo != null) { bar(); } ", new StatementBlock( Factory.Code("do { var foo = bar; if(foo != null) { bar(); } ").AsStatement() ), RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF( new SourceSpan(SourceLocation.Zero, contentLength: 1), "do", "}", "{")); }
private void RunUnterminatedSimpleKeywordBlock(string keyword) { SingleSpanBlockTest( keyword + " (foo) { var foo = bar; if(foo != null) { bar(); } ", BlockKindInternal.Statement, SpanKindInternal.Code, RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF( new SourceSpan(SourceLocation.Zero, contentLength: 1), keyword, "}", "{")); }
public void AddRequiredAttributes(TagMatchingRuleDescriptorBuilder ruleBuilder) { if (string.IsNullOrEmpty(_requiredAttributes)) { return; } var descriptors = new List <RequiredAttributeDescriptor>(); PassOptionalWhitespace(); do { var successfulParse = true; ruleBuilder.Attribute(attributeBuilder => { if (At('[')) { if (!TryParseCssSelector(attributeBuilder)) { successfulParse = false; return; } } else { ParsePlainSelector(attributeBuilder); } PassOptionalWhitespace(); if (At(',')) { _index++; if (!EnsureNotAtEnd(attributeBuilder)) { successfulParse = false; return; } } else if (!AtEnd) { var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRequiredAttributeCharacter(Current, _requiredAttributes); attributeBuilder.Diagnostics.Add(diagnostic); successfulParse = false; return; } PassOptionalWhitespace(); }); if (!successfulParse) { break; } }while (!AtEnd); }
protected void RazorComment() { if (!Language.KnowsTokenType(KnownTokenType.CommentStart) || !Language.KnowsTokenType(KnownTokenType.CommentStar) || !Language.KnowsTokenType(KnownTokenType.CommentBody)) { throw new InvalidOperationException(Resources.Language_Does_Not_Support_RazorComment); } OutputSpanBeforeRazorComment(); using (PushSpanConfig(CommentSpanConfig)) { using (Context.Builder.StartBlock(BlockKindInternal.Comment)) { Context.Builder.CurrentBlock.ChunkGenerator = new RazorCommentChunkGenerator(); var start = CurrentStart; Expected(KnownTokenType.CommentStart); Output(SpanKindInternal.Transition, AcceptedCharactersInternal.None); Expected(KnownTokenType.CommentStar); Output(SpanKindInternal.MetaCode, AcceptedCharactersInternal.None); Optional(KnownTokenType.CommentBody); AddMarkerTokenIfNecessary(); Output(SpanKindInternal.Comment); var errorReported = false; if (!Optional(KnownTokenType.CommentStar)) { errorReported = true; Context.ErrorSink.OnError( RazorDiagnosticFactory.CreateParsing_RazorCommentNotTerminated( new SourceSpan(start, contentLength: 2 /* @* */))); } else { Output(SpanKindInternal.MetaCode, AcceptedCharactersInternal.None); } if (!Optional(KnownTokenType.CommentStart)) { if (!errorReported) { errorReported = true; Context.ErrorSink.OnError( RazorDiagnosticFactory.CreateParsing_RazorCommentNotTerminated( new SourceSpan(start, contentLength: 2 /* @* */))); } } else { Output(SpanKindInternal.Transition, AcceptedCharactersInternal.None); } } } Initialize(Span); }
public void ParseBlockWithUnclosedTagAtEOFThrowsMissingEndTagException() { ParseBlockTest("<foo>blah blah blah blah blah", new MarkupBlock( new MarkupTagBlock( Factory.Markup("<foo>").Accepts(AcceptedCharactersInternal.None)), Factory.Markup("blah blah blah blah blah")), RazorDiagnosticFactory.CreateParsing_MissingEndTag( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 3), "foo")); }
public void ParseBlockTerminatesNormalCSharpStringsAtEOLIfEndQuoteMissing() { SingleSpanBlockTest("if(foo) {" + Environment.NewLine + " var p = \"foo bar baz" + Environment.NewLine + ";" + Environment.NewLine + "}", BlockKindInternal.Statement, SpanKindInternal.Code, RazorDiagnosticFactory.CreateParsing_UnterminatedStringLiteral( new SourceSpan(new SourceLocation(21 + Environment.NewLine.Length, 1, 12), contentLength: 1))); }
public void ParseBlockTerminatesUsingBlockAtEOLWhenRecoveringFromMissingCloseParen() { ParseBlockTest("using(foo bar" + Environment.NewLine + "baz", new StatementBlock( Factory.Code("using(foo bar" + Environment.NewLine).AsStatement() ), RazorDiagnosticFactory.CreateParsing_ExpectedCloseBracketBeforeEOF( new SourceSpan(new SourceLocation(5, 0, 5), contentLength: 1), "(", ")")); }
public void EmptyTagNestsLikeNormalTag() { ParseBlockTest("<p></> Bar", new MarkupBlock( BlockFactory.MarkupTagBlock("<p>", AcceptedCharactersInternal.None), BlockFactory.MarkupTagBlock("</>", AcceptedCharactersInternal.None), Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None)), RazorDiagnosticFactory.CreateParsing_MissingEndTag( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")); }