- {
- {
- "
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- },
- {
- "
- {
- new TagHelperAttributeNode("notRequired", factory.Markup("hi")),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- },
- {
- "
"),
- blockFactory.MarkupTagBlock("
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(17, 0, 17), contentLength: 1), "p")
- }
- },
- {
- "
- {
- new TagHelperAttributeNode("notRequired", factory.Markup("hi")),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(34, 0, 34), contentLength: 1), "p")
- }
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: blockFactory.MarkupTagBlock(""))),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"),
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- attributes: new List
- {
- new TagHelperAttributeNode("notRequired", factory.Markup("hi")),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: blockFactory.MarkupTagBlock(""))),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"),
- }
- },
- {
- "
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(17, 0, 17), contentLength: 1), "p")
- }
- },
- {
- "
- {
- new TagHelperAttributeNode("notRequired", factory.Markup("hi")),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(34, 0, 34), contentLength: 1), "p")
- }
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- [Theory]
- [MemberData(nameof(MalformedRequiredAttributeData))]
- public void Rewrite_RequiredAttributeDescriptorsCreateMalformedTagHelperBlocksCorrectly(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly6()
{
- // Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("pTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("p")
- .RequireAttributeDescriptor(attribute => attribute.Name("class")))
- .Build(),
- };
-
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors);
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- public static TheoryData PrefixedTagHelperBoundData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly7()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var availableDescriptorsColon = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("mythTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("myth"))
- .Build(),
- TagHelperDescriptorBuilder.Create("mythTagHelper2", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("myth2"))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("bound")
- .PropertyName("Bound")
- .TypeName(typeof(bool).FullName))
- .Build()
- };
- var availableDescriptorsCatchAll = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("mythTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- .Build(),
- };
-
- // documentContent, expectedOutput, availableDescriptors
- return new TheoryData>
- {
- {
- " ",
- new MarkupBlock(blockFactory.MarkupTagBlock(" ")),
- availableDescriptorsCatchAll
- },
- {
- "words and spaces ",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- factory.Markup("words and spaces"),
- blockFactory.MarkupTagBlock(" ")),
- availableDescriptorsCatchAll
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("th:myth", tagMode: TagMode.SelfClosing)),
- availableDescriptorsColon
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("th:myth")),
- availableDescriptorsColon
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "th:myth",
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "))),
- availableDescriptorsColon
- },
- {
- "",
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "th:myth />")),
- availableDescriptorsColon
- },
- {
- "!th:myth>",
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "th:myth>"),
- blockFactory.EscapedMarkupTagBlock("", "th:myth>")),
- availableDescriptorsColon
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "th:myth",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- })),
- availableDescriptorsColon
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "th:myth2",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- })),
- availableDescriptorsColon
- },
- {
- "words and spaces ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "th:myth",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: factory.Markup("words and spaces"))),
- availableDescriptorsColon
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "th:myth2",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- {
- new TagHelperAttributeNode(
- "bound",
- new MarkupBlock(
- new MarkupBlock(
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
- .Accepts(AcceptedCharactersInternal.AnyExceptNewline)))))
- }
- })),
- availableDescriptorsColon
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces
");
}
- [Theory]
- [MemberData(nameof(PrefixedTagHelperBoundData))]
- public void Rewrite_AllowsPrefixedTagHelpers(
- string documentContent,
- object expectedOutput,
- object availableDescriptors)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly8()
{
- // Act & Assert
- EvaluateData(
- (IEnumerable)availableDescriptors,
- documentContent,
- (MarkupBlock)expectedOutput,
- expectedErrors: Enumerable.Empty(),
- tagHelperPrefix: "th:");
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces
");
}
- public static TheoryData OptOut_WithAttributeTextTagData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly9()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- Func, MarkupBlock> buildStatementBlock = (insideBuilder) =>
- {
- return new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- insideBuilder(),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml());
- };
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "@{}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 8, 0, 8),
- suffix: new LocationTagged("\"", 19, 0, 19)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 16, 0, 16),
- value: new LocationTagged("btn", 16, 0, 16))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- factory.Markup("}")))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- RazorDiagnosticFactory.CreateParsing_MissingEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: 5), "!text"),
- }
- },
- {
- "@{!text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 8, 0, 8),
- suffix: new LocationTagged("\"", 19, 0, 19)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 16, 0, 16),
- value: new LocationTagged("btn", 16, 0, 16))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{words with spaces!text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 8, 0, 8),
- suffix: new LocationTagged("\"", 19, 0, 19)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 16, 0, 16),
- value: new LocationTagged("btn", 16, 0, 16))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- factory.Markup("words with spaces"),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{!text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class='", 8, 0, 8),
- suffix: new LocationTagged("'", 25, 0, 25)),
- factory.Markup(" class='").With(SpanChunkGenerator.Null),
- factory.Markup("btn1").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 16, 0, 16),
- value: new LocationTagged("btn1", 16, 0, 16))),
- factory.Markup(" btn2").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(" ", 20, 0, 20),
- value: new LocationTagged("btn2", 21, 0, 21))),
- factory.Markup("'").With(SpanChunkGenerator.Null)),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class2",
- prefix: new LocationTagged(" class2=", 26, 0, 26),
- suffix: new LocationTagged(string.Empty, 37, 0, 37)),
- factory.Markup(" class2=").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 34, 0, 34),
- value: new LocationTagged("btn", 34, 0, 34)))),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{!text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class='", 8, 0, 8),
- suffix: new LocationTagged("'", 39, 0, 39)),
- factory.Markup(" class='").With(SpanChunkGenerator.Null),
- factory.Markup("btn1").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 16, 0, 16),
- value: new LocationTagged("btn1", 16, 0, 16))),
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(" ", 20, 0, 20), 21, 0, 21),
- factory.Markup(" ").With(SpanChunkGenerator.Null),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace))),
- factory.Markup(" btn2").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(" ", 34, 0, 34),
- value: new LocationTagged("btn2", 35, 0, 35))),
- factory.Markup("'").With(SpanChunkGenerator.Null)),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "wordsand spaces
");
}
- public static TheoryData OptOut_WithBlockTextTagData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly10()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- RazorDiagnostic MissingEndTagError(string tagName)
- {
- return RazorDiagnosticFactory.CreateParsing_MissingEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: tagName.Length), tagName);
- }
-
- Func, MarkupBlock> buildStatementBlock = (insideBuilder) =>
- {
- return new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- insideBuilder(),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml());
- };
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "@{}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "text>", AcceptedCharactersInternal.None),
- factory.Markup("}")))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- MissingEndTagError("!text"),
- }
- },
- {
- "@{!text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 4, lineIndex: 0, characterIndex: 4, length: 5), "!text"),
- }
- },
- {
- "@{!text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "text>", AcceptedCharactersInternal.None),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{words and spaces!text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "text>", AcceptedCharactersInternal.None),
- factory.Markup("words and spaces"),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "text>", AcceptedCharactersInternal.None),
- blockFactory.MarkupTagBlock("", AcceptedCharactersInternal.None))),
- new []
- {
- MissingEndTagError("!text"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 11, lineIndex: 0, characterIndex: 11, length: 4), "text")
- }
- },
- {
- "@{!text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(factory.MarkupTransition("")),
- new MarkupTagBlock(
- factory.Markup("").Accepts(AcceptedCharactersInternal.None),
- factory.BangEscape(),
- factory.Markup("text>").Accepts(AcceptedCharactersInternal.None)))),
- new []
- {
- MissingEndTagError("text"),
- }
- },
- {
- "@{ !text>}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "text>", AcceptedCharactersInternal.None),
- new MarkupTagHelperBlock("text"),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{!text>}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagBlock(factory.MarkupTransition("")),
- new MarkupTagBlock(
- factory.Markup("<").Accepts(AcceptedCharactersInternal.None),
- factory.BangEscape(),
- factory.Markup("text>").Accepts(AcceptedCharactersInternal.None)),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None),
- factory.Markup("}")))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- MissingEndTagError("text"),
- }
- },
- {
- "@{!text> }",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "text>", AcceptedCharactersInternal.None),
- blockFactory.EscapedMarkupTagBlock("", "text>", AcceptedCharactersInternal.None)),
- new MarkupBlock(
- blockFactory.MarkupTagBlock(" ", AcceptedCharactersInternal.None)),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml()),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 19, lineIndex: 0, characterIndex: 19, length: 4), "text"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 19, lineIndex: 0, characterIndex: 19, length: 4), "text")
- }
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, " ");
}
- [Theory]
- [MemberData(nameof(OptOut_WithAttributeTextTagData))]
- [MemberData(nameof(OptOut_WithBlockTextTagData))]
- public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly11()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors, "p", "text");
+ EvaluateData(RequiredAttribute_Descriptors, " ");
}
- public static TheoryData OptOut_WithPartialTextTagData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly12()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- RazorDiagnostic UnfinishedTagError(string tagName, int length)
- {
- return RazorDiagnosticFactory.CreateParsing_UnfinishedTag(
- new SourceSpan(filePath: null, absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: length),
- tagName);
- }
-
- Func, MarkupBlock> buildPartialStatementBlock = (insideBuilder) =>
- {
- return new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- insideBuilder()));
- };
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "@{ new MarkupBlock(blockFactory.EscapedMarkupTagBlock("<", "text}"))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!text}", 6),
- }
- },
- {
- "@{ new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock(
- "<",
- "text /",
- new MarkupBlock(factory.Markup("}"))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!text", 5),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=", 8, 0, 8),
- suffix: new LocationTagged(string.Empty, 16, 0, 16)),
- factory.Markup(" class=").With(SpanChunkGenerator.Null),
- factory.Markup("}").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 15, 0, 15),
- value: new LocationTagged("}", 15, 0, 15))))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!text", 5),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 8, 0, 8),
- suffix: new LocationTagged(string.Empty, 20, 0, 20)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn}").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 16, 0, 16),
- value: new LocationTagged("btn}", 16, 0, 16))))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!text", 5),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
-
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 8, 0, 8),
- suffix: new LocationTagged("\"", 19, 0, 19)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 16, 0, 16),
- value: new LocationTagged("btn", 16, 0, 16))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- new MarkupBlock(factory.Markup("}"))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!text", 5),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("text"),
-
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 8, 0, 8),
- suffix: new LocationTagged("\"", 19, 0, 19)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 16, 0, 16),
- value: new LocationTagged("btn", 16, 0, 16))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(" /"),
- new MarkupBlock(factory.Markup("}"))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!text", 5),
- }
- }
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces ");
}
- [Theory]
- [MemberData(nameof(OptOut_WithPartialTextTagData))]
- public void Rewrite_AllowsTagHelperElementOptForIncompleteTextTagInCSharpBlock(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly13()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors, "text");
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces ");
}
- public static TheoryData OptOut_WithPartialData_CSharp
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly14()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- RazorDiagnostic UnfinishedTagError(string tagName)
- {
- return RazorDiagnosticFactory.CreateParsing_UnfinishedTag(
- new SourceSpan(filePath: null, absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: tagName.Length),
- tagName);
- }
-
- Func, MarkupBlock> buildPartialStatementBlock = (insideBuilder) =>
- {
- return new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- insideBuilder()));
- };
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "@{ new MarkupBlock(blockFactory.EscapedMarkupTagBlock("<", "}"))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!}"),
- }
- },
- {
- "@{ new MarkupBlock(blockFactory.EscapedMarkupTagBlock("<", "p}"))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!p}"),
- }
- },
- {
- "@{ new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p /", new MarkupBlock(factory.Markup("}"))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!p"),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=", 5, 0, 5),
- suffix: new LocationTagged(string.Empty, 13, 0, 13)),
- factory.Markup(" class=").With(SpanChunkGenerator.Null),
- factory.Markup("}").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 12, 0, 12),
- value: new LocationTagged("}", 12, 0, 12))))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!p"),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 5, 0, 5),
- suffix: new LocationTagged(string.Empty, 17, 0, 17)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn}").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn}", 13, 0, 13))))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!p"),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 5, 0, 5),
- suffix: new LocationTagged(string.Empty, 19, 0, 19)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn", 13, 0, 13))),
- new MarkupBlock(
- factory.Markup("@").With(new LiteralAttributeChunkGenerator(new LocationTagged(string.Empty, 16, 0, 16), new LocationTagged("@", 16, 0, 16))).Accepts(AcceptedCharactersInternal.None),
- factory.Markup("@").With(SpanChunkGenerator.Null).Accepts(AcceptedCharactersInternal.None)),
- factory.Markup("}").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 18, 0, 18),
- value: new LocationTagged("}", 18, 0, 18))))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!p"),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
-
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 5, 0, 5),
- suffix: new LocationTagged("\"", 16, 0, 16)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn", 13, 0, 13))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- new MarkupBlock(factory.Markup("}"))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!p"),
- }
- },
- {
- "@{ new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
-
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 5, 0, 5),
- suffix: new LocationTagged("\"", 16, 0, 16)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn", 13, 0, 13))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(" /"),
- new MarkupBlock(
- factory.Markup("}"))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- UnfinishedTagError("!p"),
- }
- }
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- [Theory]
- [MemberData(nameof(OptOut_WithPartialData_CSharp))]
- public void Rewrite_AllowsTagHelperElementOptForIncompleteHTMLInCSharpBlock(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly15()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors, "strong", "p");
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- public static TheoryData OptOut_WithPartialData_HTML
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly16()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- // documentContent, expectedOutput
- return new TheoryData
- {
- {
- "(" class=", 3, 0, 3),
- suffix: new LocationTagged(string.Empty, 10, 0, 10)),
- factory.Markup(" class=").With(SpanChunkGenerator.Null))))
- },
- {
- "(" class=\"", 3, 0, 3),
- suffix: new LocationTagged(string.Empty, 14, 0, 14)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 11, 0, 11),
- value: new LocationTagged("btn", 11, 0, 11))))))
- },
- {
- "(" class=\"", 3, 0, 3),
- suffix: new LocationTagged("\"", 14, 0, 14)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 11, 0, 11),
- value: new LocationTagged("btn", 11, 0, 11))),
- factory.Markup("\"").With(SpanChunkGenerator.Null))))
- },
- {
- "(" class=\"", 3, 0, 3),
- suffix: new LocationTagged("\"", 14, 0, 14)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 11, 0, 11),
- value: new LocationTagged("btn", 11, 0, 11))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(" /")))
- }
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- [Theory]
- [MemberData(nameof(OptOut_WithPartialData_HTML))]
- public void Rewrite_AllowsTagHelperElementOptForIncompleteHTML(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly17()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, new RazorDiagnostic[0], "strong", "p");
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- public static TheoryData OptOut_WithBlockData_CSharp
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly18()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- RazorDiagnostic MissingEndTagError(string tagName, int index = 3)
- {
- return RazorDiagnosticFactory.CreateParsing_MissingEndTag(
- new SourceSpan(filePath: null, absoluteIndex: index, lineIndex: 0, characterIndex: index, length: tagName.Length), tagName);
- }
-
- Func, MarkupBlock> buildStatementBlock = (insideBuilder) =>
- {
- return new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- insideBuilder(),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml());
- };
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "@{}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- factory.Markup("}")))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- MissingEndTagError("!p"),
- }
- },
- {
- "@{!p>}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 4, lineIndex: 0, characterIndex: 4, length: 2), "!p"),
- }
- },
- {
- "@{!p>}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{words and spaces!p>}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- factory.Markup("words and spaces"),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{
}",
- buildStatementBlock(
- () => new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- blockFactory.MarkupTagBlock("
", AcceptedCharactersInternal.None))),
- new []
- {
- MissingEndTagError("!p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 8, lineIndex: 0, characterIndex: 8, length: 1), "p")
- }
- },
- {
- "@{!p>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None)))),
- new []
- {
- MissingEndTagError("p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: 1), "p")
- }
- },
- {
- "@{
!p>
}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None)))),
- new RazorDiagnostic[0]
- },
- {
- "@{!p>}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None),
- factory.Markup("}"))))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- MissingEndTagError("p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: 1), "p")
- }
- },
- {
- "@{!p>
}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None)),
- new MarkupBlock(
- blockFactory.MarkupTagBlock("", AcceptedCharactersInternal.None)),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml()),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 13, lineIndex: 0, characterIndex: 13, length: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 13, lineIndex: 0, characterIndex: 13, length: 1), "p")
- }
- },
- {
- "@{!p> }",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagHelperBlock("strong",
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None))),
- new MarkupBlock(
- blockFactory.MarkupTagBlock("", AcceptedCharactersInternal.None)),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml()),
- new []
- {
- MissingEndTagError("strong"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: 6), "strong"),
- RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 17, lineIndex: 0, characterIndex: 17, length: 6), "strong"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 17, lineIndex: 0, characterIndex: 17, length: 6), "strong")
- }
- },
- {
- "@{ !p>}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagHelperBlock("strong")),
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None)),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml()),
- new RazorDiagnostic[0]
- },
- {
- "@{!strong> !p>}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong",
- blockFactory.EscapedMarkupTagBlock("", "strong>", AcceptedCharactersInternal.None)))),
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>", AcceptedCharactersInternal.None),
- blockFactory.MarkupTagBlock("", AcceptedCharactersInternal.None)),
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None)),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml()),
- new []
- {
- MissingEndTagError("p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 6, lineIndex: 0, characterIndex: 6, length: 6), "strong"),
- MissingEndTagError("!p", index: 24),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 29, lineIndex: 0, characterIndex: 29, length: 6), "strong"),
- RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 38, lineIndex: 0, characterIndex: 38, length: 2), "!p"),
- }
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
words and spaces
");
}
- public static TheoryData OptOut_WithAttributeData_CSharp
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly19()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- Func, MarkupBlock> buildStatementBlock = (insideBuilder) =>
- {
- return new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- insideBuilder(),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml());
- };
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "@{}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 5, 0, 5),
- suffix: new LocationTagged("\"", 16, 0, 16)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn", 13, 0, 13))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- factory.Markup("}")))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), Resources.BlockName_Code, "}", "{"),
- RazorDiagnosticFactory.CreateParsing_MissingEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: 2), "!p"),
- }
- },
- {
- "@{!p>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 5, 0, 5),
- suffix: new LocationTagged("\"", 16, 0, 16)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn", 13, 0, 13))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{words with spaces!p>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 5, 0, 5),
- suffix: new LocationTagged("\"", 16, 0, 16)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn", 13, 0, 13))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- factory.Markup("words with spaces"),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{!p>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class='", 5, 0, 5),
- suffix: new LocationTagged("'", 22, 0, 22)),
- factory.Markup(" class='").With(SpanChunkGenerator.Null),
- factory.Markup("btn1").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn1", 13, 0, 13))),
- factory.Markup(" btn2").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(" ", 17, 0, 17),
- value: new LocationTagged("btn2", 18, 0, 18))),
- factory.Markup("'").With(SpanChunkGenerator.Null)),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class2",
- prefix: new LocationTagged(" class2=", 23, 0, 23),
- suffix: new LocationTagged(string.Empty, 34, 0, 34)),
- factory.Markup(" class2=").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 31, 0, 31),
- value: new LocationTagged("btn", 31, 0, 31)))),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- {
- "@{!p>}",
- buildStatementBlock(
- () => new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class='", 5, 0, 5),
- suffix: new LocationTagged("'", 36, 0, 36)),
- factory.Markup(" class='").With(SpanChunkGenerator.Null),
- factory.Markup("btn1").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 13, 0, 13),
- value: new LocationTagged("btn1", 13, 0, 13))),
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(" ", 17, 0, 17), 18, 0, 18),
- factory.Markup(" ").With(SpanChunkGenerator.Null),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace))),
- factory.Markup(" btn2").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(" ", 31, 0, 31),
- value: new LocationTagged("btn2", 32, 0, 32))),
- factory.Markup("'").With(SpanChunkGenerator.Null)),
- factory.Markup(">").Accepts(AcceptedCharactersInternal.None)),
- blockFactory.EscapedMarkupTagBlock("", "p>", AcceptedCharactersInternal.None))),
- new RazorDiagnostic[0]
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- [Theory]
- [MemberData(nameof(OptOut_WithBlockData_CSharp))]
- [MemberData(nameof(OptOut_WithAttributeData_CSharp))]
- public void Rewrite_AllowsTagHelperElementOptOutCSharp(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly20()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors, "strong", "p");
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- public static TheoryData OptOut_WithBlockData_HTML
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly21()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "",
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>")),
- new RazorDiagnostic[0]
- },
- {
- "!p>",
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("", "p>")),
- new RazorDiagnostic[0]
- },
- {
- "!p>",
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>"),
- blockFactory.EscapedMarkupTagBlock("", "p>")),
- new RazorDiagnostic[0]
- },
- {
- "words and spaces!p>",
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>"),
- factory.Markup("words and spaces"),
- blockFactory.EscapedMarkupTagBlock("", "p>")),
- new RazorDiagnostic[0]
- },
- {
- "",
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>"),
- blockFactory.MarkupTagBlock("")),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 6, lineIndex: 0, characterIndex: 6, length: 1), "p")
- }
- },
- {
- "!p>",
- new MarkupBlock(
- new MarkupTagHelperBlock("p", blockFactory.EscapedMarkupTagBlock("", "p>"))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- },
- {
- "
!p>
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.EscapedMarkupTagBlock("<", "p>"),
- blockFactory.EscapedMarkupTagBlock("", "p>"))),
- new RazorDiagnostic[0]
- },
- {
- "!p>",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.EscapedMarkupTagBlock("<", "p>"),
- blockFactory.EscapedMarkupTagBlock("", "p>"))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- },
- {
- "!p>
",
- new MarkupBlock(
- blockFactory.EscapedMarkupTagBlock("<", "p>"),
- blockFactory.EscapedMarkupTagBlock("", "p>"),
- blockFactory.MarkupTagBlock("")),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(11, 0, 11), contentLength: 1), "p")
- }
- },
- {
- "!p> ",
- new MarkupBlock(
- new MarkupTagHelperBlock("strong",
- blockFactory.EscapedMarkupTagBlock("", "p>"))),
- new RazorDiagnostic[0]
- },
- {
- " !p>",
- new MarkupBlock(
- new MarkupTagHelperBlock("strong"),
- blockFactory.EscapedMarkupTagBlock("<", "p>"),
- blockFactory.EscapedMarkupTagBlock("", "p>")),
- new RazorDiagnostic[0]
- },
- {
- "!strong> !p>",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong",
- blockFactory.EscapedMarkupTagBlock("", "strong>"),
- blockFactory.EscapedMarkupTagBlock("<", "p>")),
- blockFactory.EscapedMarkupTagBlock("", "p>"))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
words and spaces
");
}
- public static TheoryData OptOut_WithAttributeData_HTML
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly22()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 3, 0, 3),
- suffix: new LocationTagged("\"", 14, 0, 14)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 11, 0, 11),
- value: new LocationTagged("btn", 11, 0, 11))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">"))),
- new RazorDiagnostic[0]
- },
- {
- "!p>",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 3, 0, 3),
- suffix: new LocationTagged("\"", 14, 0, 14)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 11, 0, 11),
- value: new LocationTagged("btn", 11, 0, 11))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">")),
- blockFactory.EscapedMarkupTagBlock("", "p>")),
- new RazorDiagnostic[0]
- },
- {
- "words and spaces!p>",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 3, 0, 3),
- suffix: new LocationTagged("\"", 14, 0, 14)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 11, 0, 11),
- value: new LocationTagged("btn", 11, 0, 11))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">")),
- factory.Markup("words and spaces"),
- blockFactory.EscapedMarkupTagBlock("", "p>")),
- new RazorDiagnostic[0]
- },
- {
- "!p>",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class='", 3, 0, 3),
- suffix: new LocationTagged("'", 20, 0, 20)),
- factory.Markup(" class='").With(SpanChunkGenerator.Null),
- factory.Markup("btn1").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 11, 0, 11),
- value: new LocationTagged("btn1", 11, 0, 11))),
- factory.Markup(" btn2").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(" ", 15, 0, 15),
- value: new LocationTagged("btn2", 16, 0, 16))),
- factory.Markup("'").With(SpanChunkGenerator.Null)),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class2",
- prefix: new LocationTagged(" class2=", 21, 0, 21),
- suffix: new LocationTagged(string.Empty, 32, 0, 32)),
- factory.Markup(" class2=").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 29, 0, 29),
- value: new LocationTagged("btn", 29, 0, 29)))),
- factory.Markup(">")),
- blockFactory.EscapedMarkupTagBlock("", "p>")),
- new RazorDiagnostic[0]
- },
- {
- "!p>",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- factory.BangEscape(),
- factory.Markup("p"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class='", 3, 0, 3),
- suffix: new LocationTagged("'", 34, 0, 34)),
- factory.Markup(" class='").With(SpanChunkGenerator.Null),
- factory.Markup("btn1").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 11, 0, 11),
- value: new LocationTagged("btn1", 11, 0, 11))),
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(" ", 15, 0, 15), 16, 0, 16),
- factory.Markup(" ").With(SpanChunkGenerator.Null),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace))),
- factory.Markup(" btn2").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(" ", 29, 0, 29),
- value: new LocationTagged("btn2", 30, 0, 30))),
- factory.Markup("'").With(SpanChunkGenerator.Null)),
- factory.Markup(">")),
- blockFactory.EscapedMarkupTagBlock("", "p>")),
- new RazorDiagnostic[0]
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces
");
}
- [Theory]
- [MemberData(nameof(OptOut_WithBlockData_HTML))]
- [MemberData(nameof(OptOut_WithAttributeData_HTML))]
- public void Rewrite_AllowsTagHelperElementOptOutHTML(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly23()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors, "strong", "p");
+ EvaluateData(RequiredAttribute_Descriptors, "wordsand spaces
");
}
- public static IEnumerable TextTagsBlockData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly24()
{
- get
- {
- var factory = new SpanFactory();
-
- // Should re-write text tags that aren't in C# blocks
- yield return new object[]
- {
- "Hello World ",
- new MarkupBlock(
- new MarkupTagHelperBlock("text",
- factory.Markup("Hello World")))
- };
- yield return new object[]
- {
- "@{Hello World }",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagBlock(
- factory.MarkupTransition("")),
- factory.Markup("Hello World").Accepts(AcceptedCharactersInternal.None),
- new MarkupTagBlock(
- factory.MarkupTransition(" "))),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml())
- };
- yield return new object[]
- {
- "@{Hello World
}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagBlock(
- factory.MarkupTransition("")),
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello World")),
- new MarkupTagBlock(
- factory.MarkupTransition(" "))),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml())
- };
- yield return new object[]
- {
- "@{Hello World
}",
- new MarkupBlock(
- factory.EmptyHtml(),
- new StatementBlock(
- factory.CodeTransition(),
- factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("text",
- factory.Markup("Hello World")))),
- factory.EmptyCSharp().AsStatement(),
- factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- factory.EmptyHtml())
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- [Theory]
- [MemberData(nameof(TextTagsBlockData))]
- public void TagHelperParseTreeRewriter_DoesNotRewriteTextTagTransitionTagHelpers(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly25()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p", "text");
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces
");
}
- public static IEnumerable SpecialTagsBlockData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly26()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- blockFactory.HtmlCommentBlock (" Hello World "),
- new MarkupTagBlock(
- factory.Markup(" ")))
- };
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- BlockFactory.HtmlCommentBlock(factory, f=> new SyntaxTreeNode[]{
- f.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace),
- new ExpressionBlock(
- f.CodeTransition(),
- f.Code("foo")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
- factory.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace) }),
- new MarkupTagBlock(
- factory.Markup(" ")))
- };
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- factory.Markup(""),
- new MarkupTagBlock(
- factory.Markup(" ")))
- };
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- factory.Markup(""),
- new MarkupTagBlock(
- factory.Markup(" ")))
- };
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- factory.Markup(""),
- new MarkupTagBlock(
- factory.Markup(" ")))
- };
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- factory.Markup(""),
- new MarkupTagBlock(
- factory.Markup(" ")))
- };
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- factory.Markup(""),
- new MarkupTagBlock(
- factory.Markup(" ")))
- };
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- factory.Markup(""),
- new MarkupTagBlock(
- factory.Markup(" ")))
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- [Theory]
- [MemberData(nameof(SpecialTagsBlockData))]
- public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly27()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces
");
}
- public static IEnumerable NestedBlockData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly28()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- yield return new object[]
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("div")))
- };
- yield return new object[]
- {
- "Hello World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello World "),
- new MarkupTagHelperBlock("div")))
- };
- yield return new object[]
- {
- "Hel
lo
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hel"),
- new MarkupTagHelperBlock("p",
- factory.Markup("lo"))),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("div",
- factory.Markup("World"))))
- };
- yield return new object[]
- {
- "Hello
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hel"),
- blockFactory.MarkupTagBlock(""),
- factory.Markup("lo"),
- blockFactory.MarkupTagBlock(" ")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(""),
- factory.Markup("World"),
- blockFactory.MarkupTagBlock(" ")))
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces
");
}
- [Theory]
- [MemberData(nameof(NestedBlockData))]
- public void TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly29()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p", "div");
+ EvaluateData(RequiredAttribute_Descriptors, "words and spaces
");
+ }
+
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly30()
+ {
+ EvaluateData(RequiredAttribute_Descriptors, "wordsand spaces
");
+ }
+
+ public static TagHelperDescriptor[] NestedRequiredAttribute_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("pTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("p")
+ .RequireAttributeDescriptor(attribute => attribute.Name("class")))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("catchAllTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("*")
+ .RequireAttributeDescriptor(attribute => attribute.Name("catchAll")))
+ .Build(),
+ };
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly1()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly2()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly3()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly4()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly5()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly6()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly7()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly8()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly9()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly10()
+ {
+ EvaluateData(NestedRequiredAttribute_Descriptors, " ");
+ }
+
+ public static TagHelperDescriptor[] MalformedRequiredAttribute_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("pTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("p")
+ .RequireAttributeDescriptor(attribute => attribute.Name("class")))
+ .Build(),
+ };
+
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateMalformedTagHelperBlocksCorrectly1()
+ {
+ EvaluateData(MalformedRequiredAttribute_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateMalformedTagHelperBlocksCorrectly8()
+ {
+ EvaluateData(MalformedRequiredAttribute_Descriptors, "");
+ }
+
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateMalformedTagHelperBlocksCorrectly9()
+ {
+ EvaluateData(MalformedRequiredAttribute_Descriptors, "
rule.RequireTagName("myth"))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("mythTagHelper2", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("myth2"))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("bound")
+ .PropertyName("Bound")
+ .TypeName(typeof(bool).FullName))
+ .Build()
+ };
+
+ public static TagHelperDescriptor[] PrefixedTagHelperCatchAll_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("mythTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
+ .Build(),
+ };
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers1()
+ {
+ EvaluateData(PrefixedTagHelperCatchAll_Descriptors, " ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers2()
+ {
+ EvaluateData(PrefixedTagHelperCatchAll_Descriptors, "words and spaces ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers3()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, " ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers4()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, " ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers5()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, " ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers6()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, "", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers7()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, "!th:myth>", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers8()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, " ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers9()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, " ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers10()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, "words and spaces ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsPrefixedTagHelpers11()
+ {
+ EvaluateData(PrefixedTagHelperColon_Descriptors, " ", tagHelperPrefix: "th:");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag1()
+ {
+ RunParseTreeRewriterTest("@{}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag2()
+ {
+ RunParseTreeRewriterTest("@{!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag3()
+ {
+ RunParseTreeRewriterTest("@{words with spaces!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag4()
+ {
+ RunParseTreeRewriterTest("@{!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag5()
+ {
+ RunParseTreeRewriterTest("@{!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag1()
+ {
+ RunParseTreeRewriterTest("@{}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag2()
+ {
+ RunParseTreeRewriterTest("@{!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag3()
+ {
+ RunParseTreeRewriterTest("@{!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag4()
+ {
+ RunParseTreeRewriterTest("@{words and spaces!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag5()
+ {
+ RunParseTreeRewriterTest("@{}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag6()
+ {
+ RunParseTreeRewriterTest("@{!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag7()
+ {
+ RunParseTreeRewriterTest("@{ !text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag8()
+ {
+ RunParseTreeRewriterTest("@{!text>}", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithBlockTextTag9()
+ {
+ RunParseTreeRewriterTest("@{!text> }", "p", "text");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptForIncompleteTextTagInCSharpBlock1()
+ {
+ RunParseTreeRewriterTest("@{}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData2()
+ {
+ RunParseTreeRewriterTest("@{!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData3()
+ {
+ RunParseTreeRewriterTest("@{!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData4()
+ {
+ RunParseTreeRewriterTest("@{words and spaces!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData5()
+ {
+ RunParseTreeRewriterTest("@{
}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData6()
+ {
+ RunParseTreeRewriterTest("@{!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData7()
+ {
+ RunParseTreeRewriterTest("@{
!p>
}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData8()
+ {
+ RunParseTreeRewriterTest("@{!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData9()
+ {
+ RunParseTreeRewriterTest("@{!p>
}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData10()
+ {
+ RunParseTreeRewriterTest("@{!p> }", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData11()
+ {
+ RunParseTreeRewriterTest("@{ !p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithBlockData12()
+ {
+ RunParseTreeRewriterTest("@{!strong> !p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithAttributeData1()
+ {
+ RunParseTreeRewriterTest("@{}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithAttributeData2()
+ {
+ RunParseTreeRewriterTest("@{!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithAttributeData3()
+ {
+ RunParseTreeRewriterTest("@{words with spaces!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithAttributeData4()
+ {
+ RunParseTreeRewriterTest("@{!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutCSharp_WithAttributeData5()
+ {
+ RunParseTreeRewriterTest("@{!p>}", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData1()
+ {
+ RunParseTreeRewriterTest("", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData2()
+ {
+ RunParseTreeRewriterTest("!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData3()
+ {
+ RunParseTreeRewriterTest("!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData4()
+ {
+ RunParseTreeRewriterTest("words and spaces!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData5()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData6()
+ {
+ RunParseTreeRewriterTest("!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData7()
+ {
+ RunParseTreeRewriterTest("
!p>
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData8()
+ {
+ RunParseTreeRewriterTest("!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData9()
+ {
+ RunParseTreeRewriterTest("!p>
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData10()
+ {
+ RunParseTreeRewriterTest("!p> ", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData11()
+ {
+ RunParseTreeRewriterTest(" !p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithBlockData12()
+ {
+ RunParseTreeRewriterTest("!strong> !p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithAttributeData1()
+ {
+ RunParseTreeRewriterTest("", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithAttributeData2()
+ {
+ RunParseTreeRewriterTest("!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithAttributeData3()
+ {
+ RunParseTreeRewriterTest("words and spaces!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithAttributeData4()
+ {
+ RunParseTreeRewriterTest("!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsTagHelperElementOptOutHTML_WithAttributeData5()
+ {
+ RunParseTreeRewriterTest("!p>", "strong", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteTextTagTransitionTagHelpers1()
+ {
+ RunParseTreeRewriterTest("Hello World ", "p", "text");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteTextTagTransitionTagHelpers2()
+ {
+ RunParseTreeRewriterTest("@{Hello World }", "p", "text");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteTextTagTransitionTagHelpers3()
+ {
+ RunParseTreeRewriterTest("@{Hello World
}", "p", "text");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteTextTagTransitionTagHelpers4()
+ {
+ RunParseTreeRewriterTest("@{
Hello World
}", "p", "text");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers1()
+ {
+ RunParseTreeRewriterTest(" ", "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers2()
+ {
+ RunParseTreeRewriterTest(" ", "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers3()
+ {
+ RunParseTreeRewriterTest(" ", "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers4()
+ {
+ RunParseTreeRewriterTest(" ", "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers5()
+ {
+ RunParseTreeRewriterTest(" ", "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers6()
+ {
+ RunParseTreeRewriterTest(" ", "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers7()
+ {
+ RunParseTreeRewriterTest(" ", "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotRewriteSpecialTagTagHelpers8()
+ {
+ RunParseTreeRewriterTest(" ", "!--", "?xml", "![CDATA[", "!DOCTYPE");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks1()
+ {
+ RunParseTreeRewriterTest("
", "p", "div");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks2()
+ {
+ RunParseTreeRewriterTest("Hello World
", "p", "div");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks3()
+ {
+ RunParseTreeRewriterTest("Hel
lo
World
", "p", "div");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks4()
+ {
+ RunParseTreeRewriterTest("Hello
World
", "p", "div");
}
[Fact]
public void Rewrite_HandlesMalformedNestedNonTagHelperTags_Correctly()
{
- var documentContent = "@{
}";
- var expectedOutput = new MarkupBlock(
- new MarkupTagBlock(
- Factory.Markup("")),
- new StatementBlock(
- Factory.CodeTransition(),
- Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
- new MarkupBlock(
- new MarkupTagBlock(
- Factory.Markup("
").Accepts(AcceptedCharactersInternal.None))),
- Factory.EmptyCSharp().AsStatement(),
- Factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
- Factory.EmptyHtml());
- var expectedErrors = new[]
- {
- RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
- new SourceSpan(new SourceLocation(9, 0, 9), contentLength: 3), "div"),
- };
-
- RunParseTreeRewriterTest(documentContent, expectedOutput, expectedErrors);
+ RunParseTreeRewriterTest("@{
}");
}
}
}
\ No newline at end of file
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperRewritingTestBase.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperRewritingTestBase.cs
index 770591d394..86a73d1683 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperRewritingTestBase.cs
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperRewritingTestBase.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using System;
using System.Collections.Generic;
using System.Linq;
@@ -8,6 +9,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
public class TagHelperRewritingTestBase : CsHtmlMarkupParserTestBase
{
+ internal void RunParseTreeRewriterTest(string documentContent, params string[] tagNames)
+ {
+ RunParseTreeRewriterTest(documentContent, expectedOutput: null, tagNames: tagNames);
+ }
+
internal void RunParseTreeRewriterTest(
string documentContent,
MarkupBlock expectedOutput,
@@ -46,6 +52,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return descriptors;
}
+ internal void EvaluateData(
+ IEnumerable descriptors,
+ string documentContent,
+ string tagHelperPrefix = null,
+ RazorParserFeatureFlags featureFlags = null)
+ {
+ EvaluateData(descriptors, documentContent, null, Array.Empty(), tagHelperPrefix, featureFlags);
+ }
+
internal void EvaluateData(
IEnumerable descriptors,
string documentContent,
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers1.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers1.syntaxtree.txt
new file mode 100644
index 0000000000..4da539e593
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers1.syntaxtree.txt
@@ -0,0 +1,8 @@
+Markup block - Gen - 7 - (0:0,0)
+ Tag block - Gen - 7 - (0:0,0)
+ Markup span - Gen - [ ] - SpanEditHandler;Accepts:Any - (0:0,0) - Symbols:5
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.Text;[th:];
+ HtmlSymbolType.WhiteSpace;[ ];
+ HtmlSymbolType.ForwardSlash;[/];
+ HtmlSymbolType.CloseAngle;[>];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers10.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers10.syntaxtree.txt
new file mode 100644
index 0000000000..86a3c37d74
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers10.syntaxtree.txt
@@ -0,0 +1,12 @@
+Markup block - Gen - 47 - (0:0,0)
+ Tag block - Gen - 47 - (0:0,0) - th:myth - mythTagHelper
+ StartTagAndEndTag - ...
+ class - DoubleQuotes
+ Markup span - Gen - [btn] - SpanEditHandler;Accepts:Any - (16:0,16) - Symbols:1
+ HtmlSymbolType.Text;[btn];
+ Markup span - Gen - [words and spaces] - SpanEditHandler;Accepts:Any - (21:0,21) - Symbols:5
+ HtmlSymbolType.Text;[words];
+ HtmlSymbolType.WhiteSpace;[ ];
+ HtmlSymbolType.Text;[and];
+ HtmlSymbolType.WhiteSpace;[ ];
+ HtmlSymbolType.Text;[spaces];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers11.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers11.syntaxtree.txt
new file mode 100644
index 0000000000..d2f2962904
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers11.syntaxtree.txt
@@ -0,0 +1,13 @@
+Markup block - Gen - 34 - (0:0,0)
+ Tag block - Gen - 34 - (0:0,0) - th:myth2 - mythTagHelper2
+ SelfClosing -
+ bound - DoubleQuotes
+ Markup block - Gen - 13 - (17:0,17)
+ Markup block - Gen - 13 - (17:0,17)
+ Expression block - Gen - 13 - (17:0,17)
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (17:0,17) - Symbols:1
+ CSharpSymbolType.Transition;[@];
+ Code span - Gen - [DateTime.Now] - ImplicitExpressionEditHandler;Accepts:AnyExceptNewline;ImplicitExpression[ATD];K14 - (18:0,18) - Symbols:3
+ CSharpSymbolType.Identifier;[DateTime];
+ CSharpSymbolType.Dot;[.];
+ CSharpSymbolType.Identifier;[Now];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers2.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers2.syntaxtree.txt
new file mode 100644
index 0000000000..c4779387d6
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers2.syntaxtree.txt
@@ -0,0 +1,18 @@
+Markup block - Gen - 27 - (0:0,0)
+ Tag block - Gen - 5 - (0:0,0)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (0:0,0) - Symbols:3
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.Text;[th:];
+ HtmlSymbolType.CloseAngle;[>];
+ Markup span - Gen - [words and spaces] - SpanEditHandler;Accepts:Any - (5:0,5) - Symbols:5
+ HtmlSymbolType.Text;[words];
+ HtmlSymbolType.WhiteSpace;[ ];
+ HtmlSymbolType.Text;[and];
+ HtmlSymbolType.WhiteSpace;[ ];
+ HtmlSymbolType.Text;[spaces];
+ Tag block - Gen - 6 - (21:0,21)
+ Markup span - Gen - [ ] - SpanEditHandler;Accepts:Any - (21:0,21) - Symbols:4
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.ForwardSlash;[/];
+ HtmlSymbolType.Text;[th:];
+ HtmlSymbolType.CloseAngle;[>];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers3.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers3.syntaxtree.txt
new file mode 100644
index 0000000000..6fa88c654b
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers3.syntaxtree.txt
@@ -0,0 +1,3 @@
+Markup block - Gen - 11 - (0:0,0)
+ Tag block - Gen - 11 - (0:0,0) - th:myth - mythTagHelper
+ SelfClosing -
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers4.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers4.syntaxtree.txt
new file mode 100644
index 0000000000..25308b73be
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers4.syntaxtree.txt
@@ -0,0 +1,3 @@
+Markup block - Gen - 19 - (0:0,0)
+ Tag block - Gen - 19 - (0:0,0) - th:myth - mythTagHelper
+ StartTagAndEndTag - ...
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers5.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers5.syntaxtree.txt
new file mode 100644
index 0000000000..7d2e3fac34
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers5.syntaxtree.txt
@@ -0,0 +1,14 @@
+Markup block - Gen - 40 - (0:0,0)
+ Tag block - Gen - 40 - (0:0,0) - th:myth - mythTagHelper
+ StartTagAndEndTag - ...
+ Tag block - Gen - 10 - (9:0,9)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (9:0,9) - Symbols:3
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.Text;[th:my2th];
+ HtmlSymbolType.CloseAngle;[>];
+ Tag block - Gen - 11 - (19:0,19)
+ Markup span - Gen - [ ] - SpanEditHandler;Accepts:Any - (19:0,19) - Symbols:4
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.ForwardSlash;[/];
+ HtmlSymbolType.Text;[th:my2th];
+ HtmlSymbolType.CloseAngle;[>];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers6.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers6.syntaxtree.txt
new file mode 100644
index 0000000000..f857e13cbe
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers6.syntaxtree.txt
@@ -0,0 +1,11 @@
+Markup block - Gen - 12 - (0:0,0)
+ Tag block - Gen - 12 - (0:0,0)
+ Markup span - Gen - [<] - SpanEditHandler;Accepts:Any - (0:0,0) - Symbols:1
+ HtmlSymbolType.OpenAngle;[<];
+ MetaCode span - Gen - [!] - SpanEditHandler;Accepts:None - (1:0,1) - Symbols:1
+ HtmlSymbolType.Bang;[!];
+ Markup span - Gen - [th:myth />] - SpanEditHandler;Accepts:Any - (2:0,2) - Symbols:4
+ HtmlSymbolType.Text;[th:myth];
+ HtmlSymbolType.WhiteSpace;[ ];
+ HtmlSymbolType.ForwardSlash;[/];
+ HtmlSymbolType.CloseAngle;[>];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers7.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers7.syntaxtree.txt
new file mode 100644
index 0000000000..cb3ccefcf1
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers7.syntaxtree.txt
@@ -0,0 +1,18 @@
+Markup block - Gen - 21 - (0:0,0)
+ Tag block - Gen - 10 - (0:0,0)
+ Markup span - Gen - [<] - SpanEditHandler;Accepts:Any - (0:0,0) - Symbols:1
+ HtmlSymbolType.OpenAngle;[<];
+ MetaCode span - Gen - [!] - SpanEditHandler;Accepts:None - (1:0,1) - Symbols:1
+ HtmlSymbolType.Bang;[!];
+ Markup span - Gen - [th:myth>] - SpanEditHandler;Accepts:Any - (2:0,2) - Symbols:2
+ HtmlSymbolType.Text;[th:myth];
+ HtmlSymbolType.CloseAngle;[>];
+ Tag block - Gen - 11 - (10:0,10)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (10:0,10) - Symbols:2
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.ForwardSlash;[/];
+ MetaCode span - Gen - [!] - SpanEditHandler;Accepts:None - (12:0,12) - Symbols:1
+ HtmlSymbolType.Bang;[!];
+ Markup span - Gen - [th:myth>] - SpanEditHandler;Accepts:Any - (13:0,13) - Symbols:2
+ HtmlSymbolType.Text;[th:myth];
+ HtmlSymbolType.CloseAngle;[>];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers8.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers8.syntaxtree.txt
new file mode 100644
index 0000000000..94f8d4f011
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers8.syntaxtree.txt
@@ -0,0 +1,6 @@
+Markup block - Gen - 23 - (0:0,0)
+ Tag block - Gen - 23 - (0:0,0) - th:myth - mythTagHelper
+ SelfClosing -
+ class - DoubleQuotes
+ Markup span - Gen - [btn] - SpanEditHandler;Accepts:Any - (16:0,16) - Symbols:1
+ HtmlSymbolType.Text;[btn];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers9.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers9.syntaxtree.txt
new file mode 100644
index 0000000000..cd47c50dd4
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsPrefixedTagHelpers9.syntaxtree.txt
@@ -0,0 +1,6 @@
+Markup block - Gen - 24 - (0:0,0)
+ Tag block - Gen - 24 - (0:0,0) - th:myth2 - mythTagHelper2
+ SelfClosing -
+ class - DoubleQuotes
+ Markup span - Gen - [btn] - SpanEditHandler;Accepts:Any - (17:0,17) - Symbols:1
+ HtmlSymbolType.Text;[btn];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsRazorCommentsAsChildren.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsRazorCommentsAsChildren.syntaxtree.txt
new file mode 100644
index 0000000000..1795f2dff2
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsRazorCommentsAsChildren.syntaxtree.txt
@@ -0,0 +1,27 @@
+Markup block - Gen - 26 - (0:0,0)
+ Tag block - Gen - 26 - (0:0,0) - p - PTagHelper
+ StartTagAndEndTag - ...
+ Tag block - Gen - 3 - (3:0,3)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (3:0,3) - Symbols:3
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.Text;[b];
+ HtmlSymbolType.CloseAngle;[>];
+ Markup span - Gen - [asdf] - SpanEditHandler;Accepts:Any - (6:0,6) - Symbols:1
+ HtmlSymbolType.Text;[asdf];
+ Tag block - Gen - 4 - (10:0,10)
+ Markup span - Gen - [ ] - SpanEditHandler;Accepts:Any - (10:0,10) - Symbols:4
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.ForwardSlash;[/];
+ HtmlSymbolType.Text;[b];
+ HtmlSymbolType.CloseAngle;[>];
+ Comment block - Gen - 8 - (14:0,14)
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (14:0,14) - Symbols:1
+ HtmlSymbolType.RazorCommentTransition;[@];
+ MetaCode span - Gen - [*] - SpanEditHandler;Accepts:None - (15:0,15) - Symbols:1
+ HtmlSymbolType.RazorCommentStar;[*];
+ Comment span - Gen - [asdf] - SpanEditHandler;Accepts:Any - (16:0,16) - Symbols:1
+ HtmlSymbolType.RazorComment;[asdf];
+ MetaCode span - Gen - [*] - SpanEditHandler;Accepts:None - (20:0,20) - Symbols:1
+ HtmlSymbolType.RazorCommentStar;[*];
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (21:0,21) - Symbols:1
+ HtmlSymbolType.RazorCommentTransition;[@];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsRazorMarkupInHtmlComment.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsRazorMarkupInHtmlComment.syntaxtree.txt
new file mode 100644
index 0000000000..4404c50f9c
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsRazorMarkupInHtmlComment.syntaxtree.txt
@@ -0,0 +1,32 @@
+Markup block - Gen - 37 - (0:0,0)
+ Tag block - Gen - 37 - (0:0,0) - p - PTagHelper
+ StartTagAndEndTag - ...
+ Tag block - Gen - 3 - (3:0,3)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (3:0,3) - Symbols:3
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.Text;[b];
+ HtmlSymbolType.CloseAngle;[>];
+ Markup span - Gen - [asdf] - SpanEditHandler;Accepts:Any - (6:0,6) - Symbols:1
+ HtmlSymbolType.Text;[asdf];
+ Tag block - Gen - 4 - (10:0,10)
+ Markup span - Gen - [ ] - SpanEditHandler;Accepts:Any - (10:0,10) - Symbols:4
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.ForwardSlash;[/];
+ HtmlSymbolType.Text;[b];
+ HtmlSymbolType.CloseAngle;[>];
+ HtmlComment block - Gen - 19 - (14:0,14)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:None - (30:0,30) - Symbols:2
+ HtmlSymbolType.DoubleHyphen;[--];
+ HtmlSymbolType.CloseAngle;[>];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsSimpleHtmlCommentsAsChildren.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsSimpleHtmlCommentsAsChildren.syntaxtree.txt
new file mode 100644
index 0000000000..018d2d3e0d
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsSimpleHtmlCommentsAsChildren.syntaxtree.txt
@@ -0,0 +1,28 @@
+Markup block - Gen - 36 - (0:0,0)
+ Tag block - Gen - 36 - (0:0,0) - p - PTagHelper
+ StartTagAndEndTag - ...
+ Tag block - Gen - 3 - (3:0,3)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (3:0,3) - Symbols:3
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.Text;[b];
+ HtmlSymbolType.CloseAngle;[>];
+ Markup span - Gen - [asdf] - SpanEditHandler;Accepts:Any - (6:0,6) - Symbols:1
+ HtmlSymbolType.Text;[asdf];
+ Tag block - Gen - 4 - (10:0,10)
+ Markup span - Gen - [ ] - SpanEditHandler;Accepts:Any - (10:0,10) - Symbols:4
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.ForwardSlash;[/];
+ HtmlSymbolType.Text;[b];
+ HtmlSymbolType.CloseAngle;[>];
+ HtmlComment block - Gen - 18 - (14:0,14)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:None - (29:0,29) - Symbols:2
+ HtmlSymbolType.DoubleHyphen;[--];
+ HtmlSymbolType.CloseAngle;[>];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag1.diagnostics.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag1.diagnostics.txt
new file mode 100644
index 0000000000..6f41e61f18
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag1.diagnostics.txt
@@ -0,0 +1,2 @@
+(1,2): Error RZ1006: 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.
+(1,4): Error RZ1025: The "!text" element was not closed. All elements must be either self-closing or have a matching end tag.
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag1.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag1.syntaxtree.txt
new file mode 100644
index 0000000000..97add6caad
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag1.syntaxtree.txt
@@ -0,0 +1,30 @@
+Markup block - Gen - 22 - (0:0,0)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (0:0,0) - Symbols:1
+ HtmlSymbolType.Unknown;[];
+ Statement block - Gen - 22 - (0:0,0)
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (0:0,0) - Symbols:1
+ CSharpSymbolType.Transition;[@];
+ MetaCode span - Gen - [{] - SpanEditHandler;Accepts:None - (1:0,1) - Symbols:1
+ CSharpSymbolType.LeftBrace;[{];
+ Markup block - Gen - 20 - (2:0,2)
+ Tag block - Gen - 19 - (2:0,2)
+ Markup span - Gen - [<] - SpanEditHandler;Accepts:Any - (2:0,2) - Symbols:1
+ HtmlSymbolType.OpenAngle;[<];
+ MetaCode span - Gen - [!] - SpanEditHandler;Accepts:None - (3:0,3) - Symbols:1
+ HtmlSymbolType.Bang;[!];
+ Markup span - Gen - [text] - SpanEditHandler;Accepts:Any - (4:0,4) - Symbols:1
+ HtmlSymbolType.Text;[text];
+ Markup block - Gen - 12 - (8:0,8)
+ Markup span - Gen - [ class="] - SpanEditHandler;Accepts:Any - (8:0,8) - Symbols:4
+ HtmlSymbolType.WhiteSpace;[ ];
+ HtmlSymbolType.Text;[class];
+ HtmlSymbolType.Equals;[=];
+ HtmlSymbolType.DoubleQuote;["];
+ Markup span - Gen - [btn] - SpanEditHandler;Accepts:Any - (16:0,16) - Symbols:1
+ HtmlSymbolType.Text;[btn];
+ Markup span - Gen - ["] - SpanEditHandler;Accepts:Any - (19:0,19) - Symbols:1
+ HtmlSymbolType.DoubleQuote;["];
+ Markup span - Gen - [>] - SpanEditHandler;Accepts:None - (20:0,20) - Symbols:1
+ HtmlSymbolType.CloseAngle;[>];
+ Markup span - Gen - [}] - SpanEditHandler;Accepts:Any - (21:0,21) - Symbols:1
+ HtmlSymbolType.Text;[}];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag2.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag2.syntaxtree.txt
new file mode 100644
index 0000000000..a98c6d9160
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag2.syntaxtree.txt
@@ -0,0 +1,43 @@
+Markup block - Gen - 30 - (0:0,0)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (0:0,0) - Symbols:1
+ HtmlSymbolType.Unknown;[];
+ Statement block - Gen - 30 - (0:0,0)
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (0:0,0) - Symbols:1
+ CSharpSymbolType.Transition;[@];
+ MetaCode span - Gen - [{] - SpanEditHandler;Accepts:None - (1:0,1) - Symbols:1
+ CSharpSymbolType.LeftBrace;[{];
+ Markup block - Gen - 27 - (2:0,2)
+ Tag block - Gen - 19 - (2:0,2)
+ Markup span - Gen - [<] - SpanEditHandler;Accepts:Any - (2:0,2) - Symbols:1
+ HtmlSymbolType.OpenAngle;[<];
+ MetaCode span - Gen - [!] - SpanEditHandler;Accepts:None - (3:0,3) - Symbols:1
+ HtmlSymbolType.Bang;[!];
+ Markup span - Gen - [text] - SpanEditHandler;Accepts:Any - (4:0,4) - Symbols:1
+ HtmlSymbolType.Text;[text];
+ Markup block - Gen - 12 - (8:0,8)
+ Markup span - Gen - [ class="] - SpanEditHandler;Accepts:Any - (8:0,8) - Symbols:4
+ HtmlSymbolType.WhiteSpace;[ ];
+ HtmlSymbolType.Text;[class];
+ HtmlSymbolType.Equals;[=];
+ HtmlSymbolType.DoubleQuote;["];
+ Markup span - Gen - [btn] - SpanEditHandler;Accepts:Any - (16:0,16) - Symbols:1
+ HtmlSymbolType.Text;[btn];
+ Markup span - Gen - ["] - SpanEditHandler;Accepts:Any - (19:0,19) - Symbols:1
+ HtmlSymbolType.DoubleQuote;["];
+ Markup span - Gen - [>] - SpanEditHandler;Accepts:None - (20:0,20) - Symbols:1
+ HtmlSymbolType.CloseAngle;[>];
+ Tag block - Gen - 8 - (21:0,21)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (21:0,21) - Symbols:2
+ HtmlSymbolType.OpenAngle;[<];
+ HtmlSymbolType.ForwardSlash;[/];
+ MetaCode span - Gen - [!] - SpanEditHandler;Accepts:None - (23:0,23) - Symbols:1
+ HtmlSymbolType.Bang;[!];
+ Markup span - Gen - [text>] - SpanEditHandler;Accepts:None - (24:0,24) - Symbols:2
+ HtmlSymbolType.Text;[text];
+ HtmlSymbolType.CloseAngle;[>];
+ Code span - Gen - [] - SpanEditHandler;Accepts:Any - (29:0,29) - Symbols:1
+ CSharpSymbolType.Unknown;[];
+ MetaCode span - Gen - [}] - SpanEditHandler;Accepts:None - (29:0,29) - Symbols:1
+ CSharpSymbolType.RightBrace;[}];
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (30:0,30) - Symbols:1
+ HtmlSymbolType.Unknown;[];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag3.syntaxtree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag3.syntaxtree.txt
new file mode 100644
index 0000000000..233ad07deb
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/TagHelperParseTreeRewriterTest/Rewrite_AllowsTagHelperElementOptForCompleteTextTagInCSharpBlock_WithAttributeTextTag3.syntaxtree.txt
@@ -0,0 +1,49 @@
+Markup block - Gen - 47 - (0:0,0)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (0:0,0) - Symbols:1
+ HtmlSymbolType.Unknown;[];
+ Statement block - Gen - 47 - (0:0,0)
+ Transition span - Gen