diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperBlockRewriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperBlockRewriterTest.cs
index 06131ae599..440b9486cd 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperBlockRewriterTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperBlockRewriterTest.cs
@@ -3,320 +3,141 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
public class TagHelperBlockRewriterTest : TagHelperRewritingTestBase
{
- public static TheoryData SymbolBoundAttributeData
+ public TagHelperBlockRewriterTest()
{
- get
- {
- var factory = new SpanFactory();
-
- return new TheoryData
- {
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("ul",
- attributes: new List
- {
- new TagHelperAttributeNode("bound", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode(
- "[item]",
- factory.CodeMarkup("items").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes)
- }))
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("ul",
- attributes: new List
- {
- new TagHelperAttributeNode("bound", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode(
- "[(item)]",
- factory.CodeMarkup("items").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes)
- }))
- },
- {
- "Click Me ",
- new MarkupBlock(
- new MarkupTagHelperBlock("button",
- attributes: new List
- {
- new TagHelperAttributeNode("bound", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode(
- "(click)",
- factory.CodeMarkup("doSomething()").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes)
- },
- children: factory.Markup("Click Me")))
- },
- {
- "Click Me ",
- new MarkupBlock(
- new MarkupTagHelperBlock("button",
- attributes: new List
- {
- new TagHelperAttributeNode("bound", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode(
- "(^click)",
- factory.CodeMarkup("doSomething()").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes)
- },
- children: factory.Markup("Click Me")))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("template",
- attributes: new List
- {
- new TagHelperAttributeNode("bound", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode(
- "*something",
- factory.Markup("value"),
- AttributeStructure.SingleQuotes)
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("div",
- attributes: new List
- {
- new TagHelperAttributeNode("bound", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("#localminimized", null, AttributeStructure.Minimized)
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("div",
- attributes: new List
- {
- new TagHelperAttributeNode("bound", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("#local", factory.Markup("value"), AttributeStructure.SingleQuotes)
- }))
- },
- };
- }
+ UseBaselineTests = true;
}
- [Theory]
- [MemberData(nameof(SymbolBoundAttributeData))]
- public void Rewrite_CanHandleSymbolBoundAttributes(string documentContent, object expectedOutput)
+ public static TagHelperDescriptor[] SymbolBoundAttributes_Descriptors = new[]
{
- // Arrange
- var descriptors = new[]
- {
- TagHelperDescriptorBuilder.Create("CatchAllTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("*")
- .RequireAttributeDescriptor(attribute => attribute.Name("bound")))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("[item]")
- .PropertyName("ListItems")
- .TypeName(typeof(List).Namespace + "List"))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("[(item)]")
- .PropertyName("ArrayItems")
- .TypeName(typeof(string[]).Namespace + "System.String[]"))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("(click)")
- .PropertyName("Event1")
- .TypeName(typeof(Action).FullName))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("(^click)")
- .PropertyName("Event2")
- .TypeName(typeof(Action).FullName))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("*something")
- .PropertyName("StringProperty1")
- .TypeName(typeof(string).FullName))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("#local")
- .PropertyName("StringProperty2")
- .TypeName(typeof(string).FullName))
- .Build()
- };
+ TagHelperDescriptorBuilder.Create("CatchAllTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("*")
+ .RequireAttributeDescriptor(attribute => attribute.Name("bound")))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("[item]")
+ .PropertyName("ListItems")
+ .TypeName(typeof(List).Namespace + "List"))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("[(item)]")
+ .PropertyName("ArrayItems")
+ .TypeName(typeof(string[]).Namespace + "System.String[]"))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("(click)")
+ .PropertyName("Event1")
+ .TypeName(typeof(Action).FullName))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("(^click)")
+ .PropertyName("Event2")
+ .TypeName(typeof(Action).FullName))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("*something")
+ .PropertyName("StringProperty1")
+ .TypeName(typeof(string).FullName))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("#local")
+ .PropertyName("StringProperty2")
+ .TypeName(typeof(string).FullName))
+ .Build()
+ };
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ [Fact]
+ public void Rewrite_CanHandleSymbolBoundAttributes1()
+ {
+ EvaluateData(SymbolBoundAttributes_Descriptors, "");
}
- public static TheoryData WithoutEndTagElementData
+ [Fact]
+ public void Rewrite_CanHandleSymbolBoundAttributes2()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- // documentContent, expectedOutput
- return new TheoryData
- {
- {
- " ",
- new MarkupBlock(new MarkupTagHelperBlock("input", TagMode.StartTagOnly))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.StartTagOnly,
- attributes: new List
- {
- new TagHelperAttributeNode("type", factory.Markup("text"), AttributeStructure.SingleQuotes)
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly),
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.StartTagOnly,
- attributes: new List
- {
- new TagHelperAttributeNode("type", factory.Markup("text"), AttributeStructure.SingleQuotes)
- }),
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly))
- },
- {
- "
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly),
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly),
- blockFactory.MarkupTagBlock("
"))
- },
- };
- }
+ EvaluateData(SymbolBoundAttributes_Descriptors, "");
}
- [Theory]
- [MemberData(nameof(WithoutEndTagElementData))]
- public void Rewrite_CanHandleWithoutEndTagTagStructure(string documentContent, object expectedOutput)
+ [Fact]
+ public void Rewrite_CanHandleSymbolBoundAttributes3()
{
- // Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("InputTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("input")
- .RequireTagStructure(TagStructure.WithoutEndTag))
- .Build()
- };
-
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ EvaluateData(SymbolBoundAttributes_Descriptors, "Click Me ");
}
- public static TheoryData TagStructureCompatibilityData
+ [Fact]
+ public void Rewrite_CanHandleSymbolBoundAttributes4()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- // documentContent, structure1, structure2, expectedOutput
- return new TheoryData
- {
- {
- " ",
- TagStructure.Unspecified,
- TagStructure.Unspecified,
- new MarkupBlock(new MarkupTagHelperBlock("input", TagMode.StartTagAndEndTag))
- },
- {
- " ",
- TagStructure.Unspecified,
- TagStructure.Unspecified,
- new MarkupBlock(new MarkupTagHelperBlock("input", TagMode.SelfClosing))
- },
- {
- " ",
- TagStructure.Unspecified,
- TagStructure.WithoutEndTag,
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.StartTagOnly,
- attributes: new List
- {
- new TagHelperAttributeNode("type", factory.Markup("text"), AttributeStructure.SingleQuotes)
- }))
- },
- {
- " ",
- TagStructure.WithoutEndTag,
- TagStructure.WithoutEndTag,
- new MarkupBlock(
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly),
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly))
- },
- {
- " ",
- TagStructure.Unspecified,
- TagStructure.NormalOrSelfClosing,
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.StartTagAndEndTag,
- attributes: new List
- {
- new TagHelperAttributeNode("type", factory.Markup("text"), AttributeStructure.SingleQuotes)
- }))
- },
- {
- " ",
- TagStructure.Unspecified,
- TagStructure.WithoutEndTag,
- new MarkupBlock(new MarkupTagHelperBlock("input", TagMode.SelfClosing))
- },
-
- {
- " ",
- TagStructure.NormalOrSelfClosing,
- TagStructure.Unspecified,
- new MarkupBlock(new MarkupTagHelperBlock("input", TagMode.SelfClosing))
- },
- };
- }
+ EvaluateData(SymbolBoundAttributes_Descriptors, "Click Me ");
}
- [Theory]
- [MemberData(nameof(TagStructureCompatibilityData))]
- public void Rewrite_AllowsCompatibleTagStructures(
- string documentContent,
- TagStructure structure1,
- TagStructure structure2,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_CanHandleSymbolBoundAttributes5()
+ {
+ EvaluateData(SymbolBoundAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CanHandleSymbolBoundAttributes6()
+ {
+ EvaluateData(SymbolBoundAttributes_Descriptors, "
");
+ }
+
+ [Fact]
+ public void Rewrite_CanHandleSymbolBoundAttributes7()
+ {
+ EvaluateData(SymbolBoundAttributes_Descriptors, "
");
+ }
+
+ public static TagHelperDescriptor[] WithoutEndTag_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("InputTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("input")
+ .RequireTagStructure(TagStructure.WithoutEndTag))
+ .Build()
+ };
+
+ [Fact]
+ public void Rewrite_CanHandleWithoutEndTagTagStructure1()
+ {
+ EvaluateData(WithoutEndTag_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CanHandleWithoutEndTagTagStructure2()
+ {
+ EvaluateData(WithoutEndTag_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CanHandleWithoutEndTagTagStructure3()
+ {
+ EvaluateData(WithoutEndTag_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CanHandleWithoutEndTagTagStructure4()
+ {
+ EvaluateData(WithoutEndTag_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CanHandleWithoutEndTagTagStructure5()
+ {
+ EvaluateData(WithoutEndTag_Descriptors, "
");
+ }
+
+ public static TagHelperDescriptor[] GetTagStructureCompatibilityDescriptors(TagStructure structure1, TagStructure structure2)
{
- // Arrange
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("InputTagHelper1", "SomeAssembly")
@@ -333,3576 +154,1933 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
.Build()
};
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ return descriptors;
}
- public static TheoryData MalformedTagHelperAttributeBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- Func createInvalidDoBlock = extraCode =>
- {
- return new MarkupBlock(
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- string.Empty,
- new SourceLocation(10, 0, 10)),
- new SourceLocation(10, 0, 10)),
- new StatementBlock(
- factory.CodeTransition(),
- factory.Code("do {" + extraCode).AsStatement())));
- };
-
- return new TheoryData
- {
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode(
- "bar",
- new MarkupBlock(factory.Markup("false"), factory.Markup(" ")),
- AttributeStructure.SingleQuotes)
- })),
- 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(
- "bar",
- new MarkupBlock(
- factory.Markup("false"),
- factory.Markup("
- {
- new TagHelperAttributeNode(
- "bar",
- factory.Markup("false"),
- AttributeStructure.NoQuotes)
- })),
- 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"),
- RazorDiagnosticFactory.CreateParsing_TagHelperAttributeListMustBeWellFormed(
- new SourceSpan(12, 0, 12, 1))
- }
- },
- {
- "
- {
- new TagHelperAttributeNode(
- "bar",
- factory.Markup("false'"))
- })),
- 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",
- new List
- {
- new TagHelperAttributeNode(
- "bar",
- new MarkupBlock(
- factory.Markup("false'"),
- factory.Markup(" >
")))
- })),
- 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",
- new List
- {
- new TagHelperAttributeNode("foo", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bar", null, AttributeStructure.Minimized)
- },
- new MarkupTagHelperBlock("strong"))),
- 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"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(11, 0, 11), contentLength: 6), "strong"),
- }
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.NoQuotes)
- })),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.NoQuotes)
- })),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode(
- "class",
- new MarkupBlock(factory.Markup("btn"), factory.Markup(" bar="))),
- new TagHelperAttributeNode("foo", null, AttributeStructure.Minimized)
- },
- new MarkupTagHelperBlock("strong"))),
- 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"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(24, 0, 24), contentLength: 6), "strong")
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode(
- "class",
- new MarkupBlock(factory.Markup("btn"), factory.Markup(" bar="))),
- new TagHelperAttributeNode("foo", null, AttributeStructure.Minimized),
- })),
- new RazorDiagnostic[0]
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p")),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelpersCannotHaveCSharpInTagDeclaration(new SourceSpan(3, 0, 3, 13), "p")
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p")),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelpersCannotHaveCSharpInTagDeclaration(new SourceSpan(3, 0, 3, 13), "p")
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode(
- "class",
- new MarkupBlock(
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- string.Empty,
- new SourceLocation(9, 0, 9)),
- new SourceLocation(9, 0, 9)),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace)))),
- AttributeStructure.DoubleQuotes)
- })),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- },
- {
- "
- {
- new TagHelperAttributeNode(
- "class",
- createInvalidDoBlock(string.Empty))
- })),
- 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"),
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(11, 0, 11), contentLength: 1), "do", "}", "{"),
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", createInvalidDoBlock("\">
"))
- })),
- 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"),
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(11, 0, 11), contentLength: 1), "do", "}", "{"),
- RazorDiagnosticFactory.CreateParsing_UnterminatedStringLiteral(
- new SourceSpan(filePath: null, absoluteIndex: 15, lineIndex: 0, characterIndex: 15, length: 1))
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p")),
- 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"),
- RazorDiagnosticFactory.CreateParsing_TagHelpersCannotHaveCSharpInTagDeclaration(new SourceSpan(3, 0, 3, 30), "p"),
- RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
- new SourceSpan(new SourceLocation(4, 0, 4), contentLength: 1), "do", "}", "{"),
- RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 31, lineIndex: 0, characterIndex: 31, length: 1), "p")
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("some"), AttributeStructure.NoQuotes)
- })),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperAttributeListMustBeWellFormed(new SourceSpan(13, 0, 13, 13))
- }
- },
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(MalformedTagHelperAttributeBlockData))]
- public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors, "strong", "p");
- }
-
- public static TheoryData MalformedTagHelperBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- return new TheoryData
- {
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("strong",
- new MarkupTagHelperBlock("p"))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 6), "strong"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 6), "strong"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(9, 0, 9), contentLength: 1), "p")
- }
- },
- {
- " <",
- new MarkupBlock(
- blockFactory.MarkupTagBlock("<"),
- blockFactory.MarkupTagBlock("<"),
- blockFactory.MarkupTagBlock("
"),
- factory.Markup(" "),
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p")),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(4, 0, 4), contentLength: 6), "strong"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(14, 0, 14), contentLength: 1), "p")
- }
- },
- {
- "<<> <<>>",
- new MarkupBlock(
- blockFactory.MarkupTagBlock("<"),
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("strong",
- factory.Markup("> "),
- blockFactory.MarkupTagBlock("<"),
- blockFactory.MarkupTagBlock("<>"),
- factory.Markup(">"))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(3, 0, 3), contentLength: 6), "strong")
- }
- },
- {
- "
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""))),
- new []
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(14, 0, 14), contentLength: 1), "p")
- }
- }
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(MalformedTagHelperBlockData))]
- public void Rewrite_CreatesErrorForMalformedTagHelper(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors, "strong", "p");
- }
-
- public static TheoryData CodeTagHelperAttributesData
- {
- get
- {
- var factory = new SpanFactory();
- var dateTimeNow = new MarkupBlock(
- factory.Markup(" "),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace)));
-
- return new TheoryData
- {
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("age", factory.CodeMarkup("12").With(new ExpressionChunkGenerator()))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "birthday",
- factory.CodeMarkup("DateTime.Now").With(new ExpressionChunkGenerator()))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "age",
- new MarkupBlock(
- new MarkupBlock(
- new ExpressionBlock(
- factory.CodeTransition(),
- factory
- .CSharpCodeMarkup("DateTime.Now.Year")
- .With(new ExpressionChunkGenerator())))))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "age",
- new MarkupBlock(
- new MarkupBlock(
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator()),
- new ExpressionBlock(
- factory.CSharpCodeMarkup("@").With(new ExpressionChunkGenerator()),
- factory
- .CSharpCodeMarkup("DateTime.Now.Year")
- .With(new ExpressionChunkGenerator())))))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("name", factory.Markup("John"))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "name",
- new MarkupBlock(factory.Markup("Time:"), dateTimeNow))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "age",
- new MarkupBlock(
- factory.CodeMarkup("1").With(new ExpressionChunkGenerator()),
- factory.CodeMarkup(" +").With(new ExpressionChunkGenerator()),
- new MarkupBlock(
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator()),
- new ExpressionBlock(
- factory.CSharpCodeMarkup("@").With(new ExpressionChunkGenerator()),
- factory.CSharpCodeMarkup("value")
- .With(new ExpressionChunkGenerator()))),
- factory.CodeMarkup(" +").With(new ExpressionChunkGenerator()),
- factory.CodeMarkup(" 2").With(new ExpressionChunkGenerator()))),
- new TagHelperAttributeNode(
- "birthday",
- new MarkupBlock(
- factory.CodeMarkup("(bool)").With(new ExpressionChunkGenerator()),
- new MarkupBlock(
- new ExpressionBlock(
- factory.CSharpCodeMarkup("@").With(new ExpressionChunkGenerator()),
- factory
- .CSharpCodeMarkup("Bag[\"val\"]")
- .With(new ExpressionChunkGenerator()))),
- factory.CodeMarkup(" ?").With(new ExpressionChunkGenerator()),
- new MarkupBlock(
- factory.CodeMarkup(" @").With(new ExpressionChunkGenerator())
- .As(SpanKindInternal.Code),
- factory.CodeMarkup("@").With(SpanChunkGenerator.Null)
- .As(SpanKindInternal.Code)),
- factory.CodeMarkup("DateTime").With(new ExpressionChunkGenerator()),
- factory.CodeMarkup(" :").With(new ExpressionChunkGenerator()),
- new MarkupBlock(
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator()),
- new ExpressionBlock(
- factory.CSharpCodeMarkup("@").With(new ExpressionChunkGenerator()),
- factory
- .CSharpCodeMarkup("DateTime.Now")
- .With(new ExpressionChunkGenerator())))),
- AttributeStructure.SingleQuotes)
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("age", factory.CodeMarkup("12").With(new ExpressionChunkGenerator())),
- new TagHelperAttributeNode(
- "birthday",
- factory.CodeMarkup("DateTime.Now").With(new ExpressionChunkGenerator())),
- new TagHelperAttributeNode(
- "name",
- new MarkupBlock(factory.Markup("Time:"), dateTimeNow))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("age", factory.CodeMarkup("12").With(new ExpressionChunkGenerator())),
- new TagHelperAttributeNode(
- "birthday",
- factory.CodeMarkup("DateTime.Now").With(new ExpressionChunkGenerator())),
- new TagHelperAttributeNode(
- "name",
- new MarkupBlock(
- factory.Markup("Time:"),
- new MarkupBlock(
- factory.Markup(" @").Accepts(AcceptedCharactersInternal.None),
- factory.Markup("@")
- .With(SpanChunkGenerator.Null)
- .Accepts(AcceptedCharactersInternal.None)),
- dateTimeNow))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("age", factory.CodeMarkup("12").With(new ExpressionChunkGenerator())),
- new TagHelperAttributeNode(
- "birthday",
- factory.CodeMarkup("DateTime.Now").With(new ExpressionChunkGenerator())),
- new TagHelperAttributeNode(
- "name",
- new MarkupBlock(
- new MarkupBlock(
- factory.Markup("@").Accepts(AcceptedCharactersInternal.None),
- factory.Markup("@")
- .With(SpanChunkGenerator.Null)
- .Accepts(AcceptedCharactersInternal.None)),
- factory.Markup("BoundStringAttribute")))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("person",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "age",
- new MarkupBlock(
- new MarkupBlock(
- factory.CodeMarkup("@").With(new ExpressionChunkGenerator()),
- factory.CodeMarkup("@").With(SpanChunkGenerator.Null)),
- new MarkupBlock(
- factory.EmptyHtml()
- .AsCodeMarkup().With(new ExpressionChunkGenerator())
- .As(SpanKindInternal.Code),
- new ExpressionBlock(
- factory.CSharpCodeMarkup("@").With(new ExpressionChunkGenerator()),
- factory.CSharpCodeMarkup("(").With(new ExpressionChunkGenerator()),
- factory.CSharpCodeMarkup("11+1")
- .With(new ExpressionChunkGenerator()),
- factory.CSharpCodeMarkup(")").With(new ExpressionChunkGenerator()))))),
- new TagHelperAttributeNode(
- "birthday",
- factory.CodeMarkup("DateTime.Now").With(new ExpressionChunkGenerator())),
- new TagHelperAttributeNode(
- "name",
- new MarkupBlock(factory.Markup("Time:"), dateTimeNow))
- }))
- },
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(CodeTagHelperAttributesData))]
- public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_AllowsCompatibleTagStructures1()
{
// Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("PersonTagHelper", "personAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("person"))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("age")
- .PropertyName("Age")
- .TypeName(typeof(int).FullName))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("birthday")
- .PropertyName("BirthDay")
- .TypeName(typeof(DateTime).FullName))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("name")
- .PropertyName("Name")
- .TypeName(typeof(string).FullName))
- .Build()
- };
+ var descriptors = GetTagStructureCompatibilityDescriptors(TagStructure.Unspecified, TagStructure.Unspecified);
// Act & Assert
- EvaluateData(
- descriptors,
- documentContent,
- (MarkupBlock)expectedOutput,
- expectedErrors: Enumerable.Empty());
+ EvaluateData(descriptors, " ");
}
- public static IEnumerable IncompleteHelperBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- yield return new object[]
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"), AttributeStructure.NoQuotes),
- new TagHelperAttributeNode(
- "dynamic",
- new MarkupBlock(
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- string.Empty,
- new SourceLocation(21, 0, 21)),
- new SourceLocation(21, 0, 21)),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace)))),
- AttributeStructure.DoubleQuotes),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"), AttributeStructure.NoQuotes)
- },
- new MarkupTagHelperBlock("strong")),
- blockFactory.MarkupTagBlock("")),
- new RazorDiagnostic[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 53, lineIndex: 0, characterIndex: 53, length: 6), "strong"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 66, lineIndex: 0, characterIndex: 66, length: 6), "strong")
- }
- };
- yield return new object[]
- {
- "",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello "),
- new MarkupTagHelperBlock("strong",
- factory.Markup("World")),
- blockFactory.MarkupTagBlock("
"))),
- new RazorDiagnostic[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 6, lineIndex: 0, characterIndex: 6, length: 1), "p")
- }
- };
- yield return new object[]
- {
- "",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello "),
- new MarkupTagHelperBlock("strong",
- factory.Markup("World"),
- blockFactory.MarkupTagBlock("
")))),
- new RazorDiagnostic[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 6, lineIndex: 0, characterIndex: 6, length: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(absoluteIndex: 15, lineIndex: 0, characterIndex: 15, length: 6), "strong")
- }
- };
- yield return new object[]
- {
- "Hello
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"))
- },
- factory.Markup("Hello "),
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- },
- factory.Markup("World")))),
- new RazorDiagnostic[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p")
- }
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(IncompleteHelperBlockData))]
- public void TagHelperParseTreeRewriter_CreatesErrorForIncompleteTagHelper(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors, "strong", "p");
- }
-
-
- public static IEnumerable OddlySpacedBlockData
- {
- get
- {
- var factory = new SpanFactory();
-
- yield return new object[]
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup(" foo")),
- new TagHelperAttributeNode(
- "style",
- new MarkupBlock(
- factory.Markup(" color"),
- factory.Markup(" :"),
- factory.Markup(" red"),
- factory.Markup(" ;"),
- factory.Markup(" ")))
- }))
- };
- yield return new object[]
- {
- "Hello World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup(" foo")),
- new TagHelperAttributeNode(
- "style",
- new MarkupBlock(
- factory.Markup(" color"),
- factory.Markup(" :"),
- factory.Markup(" red"),
- factory.Markup(" ;"),
- factory.Markup(" ")))
- },
- factory.Markup("Hello World")))
- };
- yield return new object[]
- {
- "Hello
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode(
- "class",
- new MarkupBlock(factory.Markup(" foo"), factory.Markup(" ")))
- },
- factory.Markup("Hello")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode(
- "style",
- new MarkupBlock(factory.Markup(" color:red;"), factory.Markup(" ")))
- },
- factory.Markup("World")))
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(OddlySpacedBlockData))]
- public void TagHelperParseTreeRewriter_RewritesOddlySpacedTagHelperTagBlocks(
- string documentContent,
- object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p");
- }
-
- public static IEnumerable ComplexAttributeTagHelperBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var dateTimeNowString = "@DateTime.Now";
- var dateTimeNow = new Func(index =>
- new MarkupBlock(
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- string.Empty,
- new SourceLocation(index, 0, index)),
- new SourceLocation(index, 0, index)),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace)))));
- var doWhileString = "@do { var foo = bar; Foo foo++; } while (foo);";
- var doWhile = new Func(index =>
- new MarkupBlock(
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- string.Empty,
- new SourceLocation(index, 0, index)),
- new SourceLocation(index, 0, index)),
- new StatementBlock(
- factory.CodeTransition(),
- factory.Code("do { var foo = bar; ").AsStatement(),
- new MarkupBlock(
- new MarkupTagBlock(
- factory.MarkupTransition("")),
- factory.Markup("Foo").Accepts(AcceptedCharactersInternal.None),
- new MarkupTagBlock(
- factory.MarkupTransition(" "))),
- factory
- .Code(" foo++; } while (foo);")
- .AsStatement()
- .Accepts(AcceptedCharactersInternal.None)))));
-
- var currentFormattedString = "
";
- yield return new object[]
- {
- string.Format(currentFormattedString, dateTimeNowString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", dateTimeNow(10)),
- new TagHelperAttributeNode("style", dateTimeNow(32), AttributeStructure.SingleQuotes)
- }))
- };
- yield return new object[]
- {
- string.Format(currentFormattedString, doWhileString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", doWhile(10)),
- new TagHelperAttributeNode("style", doWhile(83), AttributeStructure.SingleQuotes)
- }))
- };
-
- currentFormattedString = "Hello World
";
- yield return new object[]
- {
- string.Format(currentFormattedString, dateTimeNowString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", dateTimeNow(10)),
- new TagHelperAttributeNode("style", dateTimeNow(32), AttributeStructure.SingleQuotes)
- },
- factory.Markup("Hello World")))
- };
- yield return new object[]
- {
- string.Format(currentFormattedString, doWhileString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", doWhile(10)),
- new TagHelperAttributeNode("style", doWhile(83), AttributeStructure.SingleQuotes)
- },
- factory.Markup("Hello World")))
- };
-
- currentFormattedString = "Hello
World
";
- yield return new object[]
- {
- string.Format(currentFormattedString, dateTimeNowString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", dateTimeNow(10))
- },
- factory.Markup("Hello")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("style", dateTimeNow(45), AttributeStructure.SingleQuotes)
- },
- factory.Markup("World")))
- };
- yield return new object[]
- {
- string.Format(currentFormattedString, doWhileString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", doWhile(10))
- },
- factory.Markup("Hello")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("style", doWhile(96), AttributeStructure.SingleQuotes)
- },
- factory.Markup("World")))
- };
-
- currentFormattedString =
- "Hello World inside of strong tag
";
- yield return new object[]
- {
- string.Format(currentFormattedString, dateTimeNowString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", dateTimeNow(10)),
- new TagHelperAttributeNode("style", dateTimeNow(32), AttributeStructure.SingleQuotes)
- },
- factory.Markup("Hello World "),
- new MarkupTagBlock(
- factory.Markup("(" class=\"", 66, 0, 66),
- suffix: new LocationTagged("\"", 87, 0, 87)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(string.Empty, 74, 0, 74), 74, 0, 74),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">")),
- factory.Markup("inside of strong tag"),
- blockFactory.MarkupTagBlock(" ")))
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(ComplexAttributeTagHelperBlockData))]
- public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks(
- string documentContent,
- object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p");
- }
-
- public static IEnumerable ComplexTagHelperBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var dateTimeNowString = "@DateTime.Now";
- var dateTimeNow = new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace));
- var doWhileString = "@do { var foo = bar; Foo
foo++; } while (foo);";
- var doWhile = new StatementBlock(
- factory.CodeTransition(),
- factory.Code("do { var foo = bar;").AsStatement(),
- new MarkupBlock(
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- factory.Markup("Foo")),
- factory.Markup(" ").Accepts(AcceptedCharactersInternal.None)),
- factory.Code("foo++; } while (foo);")
- .AsStatement()
- .Accepts(AcceptedCharactersInternal.None));
-
- var currentFormattedString = "{0}
";
- yield return new object[]
- {
- string.Format(currentFormattedString, dateTimeNowString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p", dateTimeNow))
- };
- yield return new object[]
- {
- string.Format(currentFormattedString, doWhileString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p", doWhile))
- };
-
- currentFormattedString = "Hello World {0}
";
- yield return new object[]
- {
- string.Format(currentFormattedString, dateTimeNowString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello World "),
- dateTimeNow))
- };
- yield return new object[]
- {
- string.Format(currentFormattedString, doWhileString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello World "),
- doWhile))
- };
-
- currentFormattedString = "{0}
{0}
";
- yield return new object[]
- {
- string.Format(currentFormattedString, dateTimeNowString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p", dateTimeNow),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p", dateTimeNow))
- };
- yield return new object[]
- {
- string.Format(currentFormattedString, doWhileString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p", doWhile),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p", doWhile))
- };
-
- currentFormattedString = "Hello {0}inside of {0} strong tag
";
- yield return new object[]
- {
- string.Format(currentFormattedString, dateTimeNowString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello "),
- dateTimeNow,
- blockFactory.MarkupTagBlock(""),
- factory.Markup("inside of "),
- dateTimeNow,
- factory.Markup(" strong tag"),
- blockFactory.MarkupTagBlock(" ")))
- };
- yield return new object[]
- {
- string.Format(currentFormattedString, doWhileString),
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello "),
- doWhile,
- blockFactory.MarkupTagBlock(""),
- factory.Markup("inside of "),
- doWhile,
- factory.Markup(" strong tag"),
- blockFactory.MarkupTagBlock(" ")))
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(ComplexTagHelperBlockData))]
- public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks(
- string documentContent,
- object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p");
- }
-
-
- public static TheoryData InvalidHtmlBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var dateTimeNow = new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace));
-
- return new TheoryData
- {
- {
- "<<>>
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock("<"),
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p",
- factory.Markup(">>")))
- },
- {
- "<
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p", TagMode.SelfClosing))
- },
- {
- "< p />",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- new MarkupBlock(
- factory.Markup(" p")),
- factory.Markup(" />")))
- },
- {
- " ",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(" ",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("<"),
- new MarkupBlock(
- new AttributeBlockChunkGenerator(
- name: "class",
- prefix: new LocationTagged(" class=\"", 1, 0, 1),
- suffix: new LocationTagged("\"", 12, 0, 12)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("foo").With(new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 9, 0, 9),
- value: new LocationTagged("foo", 9, 0, 9))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(" ")),
- new MarkupTagHelperBlock("p", TagMode.SelfClosing))
- },
- {
- "</>
>",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p",
- factory.Markup("/>")),
- factory.Markup(">"))
- },
- {
- "</>
>",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p",
- factory.Markup("/>"),
- blockFactory.MarkupTagBlock("")),
- factory.Markup(">"))
- },
- {
- "<@DateTime.Now/>
>",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p",
- dateTimeNow,
- factory.Markup("/>"),
- blockFactory.MarkupTagBlock("")),
- factory.Markup(">"))
- },
- {
- " /< >@DateTime.Now / >
>",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(" "),
- factory.Markup("/"),
- blockFactory.MarkupTagBlock("< >"),
- new MarkupTagHelperBlock("p",
- dateTimeNow,
- factory.Markup(" / >"),
- blockFactory.MarkupTagBlock("")),
- blockFactory.MarkupTagBlock(" >"))
- },
- {
- "< @DateTime.Now > @DateTime.Now >
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagBlock(
- factory.Markup("< "),
- dateTimeNow,
- factory.Markup(" >")),
- blockFactory.MarkupTagBlock(" "),
- dateTimeNow,
- factory.Markup(" >")))
- }
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(InvalidHtmlBlockData))]
- public void TagHelperParseTreeRewriter_AllowsInvalidHtml(string documentContent, object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p");
- }
-
- public static TheoryData EmptyAttributeTagHelperData
- {
- get
- {
- var factory = new SpanFactory();
-
- // documentContent, expectedOutput
- return new TheoryData
- {
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", new MarkupBlock())
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", new MarkupBlock(), AttributeStructure.SingleQuotes)
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- // We expected a markup node here because attribute values without quotes can only ever
- // be a single item, hence don't need to be enclosed by a block.
- new TagHelperAttributeNode(
- "class",
- factory.Markup("").With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes),
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class1", new MarkupBlock(), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode(
- "class2",
- factory.Markup(string.Empty).With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes),
- new TagHelperAttributeNode("class3", new MarkupBlock()),
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class1", new MarkupBlock(), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("class2", new MarkupBlock()),
- new TagHelperAttributeNode(
- "class3",
- factory.Markup(string.Empty).With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes),
- }))
- },
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(EmptyAttributeTagHelperData))]
- public void Rewrite_UnderstandsEmptyAttributeTagHelpers(string documentContent, object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, new RazorDiagnostic[0], "p");
- }
-
- public static TheoryData EmptyTagHelperBoundAttributeData
- {
- get
- {
- var factory = new SpanFactory();
- var boolTypeName = typeof(bool).FullName;
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("bound", new MarkupBlock(), AttributeStructure.SingleQuotes)
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "bound",
- "myth",
- boolTypeName)
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup(" true").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes)
- })),
- new RazorDiagnostic[0]
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes)
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "bound",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("bound", new MarkupBlock(), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound", new MarkupBlock())
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "bound",
- "myth",
- boolTypeName),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(16, 0, 16, 5),
- "bound",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup(" "))
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "bound",
- "myth",
- boolTypeName),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(17, 0, 17, 5),
- "bound",
- "myth",
- boolTypeName),
- }
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup("true").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup(string.Empty).With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes)
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(19, 0, 19, 5),
- "bound",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup(string.Empty).With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes),
- new TagHelperAttributeNode("name", new MarkupBlock(), AttributeStructure.SingleQuotes)
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "bound",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup(string.Empty).With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes),
- new TagHelperAttributeNode("name", factory.Markup(" "), AttributeStructure.SingleQuotes)
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "bound",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup("true").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("name", factory.Markup("john"), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode(
- "bound",
- factory.CodeMarkup(string.Empty).With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes),
- new TagHelperAttributeNode(
- "name",
- factory.Markup(string.Empty).With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes)
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(31, 0, 31, 5),
- "bound",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("BouND", new MarkupBlock(), AttributeStructure.SingleQuotes)
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "BouND",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("BOUND", new MarkupBlock(), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bOUnd", new MarkupBlock())
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "BOUND",
- "myth",
- boolTypeName),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(18, 0, 18, 5),
- "bOUnd",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- new List
- {
- new TagHelperAttributeNode(
- "BOUND",
- factory.CodeMarkup(string.Empty).With(SpanChunkGenerator.Null),
- AttributeStructure.DoubleQuotes),
- new TagHelperAttributeNode("nAMe", factory.Markup("john"), AttributeStructure.SingleQuotes)
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 5),
- "BOUND",
- "myth",
- boolTypeName),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- {
- new TagHelperAttributeNode(
- "bound",
- new MarkupBlock(
- new MarkupBlock(
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator()),
- new ExpressionBlock(
- factory.CSharpCodeMarkup("@").With(new ExpressionChunkGenerator()),
- factory.CSharpCodeMarkup("true")
- .With(new ExpressionChunkGenerator()))),
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator())),
- AttributeStructure.SingleQuotes)
- }
- })),
- new RazorDiagnostic[0]
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "myth",
- TagMode.SelfClosing,
- attributes: new List
- {
- {
- new TagHelperAttributeNode(
- "bound",
- new MarkupBlock(
- new MarkupBlock(
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator()),
- new ExpressionBlock(
- factory.CSharpCodeMarkup("@").With(new ExpressionChunkGenerator()),
- factory.CSharpCodeMarkup("(").With(new ExpressionChunkGenerator()),
- factory.CSharpCodeMarkup("true")
- .With(new ExpressionChunkGenerator()),
- factory.CSharpCodeMarkup(")").With(new ExpressionChunkGenerator()))),
- factory.CodeMarkup(" ").With(new ExpressionChunkGenerator())),
- AttributeStructure.SingleQuotes)
- }
- })),
- new RazorDiagnostic[0]
- },
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(EmptyTagHelperBoundAttributeData))]
- public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_AllowsCompatibleTagStructures2()
{
// Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("mythTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("myth"))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("bound")
- .PropertyName("Bound")
- .TypeName(typeof(bool).FullName))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("name")
- .PropertyName("Name")
- .TypeName(typeof(string).FullName))
- .Build()
- };
+ var descriptors = GetTagStructureCompatibilityDescriptors(TagStructure.Unspecified, TagStructure.Unspecified);
// Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors);
+ EvaluateData(descriptors, " ");
}
- public static IEnumerable ScriptBlockData
- {
- get
- {
- var factory = new SpanFactory();
-
- yield return new object[]
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("script",
- factory.Markup("",
- new MarkupBlock(
- new MarkupTagHelperBlock("script",
- factory.Markup("Hello World
")))
- };
- yield return new object[]
- {
- "
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("script",
- factory.Markup("Hello
")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("div",
- factory.Markup("World"))))
- };
- yield return new object[]
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("script",
- factory.Markup("Hello ")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("script",
- factory.Markup("World ")))
- };
- yield return new object[]
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("script",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo")),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- }))
- };
- yield return new object[]
- {
- "Hello World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello "),
- new MarkupTagHelperBlock("script",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo")),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- }),
- factory.Markup(" World")))
- };
- yield return new object[]
- {
- "Hello World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello "),
- new MarkupTagHelperBlock("script",
- new List
- {
- new TagHelperAttributeNode(
- "class",
- new MarkupBlock(
- new MarkupBlock(
- factory.Markup("@").Accepts(AcceptedCharactersInternal.None),
- factory.Markup("@").With(SpanChunkGenerator.Null).Accepts(AcceptedCharactersInternal.None)),
- factory.Markup("foo@bar.com"))),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- }),
- factory.Markup(" World")))
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(ScriptBlockData))]
- public void TagHelperParseTreeRewriter_RewritesScriptTagHelpers(
- string documentContent,
- object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p", "div", "script");
- }
-
- public static IEnumerable SelfClosingBlockData
- {
- get
- {
- var factory = new SpanFactory();
-
- yield return new object[]
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo")),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- }))
- };
- yield return new object[]
- {
- "Hello
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- children: new SyntaxTreeNode[]
- {
- factory.Markup("Hello "),
- new MarkupTagHelperBlock(
- "p",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo")),
- new TagHelperAttributeNode(
- "style",
- factory.Markup("color:red;"))
- }),
- factory.Markup(" World")
- }))
- };
- yield return new object[]
- {
- "Hello
World",
- new MarkupBlock(
- factory.Markup("Hello"),
- new MarkupTagHelperBlock("p",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"))
- }),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- }),
- factory.Markup("World"))
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(SelfClosingBlockData))]
- public void TagHelperParseTreeRewriter_RewritesSelfClosingTagHelpers(
- string documentContent,
- object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p");
- }
-
- public static IEnumerable QuotelessAttributeBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var dateTimeNow = new Func(index =>
- new MarkupBlock(
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- string.Empty,
- new SourceLocation(index, 0, index)),
- new SourceLocation(index, 0, index)),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace)))));
-
- yield return new object[]
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"), AttributeStructure.NoQuotes),
- new TagHelperAttributeNode("dynamic", dateTimeNow(21)),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"), AttributeStructure.NoQuotes)
- }))
- };
- yield return new object[]
- {
- "Hello World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"), AttributeStructure.NoQuotes),
- new TagHelperAttributeNode("dynamic", dateTimeNow(21)),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"), AttributeStructure.NoQuotes)
- },
- factory.Markup("Hello World")))
- };
- yield return new object[]
- {
- "Hello World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"), AttributeStructure.NoQuotes),
- new TagHelperAttributeNode("dynamic", dateTimeNow(21)),
- new TagHelperAttributeNode(
- "style",
- new MarkupBlock(
- factory.Markup("color"),
- new MarkupBlock(
- factory.Markup("@").Accepts(AcceptedCharactersInternal.None),
- factory.Markup("@").With(SpanChunkGenerator.Null).Accepts(AcceptedCharactersInternal.None)),
- factory.Markup(":red;")),
- AttributeStructure.DoubleQuotes)
- },
- factory.Markup("Hello World")))
- };
- yield return new object[]
- {
- "Hello
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"), AttributeStructure.NoQuotes),
- new TagHelperAttributeNode("dynamic", dateTimeNow(21))
- },
- factory.Markup("Hello")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("style", factory.Markup("color:red;"), AttributeStructure.NoQuotes),
- new TagHelperAttributeNode("dynamic", dateTimeNow(73))
- },
- factory.Markup("World")))
- };
- yield return new object[]
- {
- "Hello World inside of strong tag
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"), AttributeStructure.NoQuotes),
- new TagHelperAttributeNode("dynamic", dateTimeNow(21)),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"), AttributeStructure.NoQuotes)
- },
- factory.Markup("Hello World "),
- new MarkupTagBlock(
- factory.Markup("(" class=\"", 71, 0, 71),
- suffix: new LocationTagged("\"", 82, 0, 82)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("foo").With(new LiteralAttributeChunkGenerator(prefix: new LocationTagged(string.Empty, 79, 0, 79),
- value: new LocationTagged("foo", 79, 0, 79))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">")),
- factory.Markup("inside of strong tag"),
- blockFactory.MarkupTagBlock(" ")))
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(QuotelessAttributeBlockData))]
- public void TagHelperParseTreeRewriter_RewritesTagHelpersWithQuotelessAttributes(
- string documentContent,
- object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p");
- }
-
- public static IEnumerable PlainAttributeBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- yield return new object[]
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo")),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- }))
- };
- yield return new object[]
- {
- "Hello World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo")),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- },
- factory.Markup("Hello World")))
- };
- yield return new object[]
- {
- "Hello
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo"))
- },
- factory.Markup("Hello")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- },
- factory.Markup("World")))
- };
- yield return new object[]
- {
- "Hello World inside of strong tag
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new List
- {
- new TagHelperAttributeNode("class", factory.Markup("foo")),
- new TagHelperAttributeNode("style", factory.Markup("color:red;"))
- },
- factory.Markup("Hello World "),
- new MarkupTagBlock(
- factory.Markup("(" class=\"", 53, 0, 53),
- suffix: new LocationTagged("\"", 64, 0, 64)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("foo").With(new LiteralAttributeChunkGenerator(prefix: new LocationTagged(string.Empty, 61, 0, 61),
- value: new LocationTagged("foo", 61, 0, 61))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">")),
- factory.Markup("inside of strong tag"),
- blockFactory.MarkupTagBlock(" ")))
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(PlainAttributeBlockData))]
- public void TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes(
- string documentContent,
- object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p");
- }
-
- public static IEnumerable PlainBlockData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- yield return new object[]
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p"))
- };
- yield return new object[]
- {
- "Hello World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello World")))
- };
- yield return new object[]
- {
- "Hello
World
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("p",
- factory.Markup("World")))
- };
- yield return new object[]
- {
- "Hello World inside of strong tag
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup("Hello World "),
- blockFactory.MarkupTagBlock(""),
- factory.Markup("inside of strong tag"),
- blockFactory.MarkupTagBlock(" ")))
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(PlainBlockData))]
- public void TagHelperParseTreeRewriter_RewritesPlainTagHelperTagBlocks(
- string documentContent,
- object expectedOutput)
- {
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p");
- }
-
- public static TheoryData DataDashAttributeData_Document
- {
- get
- {
- var factory = new SpanFactory();
- var dateTimeNowString = "@DateTime.Now";
- var dateTimeNow = new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace));
-
- // documentContent, expectedOutput
- return new TheoryData
- {
- {
- $" ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode(
- "data-required",
- new MarkupBlock(dateTimeNow),
- AttributeStructure.SingleQuotes),
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("data-required", factory.Markup("value"), AttributeStructure.SingleQuotes),
- }))
- },
- {
- $" ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode(
- "data-required",
- new MarkupBlock(factory.Markup("prefix "), dateTimeNow),
- AttributeStructure.SingleQuotes),
- }))
- },
- {
- $" ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode(
- "data-required",
- new MarkupBlock(dateTimeNow, factory.Markup(" suffix")),
- AttributeStructure.SingleQuotes),
- }))
- },
- {
- $" ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode(
- "data-required",
- new MarkupBlock(
- factory.Markup("prefix "),
- dateTimeNow,
- factory.Markup(" suffix")),
- AttributeStructure.SingleQuotes),
- }))
- },
- {
- $" ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("pre-attribute", value: null, attributeStructure: AttributeStructure.Minimized),
- new TagHelperAttributeNode(
- "data-required",
- new MarkupBlock(
- factory.Markup("prefix "),
- dateTimeNow,
- factory.Markup(" suffix")),
- AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("post-attribute", value: null, attributeStructure: AttributeStructure.Minimized),
- }))
- },
- {
- $" ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode(
- "data-required",
- new MarkupBlock(
- dateTimeNow,
- factory.Markup(" middle "),
- dateTimeNow),
- AttributeStructure.SingleQuotes),
- }))
- },
- };
- }
- }
-
- public static TheoryData DataDashAttributeData_CSharpBlock
- {
- get
- {
- var factory = new SpanFactory();
- var documentData = DataDashAttributeData_Document;
- 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());
- };
-
- foreach (var data in documentData)
- {
- data[0] = $"@{{{data[0]}}}";
- data[1] = buildStatementBlock(() => data[1] as MarkupBlock);
- }
-
- return documentData;
- }
- }
-
- [Theory]
- [MemberData(nameof(DataDashAttributeData_Document))]
- [MemberData(nameof(DataDashAttributeData_CSharpBlock))]
- public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes(
- string documentContent,
- object expectedOutput)
- {
- // Act & Assert
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, Enumerable.Empty(), "input");
- }
-
- public static TheoryData MinimizedAttributeData_Document
- {
- get
- {
- var factory = new SpanFactory();
- var noErrors = new RazorDiagnostic[0];
- var stringType = typeof(string).FullName;
- var intType = typeof(int).FullName;
- var expressionString = "@DateTime.Now + 1";
- var expression = new Func(index =>
- new MarkupBlock(
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- string.Empty,
- new SourceLocation(index, 0, index)),
- new SourceLocation(index, 0, index)),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace))),
- factory.Markup(" +")
- .With(new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(" ", index + 13, 0, index + 13),
- value: new LocationTagged("+", index + 14, 0, index + 14))),
- factory.Markup(" 1")
- .With(new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(" ", index + 15, 0, index + 15),
- value: new LocationTagged("1", index + 16, 0, index + 16)))));
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- })),
- noErrors
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 21),
- "bound-required-string",
- "input",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 18),
- "bound-required-int",
- "input",
- intType),
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 9),
- "bound-int",
- "p",
- intType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("int-dictionary", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 14),
- "int-dictionary",
- "input",
- typeof(IDictionary).Namespace + ".IDictionary"),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("string-dictionary", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 17),
- "string-dictionary",
- "input",
- typeof(IDictionary).Namespace + ".IDictionary"),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("int-prefix-", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 11),
- "int-prefix-",
- "input",
- intType),
- RazorDiagnosticFactory.CreateParsing_TagHelperIndexerAttributeNameMustIncludeKey(
- new SourceSpan(7, 0, 7, 11),
- "int-prefix-",
- "input"),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("string-prefix-", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 14),
- "string-prefix-",
- "input",
- stringType),
- RazorDiagnosticFactory.CreateParsing_TagHelperIndexerAttributeNameMustIncludeKey(
- new SourceSpan(7, 0, 7, 14),
- "string-prefix-",
- "input"),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("int-prefix-value", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 16),
- "int-prefix-value",
- "input",
- intType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("string-prefix-value", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 19),
- "string-prefix-value",
- "input",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("int-prefix-value", new MarkupBlock(), AttributeStructure.SingleQuotes),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 16),
- "int-prefix-value",
- "input",
- intType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("string-prefix-value", new MarkupBlock(), AttributeStructure.SingleQuotes),
- })),
- new RazorDiagnostic[0]
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "int-prefix-value",
- factory.CodeMarkup("3").With(new ExpressionChunkGenerator()),
- AttributeStructure.SingleQuotes),
- })),
- new RazorDiagnostic[0]
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode(
- "string-prefix-value",
- new MarkupBlock(
- factory.Markup("some"),
- factory.Markup(" string")),
- AttributeStructure.SingleQuotes),
- })),
- new RazorDiagnostic[0]
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(24, 0, 24, 21),
- "bound-required-string",
- "input",
- stringType),
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 9),
- "bound-int",
- "p",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(13, 0, 13, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 18),
- "bound-required-int",
- "input",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(43, 0, 43, 21),
- "bound-required-string",
- "input",
- stringType),
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 9),
- "bound-int",
- "p",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(13, 0, 13, 12),
- "bound-string",
- "p",
- stringType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(26, 0, 26, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- })),
- noErrors
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- })),
- noErrors
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(15, 0, 15, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 21),
- "bound-required-string",
- "input",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(19, 0, 19, 21),
- "bound-required-string",
- "input",
- stringType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 18),
- "bound-required-int",
- "input",
- intType),
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 9),
- "bound-int",
- "p",
- intType),
- }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(19, 0, 19, 18),
- "bound-required-int",
- "input",
- intType),
- }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(15, 0, 15, 9),
- "bound-int",
- "p",
- intType),
- }
- },
- {
- $" ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("class", expression(14), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(33, 0, 33, 18),
- "bound-required-int",
- "input",
- intType),
- }
- },
- {
- $"
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("class", expression(10), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(29, 0, 29, 9),
- "bound-int",
- "p",
- intType),
- }
- },
- {
- $" ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", expression(36), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", expression(86), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(10, 0, 10, 18),
- "bound-required-int",
- "input",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(57, 0, 57, 21),
- "bound-required-string",
- "input",
- stringType),
- }
- },
- {
- $"
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", expression(23), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("class", expression(64), AttributeStructure.SingleQuotes),
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(6, 0, 6, 9),
- "bound-int",
- "p",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(44, 0, 44, 12),
- "bound-string",
- "p",
- stringType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(84, 0, 84, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- };
- }
- }
-
- public static TheoryData MinimizedAttributeData_CSharpBlock
- {
- get
- {
- var factory = new SpanFactory();
- var documentData = MinimizedAttributeData_Document;
- 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());
- };
- Action updateDynamicChunkGenerators = (block) =>
- {
- var tagHelperBlock = block.Children.First() as MarkupTagHelperBlock;
-
- for (var i = 0; i < tagHelperBlock.Attributes.Count; i++)
- {
- var attribute = tagHelperBlock.Attributes[i];
- var holderBlock = attribute.Value as Block;
-
- if (holderBlock == null)
- {
- continue;
- }
-
- var valueBlock = holderBlock.Children.FirstOrDefault() as Block;
- if (valueBlock != null)
- {
- var chunkGenerator = valueBlock.ChunkGenerator as DynamicAttributeBlockChunkGenerator;
-
- if (chunkGenerator != null)
- {
- var blockBuilder = new BlockBuilder(holderBlock);
- var expressionBlockBuilder = new BlockBuilder(valueBlock);
- var newChunkGenerator = new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- chunkGenerator.Prefix.Value,
- new SourceLocation(
- chunkGenerator.Prefix.Location.AbsoluteIndex + 2,
- chunkGenerator.Prefix.Location.LineIndex,
- chunkGenerator.Prefix.Location.CharacterIndex + 2)),
- new SourceLocation(
- chunkGenerator.ValueStart.AbsoluteIndex + 2,
- chunkGenerator.ValueStart.LineIndex,
- chunkGenerator.ValueStart.CharacterIndex + 2));
-
- expressionBlockBuilder.ChunkGenerator = newChunkGenerator;
- blockBuilder.Children[0] = expressionBlockBuilder.Build();
-
- for (var j = 1; j < blockBuilder.Children.Count; j++)
- {
- var span = blockBuilder.Children[j] as Span;
- if (span != null)
- {
- var literalChunkGenerator =
- span.ChunkGenerator as LiteralAttributeChunkGenerator;
-
- var spanBuilder = new SpanBuilder(span);
- spanBuilder.ChunkGenerator = new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(
- literalChunkGenerator.Prefix.Value,
- new SourceLocation(
- literalChunkGenerator.Prefix.Location.AbsoluteIndex + 2,
- literalChunkGenerator.Prefix.Location.LineIndex,
- literalChunkGenerator.Prefix.Location.CharacterIndex + 2)),
- value: new LocationTagged(
- literalChunkGenerator.Value.Value,
- new SourceLocation(
- literalChunkGenerator.Value.Location.AbsoluteIndex + 2,
- literalChunkGenerator.Value.Location.LineIndex,
- literalChunkGenerator.Value.Location.CharacterIndex + 2)));
-
- blockBuilder.Children[j] = spanBuilder.Build();
- }
- }
-
- tagHelperBlock.Attributes[i] = new TagHelperAttributeNode(
- attribute.Name,
- blockBuilder.Build(),
- attribute.AttributeStructure);
- }
- }
- }
- };
-
- foreach (var data in documentData)
- {
- data[0] = $"@{{{data[0]}}}";
-
- updateDynamicChunkGenerators(data[1] as MarkupBlock);
-
- data[1] = buildStatementBlock(() => data[1] as MarkupBlock);
-
- var errors = data[2] as RazorDiagnostic[];
-
- for (var i = 0; i < errors.Length; i++)
- {
- var error = errors[i] as DefaultRazorDiagnostic;
- var currentErrorLocation = new SourceLocation(error.Span.AbsoluteIndex, error.Span.LineIndex, error.Span.CharacterIndex);
- var newErrorLocation = SourceLocationTracker.Advance(currentErrorLocation, "@{");
- var copiedDiagnostic = new DefaultRazorDiagnostic(error.Descriptor, new SourceSpan(newErrorLocation, error.Span.Length), error.Args);
- errors[i] = copiedDiagnostic;
- }
- }
-
- return documentData;
- }
- }
-
- public static TheoryData MinimizedAttributeData_PartialTags
- {
- get
- {
- var factory = new SpanFactory();
- var noErrors = new RazorDiagnostic[0];
- var stringType = typeof(string).FullName;
- var intType = typeof(int).FullName;
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- " ()
- {
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- }
- },
- {
- " ()
- {
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 21),
- "bound-required-string",
- "input",
- stringType),
- }
- },
- {
- " ()
- {
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 18),
- "bound-required-int",
- "input",
- intType),
- }
- },
- {
- " ()
- {
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- })),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 18),
- "bound-required-int",
- "input",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(43, 0, 43, 21),
- "bound-required-string",
- "input",
- stringType),
- }
- },
- {
- "()
- {
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- })),
- 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"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- {
- "
()
- {
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- })),
- 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"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 9),
- "bound-int",
- "p",
- intType),
- }
- },
- {
- "
()
- {
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- })),
- 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"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(3, 0, 3, 9),
- "bound-int",
- "p",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(13, 0, 13, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- {
- " ()
- {
- new TagHelperAttributeNode("bound-required-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("unbound-required", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-required-string", null, AttributeStructure.Minimized),
- },
- children: new MarkupTagHelperBlock(
- "p",
- TagMode.StartTagAndEndTag,
- attributes: new List()
- {
- new TagHelperAttributeNode("bound-int", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("bound-string", null, AttributeStructure.Minimized),
- }))),
- new[]
- {
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 5), "input"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 18),
- "bound-required-int",
- "input",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(43, 0, 43, 21),
- "bound-required-string",
- "input",
- stringType),
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(65, 0, 65), contentLength: 1), "p"),
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(65, 0, 65), contentLength: 1), "p"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(67, 0, 67, 9),
- "bound-int",
- "p",
- intType),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(77, 0, 77, 12),
- "bound-string",
- "p",
- stringType),
- }
- },
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(MinimizedAttributeData_Document))]
- [MemberData(nameof(MinimizedAttributeData_CSharpBlock))]
- [MemberData(nameof(MinimizedAttributeData_PartialTags))]
- public void Rewrite_UnderstandsMinimizedAttributes(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_AllowsCompatibleTagStructures3()
{
// Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("InputTagHelper1", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("input")
- .RequireAttributeDescriptor(attribute => attribute.Name("unbound-required")))
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("input")
- .RequireAttributeDescriptor(attribute => attribute.Name("bound-required-string")))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("bound-required-string")
- .PropertyName("BoundRequiredString")
- .TypeName(typeof(string).FullName))
- .Build(),
- TagHelperDescriptorBuilder.Create("InputTagHelper2", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("input")
- .RequireAttributeDescriptor(attribute => attribute.Name("bound-required-int")))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("bound-required-int")
- .PropertyName("BoundRequiredInt")
- .TypeName(typeof(int).FullName))
- .Build(),
- TagHelperDescriptorBuilder.Create("InputTagHelper3", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("input"))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("int-dictionary")
- .PropertyName("DictionaryOfIntProperty")
- .TypeName(typeof(IDictionary).Namespace + ".IDictionary")
- .AsDictionaryAttribute("int-prefix-", typeof(int).FullName))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("string-dictionary")
- .PropertyName("DictionaryOfStringProperty")
- .TypeName(typeof(IDictionary).Namespace + ".IDictionary")
- .AsDictionaryAttribute("string-prefix-", typeof(string).FullName))
- .Build(),
- TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("bound-string")
- .PropertyName("BoundRequiredString")
- .TypeName(typeof(string).FullName))
- .BoundAttributeDescriptor(attribute =>
- attribute
- .Name("bound-int")
- .PropertyName("BoundRequiredString")
- .TypeName(typeof(int).FullName))
- .Build(),
- };
+ var descriptors = GetTagStructureCompatibilityDescriptors(TagStructure.Unspecified, TagStructure.WithoutEndTag);
// Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors);
+ EvaluateData(descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsCompatibleTagStructures4()
+ {
+ // Arrange
+ var descriptors = GetTagStructureCompatibilityDescriptors(TagStructure.WithoutEndTag, TagStructure.WithoutEndTag);
+
+ // Act & Assert
+ EvaluateData(descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsCompatibleTagStructures5()
+ {
+ // Arrange
+ var descriptors = GetTagStructureCompatibilityDescriptors(TagStructure.Unspecified, TagStructure.NormalOrSelfClosing);
+
+ // Act & Assert
+ EvaluateData(descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsCompatibleTagStructures6()
+ {
+ // Arrange
+ var descriptors = GetTagStructureCompatibilityDescriptors(TagStructure.Unspecified, TagStructure.WithoutEndTag);
+
+ // Act & Assert
+ EvaluateData(descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_AllowsCompatibleTagStructures7()
+ {
+ // Arrange
+ var descriptors = GetTagStructureCompatibilityDescriptors(TagStructure.NormalOrSelfClosing, TagStructure.Unspecified);
+
+ // Act & Assert
+ EvaluateData(descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes1()
+ {
+ RunParseTreeRewriterTest("", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes4()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes8()
+ {
+ RunParseTreeRewriterTest("", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes9()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes10()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes11()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes12()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes13()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes14()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes15()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes16()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes18()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes19()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelper1()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelper5()
+ {
+ RunParseTreeRewriterTest(" <", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelper7()
+ {
+ RunParseTreeRewriterTest("<<> <<>>", "strong", "p");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForMalformedTagHelper8()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ public static TagHelperDescriptor[] CodeTagHelperAttributes_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("PersonTagHelper", "personAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("person"))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("age")
+ .PropertyName("Age")
+ .TypeName(typeof(int).FullName))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("birthday")
+ .PropertyName("BirthDay")
+ .TypeName(typeof(DateTime).FullName))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("name")
+ .PropertyName("Name")
+ .TypeName(typeof(string).FullName))
+ .Build()
+ };
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes1()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes2()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes3()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes4()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes5()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes6()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes7()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes8()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes9()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes10()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesMarkupCodeSpansForNonStringTagHelperAttributes11()
+ {
+ EvaluateData(CodeTagHelperAttributes_Descriptors, " ");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_CreatesErrorForIncompleteTagHelper1()
+ {
+ RunParseTreeRewriterTest("
", "strong", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_CreatesErrorForIncompleteTagHelper2()
+ {
+ RunParseTreeRewriterTest("", "strong", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_CreatesErrorForIncompleteTagHelper3()
+ {
+ RunParseTreeRewriterTest("", "strong", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_CreatesErrorForIncompleteTagHelper4()
+ {
+ RunParseTreeRewriterTest("Hello
World
", "strong", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesOddlySpacedTagHelperTagBlocks1()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesOddlySpacedTagHelperTagBlocks2()
+ {
+ RunParseTreeRewriterTest("Hello World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesOddlySpacedTagHelperTagBlocks3()
+ {
+ RunParseTreeRewriterTest("Hello
World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks1()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var currentFormattedString = "
";
+ var document = string.Format(currentFormattedString, dateTimeNowString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks2()
+ {
+ // Arrange
+ var doWhileString = "@do { var foo = bar; Foo foo++; } while (foo);";
+ var currentFormattedString = "
";
+ var document = string.Format(currentFormattedString, doWhileString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks3()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var currentFormattedString = "Hello World
";
+ var document = string.Format(currentFormattedString, dateTimeNowString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks4()
+ {
+ // Arrange
+ var doWhileString = "@do { var foo = bar; Foo foo++; } while (foo);";
+ var currentFormattedString = "Hello World
";
+ var document = string.Format(currentFormattedString, doWhileString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks5()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var currentFormattedString = "Hello
World
";
+ var document = string.Format(currentFormattedString, dateTimeNowString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks6()
+ {
+ // Arrange
+ var doWhileString = "@do { var foo = bar; Foo foo++; } while (foo);";
+ var currentFormattedString = "Hello
World
";
+ var document = string.Format(currentFormattedString, doWhileString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks7()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var currentFormattedString = "Hello World inside of strong tag
";
+ var document = string.Format(currentFormattedString, dateTimeNowString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks1()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var currentFormattedString = "{0}
";
+ var document = string.Format(currentFormattedString, dateTimeNowString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks2()
+ {
+ // Arrange
+ var doWhileString = "@do { var foo = bar; Foo
foo++; } while (foo);";
+ var currentFormattedString = "{0}
";
+ var document = string.Format(currentFormattedString, doWhileString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks3()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var currentFormattedString = "Hello World {0}
";
+ var document = string.Format(currentFormattedString, dateTimeNowString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks4()
+ {
+ // Arrange
+ var doWhileString = "@do { var foo = bar; Foo
foo++; } while (foo);";
+ var currentFormattedString = "Hello World {0}
";
+ var document = string.Format(currentFormattedString, doWhileString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks5()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var currentFormattedString = "{0}
{0}
";
+ var document = string.Format(currentFormattedString, dateTimeNowString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks6()
+ {
+ // Arrange
+ var doWhileString = "@do { var foo = bar; Foo
foo++; } while (foo);";
+ var currentFormattedString = "{0}
{0}
";
+ var document = string.Format(currentFormattedString, doWhileString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks7()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var currentFormattedString = "Hello {0}inside of {0} strong tag
";
+ var document = string.Format(currentFormattedString, dateTimeNowString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesComplexTagHelperTagBlocks8()
+ {
+ // Arrange
+ var doWhileString = "@do { var foo = bar; Foo
foo++; } while (foo);";
+ var currentFormattedString = "Hello {0}inside of {0} strong tag
";
+ var document = string.Format(currentFormattedString, doWhileString);
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml1()
+ {
+ RunParseTreeRewriterTest("<<>>
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml2()
+ {
+ RunParseTreeRewriterTest("<
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml3()
+ {
+ RunParseTreeRewriterTest("< p />", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml4()
+ {
+ RunParseTreeRewriterTest(" ", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml5()
+ {
+ RunParseTreeRewriterTest("< class=\"foo\"
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml6()
+ {
+ RunParseTreeRewriterTest("</>
>", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml7()
+ {
+ RunParseTreeRewriterTest("</>
>", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml8()
+ {
+ RunParseTreeRewriterTest("<@DateTime.Now/>
>", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml9()
+ {
+ RunParseTreeRewriterTest(" /< >@DateTime.Now / >
>", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_AllowsInvalidHtml10()
+ {
+ RunParseTreeRewriterTest("< @DateTime.Now > @DateTime.Now >
", "p");
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsEmptyAttributeTagHelpers1()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsEmptyAttributeTagHelpers2()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsEmptyAttributeTagHelpers3()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsEmptyAttributeTagHelpers4()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsEmptyAttributeTagHelpers5()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ public static TagHelperDescriptor[] EmptyTagHelperBoundAttribute_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("mythTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("myth"))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("bound")
+ .PropertyName("Bound")
+ .TypeName(typeof(bool).FullName))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("name")
+ .PropertyName("Name")
+ .TypeName(typeof(string).FullName))
+ .Build()
+ };
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes1()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes2()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes3()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes4()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes5()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes6()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, "");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes7()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes8()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes9()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes10()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes11()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes12()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes13()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void Rewrite_CreatesErrorForEmptyTagHelperBoundAttributes14()
+ {
+ EvaluateData(EmptyTagHelperBoundAttribute_Descriptors, " ");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesScriptTagHelpers1()
+ {
+ RunParseTreeRewriterTest("", "p", "div", "script");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesScriptTagHelpers2()
+ {
+ RunParseTreeRewriterTest("", "p", "div", "script");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesScriptTagHelpers3()
+ {
+ RunParseTreeRewriterTest("
World
", "p", "div", "script");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesScriptTagHelpers4()
+ {
+ RunParseTreeRewriterTest(" ", "p", "div", "script");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesScriptTagHelpers5()
+ {
+ RunParseTreeRewriterTest("", "p", "div", "script");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesScriptTagHelpers6()
+ {
+ RunParseTreeRewriterTest("Hello World
", "p", "div", "script");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesScriptTagHelpers7()
+ {
+ RunParseTreeRewriterTest("Hello World
", "p", "div", "script");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesSelfClosingTagHelpers1()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesSelfClosingTagHelpers2()
+ {
+ RunParseTreeRewriterTest("Hello
World", "p");
+ }
+
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesSelfClosingTagHelpers3()
+ {
+ RunParseTreeRewriterTest("Hello
World", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithQuotelessAttributes1()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithQuotelessAttributes2()
+ {
+ RunParseTreeRewriterTest("Hello World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithQuotelessAttributes3()
+ {
+ RunParseTreeRewriterTest("Hello World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithQuotelessAttributes4()
+ {
+ RunParseTreeRewriterTest("Hello
World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithQuotelessAttributes5()
+ {
+ RunParseTreeRewriterTest("Hello World inside of strong tag
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes1()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes2()
+ {
+ RunParseTreeRewriterTest("Hello World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes3()
+ {
+ RunParseTreeRewriterTest("Hello
World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes4()
+ {
+ RunParseTreeRewriterTest("Hello World inside of strong tag
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesPlainTagHelperTagBlocks1()
+ {
+ RunParseTreeRewriterTest("
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesPlainTagHelperTagBlocks2()
+ {
+ RunParseTreeRewriterTest("Hello World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesPlainTagHelperTagBlocks3()
+ {
+ RunParseTreeRewriterTest("Hello
World
", "p");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_RewritesPlainTagHelperTagBlocks4()
+ {
+ RunParseTreeRewriterTest("Hello World inside of strong tag
", "p");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Document1()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Document2()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Document3()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Document4()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Document5()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Document6()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Document7()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Block1()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Block2()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Block3()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Block4()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Block5()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Block6()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void Rewrite_GeneratesExpectedOutputForUnboundDataDashAttributes_Block7()
+ {
+ // Arrange
+ var dateTimeNowString = "@DateTime.Now";
+ var document = $" ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ public static TagHelperDescriptor[] MinimizedAttribute_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("InputTagHelper1", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("input")
+ .RequireAttributeDescriptor(attribute => attribute.Name("unbound-required")))
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("input")
+ .RequireAttributeDescriptor(attribute => attribute.Name("bound-required-string")))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("bound-required-string")
+ .PropertyName("BoundRequiredString")
+ .TypeName(typeof(string).FullName))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("InputTagHelper2", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("input")
+ .RequireAttributeDescriptor(attribute => attribute.Name("bound-required-int")))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("bound-required-int")
+ .PropertyName("BoundRequiredInt")
+ .TypeName(typeof(int).FullName))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("InputTagHelper3", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("input"))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("int-dictionary")
+ .PropertyName("DictionaryOfIntProperty")
+ .TypeName(typeof(IDictionary).Namespace + ".IDictionary")
+ .AsDictionaryAttribute("int-prefix-", typeof(int).FullName))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("string-dictionary")
+ .PropertyName("DictionaryOfStringProperty")
+ .TypeName(typeof(IDictionary).Namespace + ".IDictionary")
+ .AsDictionaryAttribute("string-prefix-", typeof(string).FullName))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("bound-string")
+ .PropertyName("BoundRequiredString")
+ .TypeName(typeof(string).FullName))
+ .BoundAttributeDescriptor(attribute =>
+ attribute
+ .Name("bound-int")
+ .PropertyName("BoundRequiredString")
+ .TypeName(typeof(int).FullName))
+ .Build(),
+ };
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document1()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document2()
+ {
+ // Arrange
+ var document = "
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document3()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document4()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document5()
+ {
+ // Arrange
+ var document = "
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document6()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document7()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document8()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document9()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document10()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document11()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document12()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document13()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document14()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document15()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document16()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document17()
+ {
+ // Arrange
+ var document = "
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document18()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document19()
+ {
+ // Arrange
+ var document = "
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document20()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document21()
+ {
+ // Arrange
+ var document = "
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document22()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document23()
+ {
+ // Arrange
+ var document = "
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document24()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document25()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document26()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document27()
+ {
+ // Arrange
+ var document = "
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document28()
+ {
+ // Arrange
+ var document = " ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document29()
+ {
+ // Arrange
+ var document = "
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document30()
+ {
+ // Arrange
+ var expressionString = "@DateTime.Now + 1";
+ var document = $" ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document31()
+ {
+ // Arrange
+ var expressionString = "@DateTime.Now + 1";
+ var document = $"
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document32()
+ {
+ // Arrange
+ var expressionString = "@DateTime.Now + 1";
+ var document = $" ";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Document33()
+ {
+ // Arrange
+ var expressionString = "@DateTime.Now + 1";
+ var document = $"
";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block1()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block2()
+ {
+ // Arrange
+ var document = "
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block3()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block4()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block5()
+ {
+ // Arrange
+ var document = "
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block6()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block7()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block8()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block9()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block10()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block11()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block12()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block13()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block14()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block15()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block16()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block17()
+ {
+ // Arrange
+ var document = "
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block18()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block19()
+ {
+ // Arrange
+ var document = "
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block20()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block21()
+ {
+ // Arrange
+ var document = "
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block22()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block23()
+ {
+ // Arrange
+ var document = "
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block24()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block25()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block26()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block27()
+ {
+ // Arrange
+ var document = "
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block28()
+ {
+ // Arrange
+ var document = " ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block29()
+ {
+ // Arrange
+ var document = "
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block30()
+ {
+ // Arrange
+ var expressionString = "@DateTime.Now + 1";
+ var document = $" ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block31()
+ {
+ // Arrange
+ var expressionString = "@DateTime.Now + 1";
+ var document = $"
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block32()
+ {
+ // Arrange
+ var expressionString = "@DateTime.Now + 1";
+ var document = $" ";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_Block33()
+ {
+ // Arrange
+ var expressionString = "@DateTime.Now + 1";
+ var document = $"
";
+
+ // Wrap in a CSharp block
+ document = $"@{{{document}}}";
+
+ // Act & Assert
+ EvaluateData(MinimizedAttribute_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsMinimizedAttributes_PartialTags1()
+ {
+ EvaluateData(MinimizedAttribute_Descriptors, " ()
- {
- new TagHelperAttributeNode("boundbool", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("boundbooldict-key", null, AttributeStructure.Minimized),
- }));
-
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, new RazorDiagnostic[] { });
+ EvaluateData(descriptors, document);
}
[Fact]
public void Rewrite_FeatureDisabled_AddsErrorForMinimizedBooleanBoundAttributes()
{
// Arrange
- var documentContent = " ";
+ var document = " ";
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("InputTagHelper", "SomeAssembly")
@@ -3964,32 +2132,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var featureFlags = new TestRazorParserFeatureFlags();
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock(
- "input",
- TagMode.SelfClosing,
- attributes: new List()
- {
- new TagHelperAttributeNode("boundbool", null, AttributeStructure.Minimized),
- new TagHelperAttributeNode("boundbooldict-key", null, AttributeStructure.Minimized),
- }));
-
- var expectedErrors = new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(7, 0, 7, 9),
- "boundbool",
- "input",
- "System.Boolean"),
- RazorDiagnosticFactory.CreateTagHelper_EmptyBoundAttribute(
- new SourceSpan(17, 0, 17, 17),
- "boundbooldict-key",
- "input",
- "System.Boolean"),
- };
-
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors, featureFlags: featureFlags);
+ EvaluateData(descriptors, document, featureFlags: featureFlags);
}
private class TestRazorParserFeatureFlags : RazorParserFeatureFlags
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs
index 3f37c82c4d..3cc644cacb 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs
@@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.Linq;
using Xunit;
@@ -11,6 +10,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
public class TagHelperParseTreeRewriterTest : TagHelperRewritingTestBase
{
+ public TagHelperParseTreeRewriterTest()
+ {
+ UseBaselineTests = true;
+ }
+
public static TheoryData GetAttributeNameValuePairsData
{
get
@@ -68,289 +72,191 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Assert.Equal(expectedPairs, pairs);
}
- public static TheoryData PartialRequiredParentData
+ public static TagHelperDescriptor[] PartialRequiredParentTags_Descriptors = new TagHelperDescriptor[]
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- Func errorFormatUnclosed = (location, tagName) =>
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(new SourceLocation(location, 0, location), tagName.Length), tagName);
+ TagHelperDescriptorBuilder.Create("StrongTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("strong"))
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("CatchALlTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
+ .Build(),
+ };
- Func errorFormatNoCloseAngle = (location, tagName) =>
- RazorDiagnosticFactory.CreateParsing_TagHelperMissingCloseAngle(
- new SourceSpan(new SourceLocation(location, 0, location), tagName.Length), tagName);
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong"))),
- new[] { errorFormatUnclosed(1, "p"), errorFormatUnclosed(4, "strong") }
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong"))),
- new[] { errorFormatUnclosed(1, "p") }
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong")),
- new MarkupTagHelperBlock("strong")),
- new[] { errorFormatUnclosed(4, "strong"), errorFormatUnclosed(16, "strong") }
- },
- {
- "<<
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("strong",
- blockFactory.MarkupTagBlock("")),
- blockFactory.MarkupTagBlock(" "))),
- new[] { errorFormatNoCloseAngle(17, "strong"), errorFormatUnclosed(25, "strong") }
- },
- {
- "<<
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("strong",
- blockFactory.MarkupTagBlock("")),
- blockFactory.MarkupTagBlock(""))),
- new[] { errorFormatUnclosed(26, "strong") }
- },
-
- {
- "<<<
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock("<"),
- new MarkupTagHelperBlock("custom",
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("<")),
- blockFactory.MarkupTagBlock(""))),
- new[] { errorFormatUnclosed(27, "custom") }
- },
- };
- }
+ [Fact]
+ public void Rewrite_UnderstandsPartialRequiredParentTags1()
+ {
+ var document = "";
+ EvaluateData(PartialRequiredParentTags_Descriptors, document);
}
- [Theory]
- [MemberData(nameof(PartialRequiredParentData))]
- public void Rewrite_UnderstandsPartialRequiredParentTags(
- string documentContent,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_UnderstandsPartialRequiredParentTags2()
{
- // Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("StrongTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("strong"))
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div"))
- .Build(),
- TagHelperDescriptorBuilder.Create("CatchALlTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
- .Build(),
- TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
- .Build(),
- };
-
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors);
+ var document = " ";
+ EvaluateData(PartialRequiredParentTags_Descriptors, document);
}
- public static TheoryData NestedVoidSelfClosingRequiredParentData
+ [Fact]
+ public void Rewrite_UnderstandsPartialRequiredParentTags3()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- // documentContent, expectedOutput
- return new TheoryData
- {
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly),
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly),
- new MarkupTagHelperBlock("strong")))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(" "),
- new MarkupTagHelperBlock("strong")))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(" ")),
- new MarkupTagHelperBlock("strong")))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock("input", TagMode.StartTagOnly),
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("input", TagMode.SelfClosing),
- new MarkupTagHelperBlock("strong", TagMode.SelfClosing)))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(" "),
- new MarkupTagHelperBlock("strong", TagMode.SelfClosing)))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(" ")),
- new MarkupTagHelperBlock("strong", TagMode.SelfClosing)))
- },
- };
- }
+ var document = "
";
+ EvaluateData(PartialRequiredParentTags_Descriptors, document);
}
- [Theory]
- [MemberData(nameof(NestedVoidSelfClosingRequiredParentData))]
- public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_UnderstandsPartialRequiredParentTags4()
{
- // Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("InputTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("input")
- .RequireTagStructure(TagStructure.WithoutEndTag))
- .Build(),
- TagHelperDescriptorBuilder.Create("StrongTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("strong")
- .RequireParentTag("p"))
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("strong")
- .RequireParentTag("input"))
- .Build(),
- TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
- .Build(),
- };
-
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ var document = "<<
";
+ EvaluateData(PartialRequiredParentTags_Descriptors, document);
}
- public static TheoryData NestedRequiredParentData
+ [Fact]
+ public void Rewrite_UnderstandsPartialRequiredParentTags5()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- // documentContent, expectedOutput
- return new TheoryData
- {
- {
- " ",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong")))
- },
- {
- "
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- new MarkupTagHelperBlock("strong"),
- blockFactory.MarkupTagBlock("
"))
- },
- {
- " ",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "),
- blockFactory.MarkupTagBlock(" "))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong",
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "))))
- },
- };
- }
+ var document = "<<
";
+ EvaluateData(PartialRequiredParentTags_Descriptors, document);
}
- [Theory]
- [MemberData(nameof(NestedRequiredParentData))]
- public void Rewrite_UnderstandsNestedRequiredParent(string documentContent, object expectedOutput)
+ [Fact]
+ public void Rewrite_UnderstandsPartialRequiredParentTags6()
{
- // Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("StrongTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("strong")
- .RequireParentTag("p"))
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("strong")
- .RequireParentTag("div"))
- .Build(),
- TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
- .Build(),
- };
+ var document = "<<<
";
+ EvaluateData(PartialRequiredParentTags_Descriptors, document);
+ }
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ public static TagHelperDescriptor[] NestedVoidSelfClosingRequiredParent_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("InputTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("input")
+ .RequireTagStructure(TagStructure.WithoutEndTag))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("StrongTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("strong")
+ .RequireParentTag("p"))
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("strong")
+ .RequireParentTag("input"))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
+ .Build(),
+ };
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent1()
+ {
+ var document = " ";
+ EvaluateData(NestedVoidSelfClosingRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent2()
+ {
+ var document = "
";
+ EvaluateData(NestedVoidSelfClosingRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent3()
+ {
+ var document = "
";
+ EvaluateData(NestedVoidSelfClosingRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent4()
+ {
+ var document = "
";
+ EvaluateData(NestedVoidSelfClosingRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent5()
+ {
+ var document = " ";
+ EvaluateData(NestedVoidSelfClosingRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent6()
+ {
+ var document = "
";
+ EvaluateData(NestedVoidSelfClosingRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent7()
+ {
+ var document = "
";
+ EvaluateData(NestedVoidSelfClosingRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedVoidSelfClosingRequiredParent8()
+ {
+ var document = "
";
+ EvaluateData(NestedVoidSelfClosingRequiredParent_Descriptors, document);
+ }
+
+ public static TagHelperDescriptor[] NestedRequiredParent_Descriptors = new TagHelperDescriptor[]
+ {
+ TagHelperDescriptorBuilder.Create("StrongTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("strong")
+ .RequireParentTag("p"))
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("strong")
+ .RequireParentTag("div"))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
+ .Build(),
+ };
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedRequiredParent1()
+ {
+ var document = " ";
+ EvaluateData(NestedRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedRequiredParent2()
+ {
+ var document = "
";
+ EvaluateData(NestedRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedRequiredParent3()
+ {
+ var document = "
";
+ EvaluateData(NestedRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedRequiredParent4()
+ {
+ var document = " ";
+ EvaluateData(NestedRequiredParent_Descriptors, document);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsNestedRequiredParent5()
+ {
+ var document = "
";
+ EvaluateData(NestedRequiredParent_Descriptors, document);
}
[Fact]
@@ -358,9 +264,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
// Arrange
var documentContent = " ";
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("th:p",
- new MarkupTagHelperBlock("th:strong")));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
@@ -376,8 +279,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
EvaluateData(
descriptors,
documentContent,
- expectedOutput,
- expectedErrors: Enumerable.Empty(),
tagHelperPrefix: "th:");
}
@@ -386,9 +287,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
// Arrange
var documentContent = " ";
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("th:p",
- new MarkupTagHelperBlock("th:strong")));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
@@ -404,8 +302,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
EvaluateData(
descriptors,
documentContent,
- expectedOutput,
- expectedErrors: Enumerable.Empty(),
tagHelperPrefix: "th:");
}
@@ -414,10 +310,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
// Arrange
var documentContent = " ";
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("th:p",
- new MarkupTagBlock(
- Factory.Markup(""))));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
@@ -428,18 +320,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("strong").RequireParentTag("p"))
.Build(),
};
- var expectedErrors = new[] {
- RazorDiagnosticFactory.CreateParsing_TagHelperFoundMalformedTagHelper(
- new SourceSpan(filePath: null, absoluteIndex: 8, lineIndex: 0, characterIndex: 8, length: 9),
- "th:strong"),
- };
// Act & Assert
EvaluateData(
descriptors,
documentContent,
- expectedOutput,
- expectedErrors: expectedErrors,
tagHelperPrefix: "th:");
}
@@ -448,12 +333,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
// Arrange
var documentContent = " ";
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("th:p",
- new MarkupTagBlock(
- Factory.Markup("")),
- new MarkupTagBlock(
- Factory.Markup(" "))));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
@@ -466,298 +345,71 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
EvaluateData(
descriptors,
documentContent,
- expectedOutput,
- expectedErrors: Enumerable.Empty(),
tagHelperPrefix: "th:");
}
- public static TheoryData InvalidHtmlScriptBlockData
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotUnderstandTagHelpersInInvalidHtmlTypedScriptTags1()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- return new TheoryData
- {
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup(""))
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup(""))
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup(""))
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup(""))
- },
- };
- }
+ var document = "";
+ RunParseTreeRewriterTest(document, "input");
}
- [Theory]
- [MemberData(nameof(InvalidHtmlScriptBlockData))]
- public void TagHelperParseTreeRewriter_DoesNotUnderstandTagHelpersInInvalidHtmlTypedScriptTags(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotUnderstandTagHelpersInInvalidHtmlTypedScriptTags2()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "input");
+ var document = "";
+ RunParseTreeRewriterTest(document, "input");
}
- public static TheoryData HtmlScriptBlockData
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotUnderstandTagHelpersInInvalidHtmlTypedScriptTags3()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- return new TheoryData
- {
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup(""))
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup(""))
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- blockFactory.MarkupTagBlock(""))
- },
- {
- "",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("")),
- blockFactory.MarkupTagBlock(""))
- },
- };
- }
+ var document = "";
+ RunParseTreeRewriterTest(document, "input");
}
- [Theory]
- [MemberData(nameof(HtmlScriptBlockData))]
- public void TagHelperParseTreeRewriter_UnderstandsTagHelpersInHtmlTypedScriptTags(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void TagHelperParseTreeRewriter_DoesNotUnderstandTagHelpersInInvalidHtmlTypedScriptTags4()
{
- RunParseTreeRewriterTest(documentContent, (MarkupBlock)expectedOutput, "p", "input");
+ var document = "";
+ RunParseTreeRewriterTest(document, "input");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_UnderstandsTagHelpersInHtmlTypedScriptTags1()
+ {
+ var document = "";
+ RunParseTreeRewriterTest(document, "p", "input");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_UnderstandsTagHelpersInHtmlTypedScriptTags2()
+ {
+ var document = "";
+ RunParseTreeRewriterTest(document, "p", "input");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_UnderstandsTagHelpersInHtmlTypedScriptTags3()
+ {
+ var document = "";
+ RunParseTreeRewriterTest(document, "p", "input");
+ }
+
+ [Fact]
+ public void TagHelperParseTreeRewriter_UnderstandsTagHelpersInHtmlTypedScriptTags4()
+ {
+ var document = "";
+ RunParseTreeRewriterTest(document, "p", "input");
}
[Fact]
public void Rewrite_CanHandleInvalidChildrenWithWhitespace()
{
// Arrange
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
var documentContent = $"{Environment.NewLine} {Environment.NewLine} Hello" +
$"{Environment.NewLine} {Environment.NewLine}
";
- var newLineLength = Environment.NewLine.Length;
- var expectedErrors = new[] {
- RazorDiagnosticFactory.CreateTagHelper_InvalidNestedTag(
- new SourceSpan(absoluteIndex: 8 + newLineLength, lineIndex: 1, characterIndex: 5, length: 6), "strong", "p", "br"),
- };
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup(Environment.NewLine + " "),
- blockFactory.MarkupTagBlock(""),
- factory.Markup(Environment.NewLine + " Hello" + Environment.NewLine + " "),
- blockFactory.MarkupTagBlock(" "),
- factory.Markup(Environment.NewLine)));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
@@ -767,29 +419,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors);
+ EvaluateData(descriptors, documentContent);
}
[Fact]
public void Rewrite_RecoversWhenRequiredAttributeMismatchAndRestrictedChildren()
{
// Arrange
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
var documentContent = " ";
-
- var expectedErrors = new[] {
- RazorDiagnosticFactory.CreateTagHelper_InvalidNestedTag(
- new SourceSpan(absoluteIndex: 18, lineIndex: 0, characterIndex: 18, length: 6), "strong", "strong", "br")
- };
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("strong",
- new List
- {
- new TagHelperAttributeNode("required", null, AttributeStructure.Minimized)
- },
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" ")));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("StrongTagHelper", "SomeAssembly")
@@ -802,20 +439,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors);
+ EvaluateData(descriptors, documentContent);
}
[Fact]
public void Rewrite_CanHandleMultipleTagHelpersWithAllowedChildren_OneNull()
{
// Arrange
- var factory = new SpanFactory();
var documentContent = "Hello World
";
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong",
- factory.Markup("Hello World")),
- new MarkupTagHelperBlock("br", TagMode.StartTagOnly)));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("PTagHelper1", "SomeAssembly")
@@ -838,20 +469,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ EvaluateData(descriptors, documentContent);
}
[Fact]
public void Rewrite_CanHandleMultipleTagHelpersWithAllowedChildren()
{
// Arrange
- var factory = new SpanFactory();
var documentContent = "Hello World
";
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong",
- factory.Markup("Hello World")),
- new MarkupTagHelperBlock("br", TagMode.StartTagOnly)));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("PTagHelper1", "SomeAssembly")
@@ -874,214 +499,165 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ EvaluateData(descriptors, documentContent);
}
- public static TheoryData AllowedChildrenData
- {
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- Func nestedTagError =
- (childName, parentName, allowed, location, length) =>
- RazorDiagnosticFactory.CreateTagHelper_InvalidNestedTag(
- new SourceSpan(absoluteIndex: location, lineIndex: 0, characterIndex: location, length: length), childName, parentName, allowed);
- Func nestedContentError =
- (parentName, allowed, location, length) =>
- RazorDiagnosticFactory.CreateTagHelper_CannotHaveNonTagContent(
- new SourceSpan(absoluteIndex: location, lineIndex: 0, characterIndex: location, length: length), parentName, allowed);
-
- return new TheoryData, MarkupBlock, RazorDiagnostic[]>
- {
- {
- "
",
- new[] { "br" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("br", TagMode.SelfClosing))),
- new RazorDiagnostic[0]
- },
- {
- $"{Environment.NewLine} {Environment.NewLine}
",
- new[] { "br" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup(Environment.NewLine),
- new MarkupTagHelperBlock("br", TagMode.SelfClosing),
- factory.Markup(Environment.NewLine))),
- new RazorDiagnostic[0]
- },
- {
- "
",
- new[] { "strong" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("br", TagMode.StartTagOnly))),
- new[] { nestedTagError("br", "p", "strong", 4, 2) }
- },
- {
- "Hello
",
- new[] { "strong" },
- new MarkupBlock(new MarkupTagHelperBlock("p", factory.Markup("Hello"))),
- new[] { nestedContentError("p", "strong", 3, 5) }
- },
- {
- "
",
- new[] { "br", "strong" },
- new MarkupBlock(new MarkupTagHelperBlock("p", blockFactory.MarkupTagBlock(" "))),
- new[] { nestedTagError("hr", "p", "br, strong", 4, 2) }
- },
- {
- " Hello
",
- new[] { "strong" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("br", TagMode.StartTagOnly),
- factory.Markup("Hello"))),
- new[] { nestedTagError("br", "p", "strong", 4, 2), nestedContentError("p", "strong", 7, 5) }
- },
- {
- "Title: Something
",
- new[] { "strong" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong", factory.Markup("Title:")),
- new MarkupTagHelperBlock("br", TagMode.SelfClosing),
- factory.Markup("Something"))),
- new[]
- {
- nestedContentError("strong", "strong", 11, 6),
- nestedTagError("br", "p", "strong", 27, 2),
- nestedContentError("p", "strong", 32, 9),
- }
- },
- {
- "Title: Something
",
- new[] { "strong", "br" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong", factory.Markup("Title:")),
- new MarkupTagHelperBlock("br", TagMode.SelfClosing),
- factory.Markup("Something"))),
- new[]
- {
- nestedContentError("strong", "strong, br", 11, 6),
- nestedContentError("p", "strong, br", 32, 9),
- }
- },
- {
- " Title: Something
",
- new[] { "strong", "br" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- factory.Markup(" "),
- new MarkupTagHelperBlock("strong", factory.Markup("Title:")),
- factory.Markup(" "),
- new MarkupTagHelperBlock("br", TagMode.SelfClosing),
- factory.Markup(" Something"))),
- new[]
- {
- nestedContentError("strong", "strong, br", 13, 6),
- nestedContentError("p", "strong, br", 38, 9),
- }
- },
- {
- "Title:A Very Cool Something
",
- new[] { "strong" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- new MarkupTagHelperBlock("strong",
- factory.Markup("Title:"),
- new MarkupTagHelperBlock("br", TagMode.StartTagOnly),
- blockFactory.MarkupTagBlock(""),
- factory.Markup("A Very Cool"),
- blockFactory.MarkupTagBlock(" ")),
- new MarkupTagHelperBlock("br", TagMode.SelfClosing),
- factory.Markup("Something"))),
- new[]
- {
- nestedContentError("strong", "strong", 11, 6),
- nestedTagError("br", "strong", "strong", 18, 2),
- nestedTagError("em", "strong", "strong", 22, 2),
- nestedTagError("br", "p", "strong", 51, 2),
- nestedContentError("p", "strong", 56, 9)
- }
- },
- {
- "Title:A Very Cool Something
",
- new[] { "custom" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(""),
- factory.Markup("Title:"),
- new MarkupTagHelperBlock("br", TagMode.StartTagOnly),
- blockFactory.MarkupTagBlock(""),
- factory.Markup("A Very Cool"),
- blockFactory.MarkupTagBlock(" "),
- blockFactory.MarkupTagBlock(" "),
- new MarkupTagHelperBlock("br", TagMode.SelfClosing),
- factory.Markup("Something"))),
- new[]
- {
- nestedTagError("br", "p", "custom", 51, 2),
- nestedContentError("p", "custom", 56, 9)
- }
- },
- {
- "
",
- new[] { "custom" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(""))),
- new[]
- {
- nestedContentError("p", "custom", 3, 2),
- }
- },
- {
- "<
",
- new[] { "custom" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock("<"))),
- new[]
- {
- nestedContentError("p", "custom", 3, 1),
- }
- },
- {
- " :Hello :
",
- new[] { "custom", "strong" },
- new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(""),
- new MarkupTagHelperBlock("br", TagMode.StartTagOnly),
- factory.Markup(":"),
- new MarkupTagHelperBlock("strong",
- new MarkupTagHelperBlock("strong",
- factory.Markup("Hello"))),
- factory.Markup(":"),
- blockFactory.MarkupTagBlock(" "),
- blockFactory.MarkupTagBlock(" "))),
- new[]
- {
- nestedContentError("strong", "custom, strong", 32, 5),
- }
- },
- };
- }
- }
-
- [Theory]
- [MemberData(nameof(AllowedChildrenData))]
- public void Rewrite_UnderstandsAllowedChildren(
- string documentContent,
- IEnumerable allowedChildren,
- object expectedOutput,
- object expectedErrors)
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren1()
{
// Arrange
+ var documentContent = "
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "br" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren2()
+ {
+ // Arrange
+ var documentContent = $"{Environment.NewLine} {Environment.NewLine}
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "br" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren3()
+ {
+ // Arrange
+ var documentContent = "
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "strong" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren4()
+ {
+ // Arrange
+ var documentContent = "Hello
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "strong" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren5()
+ {
+ // Arrange
+ var documentContent = "
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "br", "strong" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren6()
+ {
+ // Arrange
+ var documentContent = " Hello
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "strong" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren7()
+ {
+ // Arrange
+ var documentContent = "Title: Something
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "strong" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren8()
+ {
+ // Arrange
+ var documentContent = "Title: Something
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "strong", "br" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren9()
+ {
+ // Arrange
+ var documentContent = " Title: Something
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "strong", "br" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren10()
+ {
+ // Arrange
+ var documentContent = "Title:A Very Cool Something
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "strong" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren11()
+ {
+ // Arrange
+ var documentContent = "Title:A Very Cool Something
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "custom" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren12()
+ {
+ // Arrange
+ var documentContent = "
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "custom" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren13()
+ {
+ // Arrange
+ var documentContent = "<
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "custom" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ [Fact]
+ public void Rewrite_UnderstandsAllowedChildren14()
+ {
+ // Arrange
+ var documentContent = " :Hello :
";
+ var descriptors = GetAllowedChildrenTagHelperDescriptors(new[] { "custom", "strong" });
+
+ // Act & Assert
+ EvaluateData(descriptors, documentContent);
+ }
+
+ private TagHelperDescriptor[] GetAllowedChildrenTagHelperDescriptors(string[] allowedChildren)
+ {
var pTagHelperBuilder = TagHelperDescriptorBuilder.Create("PTagHelper", "SomeAssembly")
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"));
var strongTagHelperBuilder = TagHelperDescriptorBuilder.Create("StrongTagHelper", "SomeAssembly")
@@ -1104,18 +680,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
.Build(),
};
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors);
+ return descriptors;
}
[Fact]
public void Rewrite_AllowsSimpleHtmlCommentsAsChildren()
{
// Arrange
- IEnumerable allowedChildren = new List { "b" };
- string literal = "asdf";
- string commentOutput = "Hello World";
- string expectedOutput = $"{literal}
";
+ var allowedChildren = new List { "b" };
+ var literal = "asdf";
+ var commentOutput = "Hello World";
+ var document = $"{literal}
";
var pTagHelperBuilder = TagHelperDescriptorBuilder
.Create("PTagHelper", "SomeAssembly")
@@ -1130,40 +705,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
pTagHelperBuilder.Build()
};
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- var expectedMarkup = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(""),
- factory.Markup(literal),
- blockFactory.MarkupTagBlock(" "),
- blockFactory.HtmlCommentBlock(commentOutput)));
-
// Act & Assert
- EvaluateData(
- descriptors,
- expectedOutput,
- expectedMarkup,
- Array.Empty());
+ EvaluateData(descriptors, document);
}
[Fact]
public void Rewrite_DoesntAllowSimpleHtmlCommentsAsChildrenWhenFeatureFlagIsOff()
{
// Arrange
- Func nestedTagError =
- (childName, parentName, allowed, location, length) =>
- RazorDiagnosticFactory.CreateTagHelper_InvalidNestedTag(
- new SourceSpan(absoluteIndex: location, lineIndex: 0, characterIndex: location, length: length), childName, parentName, allowed);
- Func nestedContentError =
- (parentName, allowed, location, length) =>
- RazorDiagnosticFactory.CreateTagHelper_CannotHaveNonTagContent(
- new SourceSpan(absoluteIndex: location, lineIndex: 0, characterIndex: location, length: length), parentName, allowed);
-
- IEnumerable allowedChildren = new List { "b" };
- string comment1 = "Hello";
- string expectedOutput = $"
";
+ var allowedChildren = new List { "b" };
+ var comment1 = "Hello";
+ var document = $"
";
var pTagHelperBuilder = TagHelperDescriptorBuilder
.Create("PTagHelper", "SomeAssembly")
@@ -1178,24 +730,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
pTagHelperBuilder.Build()
};
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- var expectedMarkup = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.HtmlCommentBlock(comment1)));
-
// Act & Assert
EvaluateData(
descriptors,
- expectedOutput,
- expectedMarkup,
- new[]
- {
- nestedContentError("p", "b", 3, 4),
- nestedContentError("p", "b", 7, 5),
- nestedContentError("p", "b", 12, 3),
- },
+ document,
featureFlags: RazorParserFeatureFlags.Create(RazorLanguageVersion.Version_2_0));
}
@@ -1203,20 +741,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public void Rewrite_FailsForContentWithCommentsAsChildren()
{
// Arrange
- Func nestedTagError =
- (childName, parentName, allowed, location, length) =>
- RazorDiagnosticFactory.CreateTagHelper_InvalidNestedTag(
- new SourceSpan(absoluteIndex: location, lineIndex: 0, characterIndex: location, length: length), childName, parentName, allowed);
- Func nestedContentError =
- (parentName, allowed, location, length) =>
- RazorDiagnosticFactory.CreateTagHelper_CannotHaveNonTagContent(
- new SourceSpan(absoluteIndex: location, lineIndex: 0, characterIndex: location, length: length), parentName, allowed);
-
- IEnumerable allowedChildren = new List { "b" };
- string comment1 = "Hello";
- string literal = "asdf";
- string comment2 = "World";
- string expectedOutput = $"{literal}
";
+ var allowedChildren = new List { "b" };
+ var comment1 = "Hello";
+ var literal = "asdf";
+ var comment2 = "World";
+ var document = $"{literal}
";
var pTagHelperBuilder = TagHelperDescriptorBuilder
.Create("PTagHelper", "SomeAssembly")
@@ -1231,34 +760,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
pTagHelperBuilder.Build()
};
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- var expectedMarkup = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.HtmlCommentBlock(comment1),
- factory.Markup(literal),
- blockFactory.HtmlCommentBlock(comment2)));
-
// Act & Assert
- EvaluateData(
- descriptors,
- expectedOutput,
- expectedMarkup,
- new[]
- {
- nestedContentError("p", "b", 15, 4),
- });
+ EvaluateData(descriptors, document);
}
[Fact]
public void Rewrite_AllowsRazorCommentsAsChildren()
{
// Arrange
- IEnumerable allowedChildren = new List { "b" };
- string literal = "asdf";
- string commentOutput = $"@*{literal}*@";
- string expectedOutput = $"{literal} {commentOutput}
";
+ var allowedChildren = new List { "b" };
+ var literal = "asdf";
+ var commentOutput = $"@*{literal}*@";
+ var document = $"{literal} {commentOutput}
";
var pTagHelperBuilder = TagHelperDescriptorBuilder
.Create("PTagHelper", "SomeAssembly")
@@ -1273,40 +786,21 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
pTagHelperBuilder.Build()
};
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- var expectedMarkup = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(""),
- factory.Markup(literal),
- blockFactory.MarkupTagBlock(" "),
- new CommentBlock(
- Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None),
- Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
- Factory.Span(SpanKindInternal.Comment, new HtmlSymbol(literal, HtmlSymbolType.RazorComment)).Accepts(AcceptedCharactersInternal.Any),
- Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
- Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None))));
-
// Act & Assert
- EvaluateData(
- descriptors,
- expectedOutput,
- expectedMarkup,
- Array.Empty());
+ EvaluateData(descriptors, document);
}
[Fact]
public void Rewrite_AllowsRazorMarkupInHtmlComment()
{
// Arrange
- IEnumerable allowedChildren = new List { "b" };
- string literal = "asdf";
- string part1 = "Hello ";
- string part2 = "World";
- string commentStart = "";
- string expectedOutput = $"{literal} {commentStart}{part1}@{part2}{commentEnd}
";
+ var allowedChildren = new List { "b" };
+ var literal = "asdf";
+ var part1 = "Hello ";
+ var part2 = "World";
+ var commentStart = "";
+ var document = $"{literal} {commentStart}{part1}@{part2}{commentEnd}
";
var pTagHelperBuilder = TagHelperDescriptorBuilder
.Create("PTagHelper", "SomeAssembly")
@@ -1321,28 +815,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
pTagHelperBuilder.Build()
};
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- var expectedMarkup = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- blockFactory.MarkupTagBlock(""),
- factory.Markup(literal),
- blockFactory.MarkupTagBlock(" "),
- BlockFactory.HtmlCommentBlock(factory, f => new SyntaxTreeNode[] {
- f.Markup(part1).Accepts(AcceptedCharactersInternal.WhiteSpace),
- new ExpressionBlock(
- f.CodeTransition(),
- f.Code(part2)
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace)) })));
-
// Act & Assert
- EvaluateData(
- descriptors,
- expectedOutput,
- expectedMarkup,
- Array.Empty());
+ EvaluateData(descriptors, document);
}
[Fact]
@@ -1360,17 +834,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
.Build(),
};
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("p",
- BlockFactory.MarkupTagBlock("")));
- var expectedErrors = new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_CannotHaveNonTagContent(
- new SourceSpan(absoluteIndex: 3, lineIndex: 0, characterIndex: 3, length: 2), "p", "custom")
- };
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors);
+ EvaluateData(descriptors, documentContent);
}
[Fact]
@@ -1388,17 +854,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("*"))
.Build(),
};
- var expectedOutput = new MarkupBlock(
- new MarkupTagHelperBlock("th:p",
- BlockFactory.MarkupTagBlock("")));
- var expectedErrors = new[]
- {
- RazorDiagnosticFactory.CreateTagHelper_CannotHaveNonTagContent(
- new SourceSpan(absoluteIndex: 6, lineIndex: 0, characterIndex: 6, length: 2), "th:p", "custom")
- };
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors, "th:");
+ EvaluateData(descriptors, documentContent, "th:");
}
[Fact]
@@ -1406,7 +864,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
// Arrange
var documentContent = " ";
- var expectedOutput = new MarkupBlock(new MarkupTagHelperBlock("input", TagMode.StartTagOnly));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("InputTagHelper", "SomeAssembly")
@@ -1418,22 +875,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ EvaluateData(descriptors, documentContent);
}
[Fact]
public void Rewrite_CreatesErrorForWithoutEndTagTagStructureForEndTags()
{
// Arrange
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var expectedError = RazorDiagnosticFactory.CreateParsing_TagHelperMustNotHaveAnEndTag(
- new SourceSpan(filePath: null, absoluteIndex: 2, lineIndex: 0, characterIndex: 2, length: 5),
- "input",
- "InputTagHelper",
- TagStructure.WithoutEndTag);
var documentContent = "";
- var expectedOutput = new MarkupBlock(blockFactory.MarkupTagBlock(""));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("InputTagHelper", "SomeAssembly")
@@ -1445,19 +894,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new[] { expectedError });
+ EvaluateData(descriptors, documentContent);
}
[Fact]
public void Rewrite_CreatesErrorForInconsistentTagStructures()
{
// Arrange
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var expectedError = RazorDiagnosticFactory.CreateTagHelper_InconsistentTagStructure(
- new SourceSpan(absoluteIndex: 0, lineIndex: 0, characterIndex: 0, length: 7), "InputTagHelper1", "InputTagHelper2", "input");
var documentContent = " ";
- var expectedOutput = new MarkupBlock(new MarkupTagHelperBlock("input", TagMode.StartTagOnly));
var descriptors = new TagHelperDescriptor[]
{
TagHelperDescriptorBuilder.Create("InputTagHelper1", "SomeAssembly")
@@ -1475,2872 +919,960 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
// Act & Assert
- EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new[] { expectedError });
+ EvaluateData(descriptors, documentContent);
}
- public static TheoryData RequiredAttributeData
+ public static TagHelperDescriptor[] RequiredAttribute_Descriptors = new TagHelperDescriptor[]
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var dateTimeNow = new Func(index =>
- new MarkupBlock(
- new MarkupBlock(
- new DynamicAttributeBlockChunkGenerator(
- new LocationTagged(
- string.Empty,
- new SourceLocation(index, 0, index)),
- new SourceLocation(index, 0, index)),
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace)))));
+ TagHelperDescriptorBuilder.Create("pTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("p")
+ .RequireAttributeDescriptor(attribute => attribute.Name("class")))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("divTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("div")
+ .RequireAttributeDescriptor(attribute => attribute.Name("class"))
+ .RequireAttributeDescriptor(attribute => attribute.Name("style")))
+ .Build(),
+ TagHelperDescriptorBuilder.Create("catchAllTagHelper", "SomeAssembly")
+ .TagMatchingRuleDescriptor(rule =>
+ rule
+ .RequireTagName("*")
+ .RequireAttributeDescriptor(attribute => attribute.Name("catchAll")))
+ .Build()
+ };
- // documentContent, expectedOutput
- return new TheoryData
- {
- {
- "
",
- new MarkupBlock(blockFactory.MarkupTagBlock("
"))
- },
- {
- "
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("
"))
- },
- {
- "
",
- new MarkupBlock(blockFactory.MarkupTagBlock("
"))
- },
- {
- "
",
- new MarkupBlock(
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("
"))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", dateTimeNow(10))
- }))
- },
- {
- "words and spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "words and spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", dateTimeNow(10))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "wordsand spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new SyntaxTreeNode[]
- {
- factory.Markup("words"),
- blockFactory.MarkupTagBlock(""),
- factory.Markup("and"),
- blockFactory.MarkupTagBlock(" "),
- factory.Markup("spaces")
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", dateTimeNow(18))
- }))
- },
- {
- "words and spaces ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "words and spaces ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", dateTimeNow(18))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("(" class=\"", 4, 0, 4),
- suffix: new LocationTagged
("\"", 15, 0, 15)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 12, 0, 12),
- value: new LocationTagged("btn", 12, 0, 12))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(" />")))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagBlock(
- factory.Markup("(" class=\"", 4, 0, 4),
- suffix: new LocationTagged("\"", 15, 0, 15)),
- factory.Markup(" class=\"").With(SpanChunkGenerator.Null),
- factory.Markup("btn").With(
- new LiteralAttributeChunkGenerator(
- prefix: new LocationTagged(string.Empty, 12, 0, 12),
- value: new LocationTagged("btn", 12, 0, 12))),
- factory.Markup("\"").With(SpanChunkGenerator.Null)),
- factory.Markup(">")),
- blockFactory.MarkupTagBlock("
"))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("notRequired", factory.Markup("a")),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("notRequired", dateTimeNow(16)),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- }))
- },
- {
- "words and spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("notRequired", factory.Markup("a")),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("style", new MarkupBlock()),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("style", dateTimeNow(12)),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- }))
- },
- {
- "words and spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- attributes: new List
- {
- new TagHelperAttributeNode("style", new MarkupBlock()),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "words and spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- attributes: new List
- {
- new TagHelperAttributeNode("style", dateTimeNow(12)),
- new TagHelperAttributeNode("class", dateTimeNow(34))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "wordsand spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- attributes: new List
- {
- new TagHelperAttributeNode("style", new MarkupBlock()),
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new SyntaxTreeNode[]
- {
- factory.Markup("words"),
- blockFactory.MarkupTagBlock(""),
- factory.Markup("and"),
- blockFactory.MarkupTagBlock(" "),
- factory.Markup("spaces")
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn")),
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- }))
- },
- {
- "words and spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn")),
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- tagMode: TagMode.SelfClosing,
- attributes: new List
- {
- new TagHelperAttributeNode("style", new MarkupBlock()),
- new TagHelperAttributeNode("class", factory.Markup("btn")),
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- }))
- },
- {
- "words and spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- attributes: new List
- {
- new TagHelperAttributeNode("style", new MarkupBlock()),
- new TagHelperAttributeNode("class", factory.Markup("btn")),
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "words and spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- attributes: new List
- {
- new TagHelperAttributeNode("style", new MarkupBlock()),
- new TagHelperAttributeNode("class", factory.Markup("btn")),
- new TagHelperAttributeNode("catchAll",
- new MarkupBlock(
- new MarkupBlock(
- factory.Markup("@").Accepts(AcceptedCharactersInternal.None),
- factory.Markup("@").With(SpanChunkGenerator.Null).Accepts(AcceptedCharactersInternal.None)),
- factory.Markup("hi"))),
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "words and " +
- "spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- attributes: new List
- {
- new TagHelperAttributeNode("style", dateTimeNow(12)),
- new TagHelperAttributeNode("class", dateTimeNow(34)),
- new TagHelperAttributeNode("catchAll", dateTimeNow(59))
- },
- children: factory.Markup("words and spaces")))
- },
- {
- "wordsand spaces
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "div",
- attributes: new List
- {
- new TagHelperAttributeNode("style", new MarkupBlock()),
- new TagHelperAttributeNode("class", factory.Markup("btn")),
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new SyntaxTreeNode[]
- {
- factory.Markup("words"),
- blockFactory.MarkupTagBlock(""),
- factory.Markup("and"),
- blockFactory.MarkupTagBlock(" "),
- factory.Markup("spaces")
- }))
- },
- };
- }
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly1()
+ {
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- [Theory]
- [MemberData(nameof(RequiredAttributeData))]
- public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly2()
{
- // Arrange
- var descriptors = new TagHelperDescriptor[]
- {
- TagHelperDescriptorBuilder.Create("pTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("p")
- .RequireAttributeDescriptor(attribute => attribute.Name("class")))
- .Build(),
- TagHelperDescriptorBuilder.Create("divTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("div")
- .RequireAttributeDescriptor(attribute => attribute.Name("class"))
- .RequireAttributeDescriptor(attribute => attribute.Name("style")))
- .Build(),
- TagHelperDescriptorBuilder.Create("catchAllTagHelper", "SomeAssembly")
- .TagMatchingRuleDescriptor(rule =>
- rule
- .RequireTagName("*")
- .RequireAttributeDescriptor(attribute => attribute.Name("catchAll")))
- .Build()
- };
-
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- public static TheoryData NestedRequiredAttributeData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly3()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
- var dateTimeNow = new MarkupBlock(
- new MarkupBlock(
- new ExpressionBlock(
- factory.CodeTransition(),
- factory.Code("DateTime.Now")
- .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
- .Accepts(AcceptedCharactersInternal.NonWhiteSpace))));
-
- // documentContent, expectedOutput
- return new TheoryData
- {
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("
")
- }))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new SyntaxTreeNode[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "),
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("
"),
- blockFactory.MarkupTagBlock(" "),
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new SyntaxTreeNode[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "),
- blockFactory.MarkupTagBlock("
"),
- }))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("
")
- })))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "),
- })))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("
")
- })))
- },
- {
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "),
- })))
- },
- {
- "
",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("
"),
- new MarkupTagHelperBlock(
- "p",
- attributes: new List
- {
- new TagHelperAttributeNode("class", factory.Markup("btn"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock("
")
- }),
- blockFactory.MarkupTagBlock("
"),
- blockFactory.MarkupTagBlock(""),
- }))
- },
- {
- " " +
- " ",
- new MarkupBlock(
- new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(""),
- new MarkupTagHelperBlock(
- "strong",
- attributes: new List
- {
- new TagHelperAttributeNode("catchAll", factory.Markup("hi"))
- },
- children: new[]
- {
- blockFactory.MarkupTagBlock(""),
- blockFactory.MarkupTagBlock(" "),
- }),
- blockFactory.MarkupTagBlock(" "),
- blockFactory.MarkupTagBlock(" "),
- }))
- },
- };
- }
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- [Theory]
- [MemberData(nameof(NestedRequiredAttributeData))]
- public void Rewrite_NestedRequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly(
- string documentContent,
- object expectedOutput)
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly4()
{
- // Arrange
- var 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(),
- };
-
- // Act & Assert
- EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorDiagnostic[0]);
+ EvaluateData(RequiredAttribute_Descriptors, "
");
}
- public static TheoryData MalformedRequiredAttributeData
+ [Fact]
+ public void Rewrite_RequiredAttributeDescriptorsCreateTagHelperBlocksCorrectly5()
{
- get
- {
- var factory = new SpanFactory();
- var blockFactory = new BlockFactory(factory);
-
- // documentContent, expectedOutput, expectedErrors
- return new TheoryData
- {
- {
- "
- {
- 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