Merge branch 'rel/2.0.0' into dev
This commit is contained in:
commit
8bbfecb0da
|
|
@ -1787,39 +1787,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor.Usage == DirectiveUsage.FileScopedSinglyOccurring ||
|
|
||||||
descriptor.Usage == DirectiveUsage.FileScopedMultipleOccurring)
|
|
||||||
{
|
|
||||||
var root = Context.Builder.ActiveBlocks.Last();
|
|
||||||
for (var i = 0; i < root.Children.Count; i++)
|
|
||||||
{
|
|
||||||
// Directives, comments and whitespace are valid prior to an unnested directive.
|
|
||||||
|
|
||||||
var child = root.Children[i];
|
|
||||||
if (child is Legacy.Block block)
|
|
||||||
{
|
|
||||||
if (block.Type == BlockKindInternal.Directive || block.Type == BlockKindInternal.Comment)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (child is Span span)
|
|
||||||
{
|
|
||||||
if (span.Length == 0 ||
|
|
||||||
span.Kind == SpanKindInternal.Comment ||
|
|
||||||
span.Symbols.All(symbol => string.IsNullOrWhiteSpace(symbol.Content)))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UsageError(Resources.FormatDirectiveMustExistBeforeMarkupOrCode(descriptor.Directive));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
void UsageError(string message)
|
void UsageError(string message)
|
||||||
{
|
{
|
||||||
// There wil always be at least 1 child because of the `@` transition.
|
// There wil always be at least 1 child because of the `@` transition.
|
||||||
|
|
|
||||||
|
|
@ -528,20 +528,6 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
internal static string FormatDuplicateDirective(object p0)
|
internal static string FormatDuplicateDirective(object p0)
|
||||||
=> string.Format(CultureInfo.CurrentCulture, GetString("DuplicateDirective"), p0);
|
=> string.Format(CultureInfo.CurrentCulture, GetString("DuplicateDirective"), p0);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The '{0}' directive must exist prior to markup or code.
|
|
||||||
/// </summary>
|
|
||||||
internal static string DirectiveMustExistBeforeMarkupOrCode
|
|
||||||
{
|
|
||||||
get => GetString("DirectiveMustExistBeforeMarkupOrCode");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The '{0}' directive must exist prior to markup or code.
|
|
||||||
/// </summary>
|
|
||||||
internal static string FormatDirectiveMustExistBeforeMarkupOrCode(object p0)
|
|
||||||
=> string.Format(CultureInfo.CurrentCulture, GetString("DirectiveMustExistBeforeMarkupOrCode"), p0);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Block directive '{0}' cannot be imported.
|
/// Block directive '{0}' cannot be imported.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -228,9 +228,6 @@
|
||||||
<data name="DuplicateDirective" xml:space="preserve">
|
<data name="DuplicateDirective" xml:space="preserve">
|
||||||
<value>The '{0}' directive may only occur once per document.</value>
|
<value>The '{0}' directive may only occur once per document.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="DirectiveMustExistBeforeMarkupOrCode" xml:space="preserve">
|
|
||||||
<value>The '{0}' directive must exist prior to markup or code.</value>
|
|
||||||
</data>
|
|
||||||
<data name="BlockDirectiveCannotBeImported" xml:space="preserve">
|
<data name="BlockDirectiveCannotBeImported" xml:space="preserve">
|
||||||
<value>Block directive '{0}' cannot be imported.</value>
|
<value>Block directive '{0}' cannot be imported.</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,12 @@
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(4,1): Error RZ9999: The 'page' directive may only occur once per document.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(4,1): Error RZ9999: The 'page' directive may only occur once per document.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(5,1): Error RZ9999: The 'page' directive may only occur once per document.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(5,1): Error RZ9999: The 'page' directive may only occur once per document.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(5,7): Error RZ9999: The 'page' directive expects a string surrounded by double quotes.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(5,7): Error RZ9999: The 'page' directive expects a string surrounded by double quotes.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(7,1): Error RZ9999: The 'model' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(7,7): Error RZ9999: The 'model' directive expects a type name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(7,7): Error RZ9999: The 'model' directive expects a type name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,1): Error RZ9999: The 'model' directive may only occur once per document.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,1): Error RZ9999: The 'model' directive may only occur once per document.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,8): Error RZ9999: The 'model' directive expects a type name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,8): Error RZ9999: The 'model' directive expects a type name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(10,1): Error RZ9999: The 'inject' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(10,8): Error RZ9999: The 'inject' directive expects a type name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(10,8): Error RZ9999: The 'inject' directive expects a type name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(11,1): Error RZ9999: The 'inject' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(11,9): Error RZ9999: The 'inject' directive expects a type name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(11,9): Error RZ9999: The 'inject' directive expects a type name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(12,1): Error RZ9999: The 'inject' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(12,26): Error RZ9999: The 'inject' directive expects an identifier.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(12,26): Error RZ9999: The 'inject' directive expects an identifier.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(14,1): Error RZ9999: The 'namespace' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(14,11): Error RZ9999: The 'namespace' directive expects a namespace name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(14,11): Error RZ9999: The 'namespace' directive expects a namespace name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(15,1): Error RZ9999: The 'namespace' directive may only occur once per document.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(15,1): Error RZ9999: The 'namespace' directive may only occur once per document.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(15,12): Error RZ9999: The 'namespace' directive expects a namespace name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(15,12): Error RZ9999: The 'namespace' directive expects a namespace name.
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,12 @@
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(4,1): Error RZ9999: The 'page' directive may only occur once per document.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(4,1): Error RZ9999: The 'page' directive may only occur once per document.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(5,1): Error RZ9999: The 'page' directive may only occur once per document.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(5,1): Error RZ9999: The 'page' directive may only occur once per document.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(5,7): Error RZ9999: The 'page' directive expects a string surrounded by double quotes.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(5,7): Error RZ9999: The 'page' directive expects a string surrounded by double quotes.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(7,1): Error RZ9999: The 'model' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(7,7): Error RZ9999: The 'model' directive expects a type name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(7,7): Error RZ9999: The 'model' directive expects a type name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,1): Error RZ9999: The 'model' directive may only occur once per document.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,1): Error RZ9999: The 'model' directive may only occur once per document.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,8): Error RZ9999: The 'model' directive expects a type name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,8): Error RZ9999: The 'model' directive expects a type name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(10,1): Error RZ9999: The 'inject' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(10,8): Error RZ9999: The 'inject' directive expects a type name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(10,8): Error RZ9999: The 'inject' directive expects a type name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(11,1): Error RZ9999: The 'inject' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(11,9): Error RZ9999: The 'inject' directive expects a type name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(11,9): Error RZ9999: The 'inject' directive expects a type name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(12,1): Error RZ9999: The 'inject' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(12,26): Error RZ9999: The 'inject' directive expects an identifier.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(12,26): Error RZ9999: The 'inject' directive expects an identifier.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(14,1): Error RZ9999: The 'namespace' directive must exist prior to markup or code.
|
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(14,11): Error RZ9999: The 'namespace' directive expects a namespace name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(14,11): Error RZ9999: The 'namespace' directive expects a namespace name.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(15,1): Error RZ9999: The 'namespace' directive may only occur once per document.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(15,1): Error RZ9999: The 'namespace' directive may only occur once per document.
|
||||||
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(15,12): Error RZ9999: The 'namespace' directive expects a namespace name.
|
TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(15,12): Error RZ9999: The 'namespace' directive expects a namespace name.
|
||||||
|
|
|
||||||
|
|
@ -46,149 +46,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
Factory.EmptyHtml()));
|
Factory.EmptyHtml()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DirectiveDescriptor_FileScopedMultipleOccurring_MixedContentErrors()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var customDescriptor = DirectiveDescriptor.CreateDirective(
|
|
||||||
"custom",
|
|
||||||
DirectiveKind.SingleLine,
|
|
||||||
builder =>
|
|
||||||
{
|
|
||||||
builder.Usage = DirectiveUsage.FileScopedMultipleOccurring;
|
|
||||||
builder.AddTypeToken();
|
|
||||||
});
|
|
||||||
var chunkGenerator = new DirectiveChunkGenerator(customDescriptor);
|
|
||||||
chunkGenerator.Diagnostics.Add(
|
|
||||||
RazorDiagnostic.Create(
|
|
||||||
new RazorError(
|
|
||||||
Resources.FormatDirectiveMustExistBeforeMarkupOrCode("custom"),
|
|
||||||
151 + Environment.NewLine.Length * 4, 4, 0, 7)));
|
|
||||||
|
|
||||||
// Act & Assert
|
|
||||||
ParseDocumentTest(
|
|
||||||
@"@custom System.Text.Encoding.ASCIIEncoding
|
|
||||||
@* There is invalid content beneath this *@
|
|
||||||
<p>Should cause error</p>
|
|
||||||
@* There is invalid content above this *@
|
|
||||||
@custom Else",
|
|
||||||
new[] { customDescriptor },
|
|
||||||
new MarkupBlock(
|
|
||||||
Factory.EmptyHtml(),
|
|
||||||
new DirectiveBlock(new DirectiveChunkGenerator(customDescriptor),
|
|
||||||
Factory.CodeTransition(),
|
|
||||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
|
||||||
Factory.Span(SpanKindInternal.Code, "System.Text.Encoding.ASCIIEncoding", markup: false).AsDirectiveToken(customDescriptor.Tokens[0]),
|
|
||||||
Factory.MetaCode(Environment.NewLine).Accepts(AcceptedCharactersInternal.WhiteSpace)),
|
|
||||||
Factory.EmptyHtml(),
|
|
||||||
new CommentBlock(
|
|
||||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Comment, new HtmlSymbol(" There is invalid content beneath this ", HtmlSymbolType.RazorComment)).Accepts(AcceptedCharactersInternal.Any),
|
|
||||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None)),
|
|
||||||
Factory.Markup(Environment.NewLine),
|
|
||||||
BlockFactory.MarkupTagBlock("<p>"),
|
|
||||||
Factory.Markup("Should cause error"),
|
|
||||||
BlockFactory.MarkupTagBlock("</p>"),
|
|
||||||
Factory.Markup(Environment.NewLine),
|
|
||||||
new CommentBlock(
|
|
||||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Comment, new HtmlSymbol(" There is invalid content above this ", HtmlSymbolType.RazorComment)).Accepts(AcceptedCharactersInternal.Any),
|
|
||||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None)),
|
|
||||||
Factory.Markup(Environment.NewLine).With(SpanChunkGenerator.Null),
|
|
||||||
new DirectiveBlock(chunkGenerator,
|
|
||||||
Factory.CodeTransition(),
|
|
||||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
|
||||||
Factory.Span(SpanKindInternal.Code, "Else", markup: false).AsDirectiveToken(customDescriptor.Tokens[0])),
|
|
||||||
Factory.EmptyHtml()));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(DirectiveUsage.FileScopedSinglyOccurring)]
|
|
||||||
[InlineData(DirectiveUsage.FileScopedMultipleOccurring)]
|
|
||||||
public void DirectiveDescriptor_FileScopedSinglyOccurring_ErrorsIfNestedInCode(DirectiveUsage directiveUsage)
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var descriptor = DirectiveDescriptor.CreateDirective(
|
|
||||||
"custom",
|
|
||||||
DirectiveKind.SingleLine,
|
|
||||||
builder =>
|
|
||||||
{
|
|
||||||
builder.Usage = directiveUsage;
|
|
||||||
builder.AddTypeToken();
|
|
||||||
});
|
|
||||||
var chunkGenerator = new DirectiveChunkGenerator(descriptor);
|
|
||||||
chunkGenerator.Diagnostics.Add(
|
|
||||||
RazorDiagnostic.Create(
|
|
||||||
new RazorError(
|
|
||||||
Resources.FormatDirectiveMustExistBeforeMarkupOrCode("custom"),
|
|
||||||
1 + Environment.NewLine.Length, 1, 0, 7)));
|
|
||||||
|
|
||||||
// Act & Assert
|
|
||||||
ParseCodeBlockTest(
|
|
||||||
@"{
|
|
||||||
@custom System.Text.Encoding.ASCIIEncoding
|
|
||||||
}",
|
|
||||||
new[] { descriptor },
|
|
||||||
new StatementBlock(
|
|
||||||
Factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Code(Environment.NewLine)
|
|
||||||
.AsStatement()
|
|
||||||
.AutoCompleteWith(autoCompleteString: null, atEndOfSpan: false),
|
|
||||||
new DirectiveBlock(chunkGenerator,
|
|
||||||
Factory.CodeTransition(),
|
|
||||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
|
||||||
Factory.Span(SpanKindInternal.Code, "System.Text.Encoding.ASCIIEncoding", markup: false).AsDirectiveToken(descriptor.Tokens[0]),
|
|
||||||
Factory.MetaCode(Environment.NewLine).Accepts(AcceptedCharactersInternal.WhiteSpace)),
|
|
||||||
Factory.EmptyCSharp().AsStatement(),
|
|
||||||
Factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(DirectiveUsage.FileScopedSinglyOccurring)]
|
|
||||||
[InlineData(DirectiveUsage.FileScopedMultipleOccurring)]
|
|
||||||
public void DirectiveDescriptor_FileScoped_ErrorsIfNestedInHtml(DirectiveUsage directiveUsage)
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var descriptor = DirectiveDescriptor.CreateDirective(
|
|
||||||
"custom",
|
|
||||||
DirectiveKind.SingleLine,
|
|
||||||
builder =>
|
|
||||||
{
|
|
||||||
builder.Usage = directiveUsage;
|
|
||||||
builder.AddTypeToken();
|
|
||||||
});
|
|
||||||
var chunkGenerator = new DirectiveChunkGenerator(descriptor);
|
|
||||||
chunkGenerator.Diagnostics.Add(
|
|
||||||
RazorDiagnostic.Create(
|
|
||||||
new RazorError(
|
|
||||||
Resources.FormatDirectiveMustExistBeforeMarkupOrCode("custom"),
|
|
||||||
3 + Environment.NewLine.Length, 1, 0, 7)));
|
|
||||||
|
|
||||||
// Act & Assert
|
|
||||||
ParseDocumentTest(
|
|
||||||
@"<p>
|
|
||||||
@custom System.Text.Encoding.ASCIIEncoding
|
|
||||||
</p>",
|
|
||||||
new[] { descriptor },
|
|
||||||
new MarkupBlock(
|
|
||||||
BlockFactory.MarkupTagBlock("<p>"),
|
|
||||||
Factory.Markup(Environment.NewLine),
|
|
||||||
new DirectiveBlock(chunkGenerator,
|
|
||||||
Factory.CodeTransition(),
|
|
||||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
|
||||||
Factory.Span(SpanKindInternal.Code, "System.Text.Encoding.ASCIIEncoding", markup: false).AsDirectiveToken(descriptor.Tokens[0]),
|
|
||||||
Factory.MetaCode(Environment.NewLine).Accepts(AcceptedCharactersInternal.WhiteSpace)),
|
|
||||||
BlockFactory.MarkupTagBlock("</p>")));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DirectiveDescriptor_FileScopedSinglyOccurring_ErrorsIfDuplicate()
|
public void DirectiveDescriptor_FileScopedSinglyOccurring_ErrorsIfDuplicate()
|
||||||
{
|
{
|
||||||
|
|
@ -335,76 +192,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
BlockFactory.MarkupTagBlock("</p>")));
|
BlockFactory.MarkupTagBlock("</p>")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DirectiveDescriptor_FileScopedSinglyOccurring_MixedContentErrors()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var customDescriptor = DirectiveDescriptor.CreateDirective(
|
|
||||||
"custom",
|
|
||||||
DirectiveKind.SingleLine,
|
|
||||||
builder =>
|
|
||||||
{
|
|
||||||
builder.Usage = DirectiveUsage.FileScopedSinglyOccurring;
|
|
||||||
builder.AddTypeToken();
|
|
||||||
});
|
|
||||||
var somethingDescriptor = DirectiveDescriptor.CreateDirective(
|
|
||||||
"something",
|
|
||||||
DirectiveKind.SingleLine,
|
|
||||||
builder =>
|
|
||||||
{
|
|
||||||
builder.Usage = DirectiveUsage.FileScopedSinglyOccurring;
|
|
||||||
builder.AddMemberToken();
|
|
||||||
});
|
|
||||||
var chunkGenerator = new DirectiveChunkGenerator(somethingDescriptor);
|
|
||||||
chunkGenerator.Diagnostics.Add(
|
|
||||||
RazorDiagnostic.Create(
|
|
||||||
new RazorError(
|
|
||||||
Resources.FormatDirectiveMustExistBeforeMarkupOrCode("something"),
|
|
||||||
151 + Environment.NewLine.Length * 4, 4, 0, 10)));
|
|
||||||
|
|
||||||
// Act & Assert
|
|
||||||
ParseDocumentTest(
|
|
||||||
@"@custom System.Text.Encoding.ASCIIEncoding
|
|
||||||
@* There is invalid content beneath this *@
|
|
||||||
<p>Should cause error</p>
|
|
||||||
@* There is invalid content above this *@
|
|
||||||
@something Else",
|
|
||||||
new[] { customDescriptor, somethingDescriptor },
|
|
||||||
new MarkupBlock(
|
|
||||||
Factory.EmptyHtml(),
|
|
||||||
new DirectiveBlock(new DirectiveChunkGenerator(customDescriptor),
|
|
||||||
Factory.CodeTransition(),
|
|
||||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
|
||||||
Factory.Span(SpanKindInternal.Code, "System.Text.Encoding.ASCIIEncoding", markup: false).AsDirectiveToken(customDescriptor.Tokens[0]),
|
|
||||||
Factory.MetaCode(Environment.NewLine).Accepts(AcceptedCharactersInternal.WhiteSpace)),
|
|
||||||
Factory.EmptyHtml(),
|
|
||||||
new CommentBlock(
|
|
||||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Comment, new HtmlSymbol(" There is invalid content beneath this ", HtmlSymbolType.RazorComment)).Accepts(AcceptedCharactersInternal.Any),
|
|
||||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None)),
|
|
||||||
Factory.Markup(Environment.NewLine),
|
|
||||||
BlockFactory.MarkupTagBlock("<p>"),
|
|
||||||
Factory.Markup("Should cause error"),
|
|
||||||
BlockFactory.MarkupTagBlock("</p>"),
|
|
||||||
Factory.Markup(Environment.NewLine),
|
|
||||||
new CommentBlock(
|
|
||||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Comment, new HtmlSymbol(" There is invalid content above this ", HtmlSymbolType.RazorComment)).Accepts(AcceptedCharactersInternal.Any),
|
|
||||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None)),
|
|
||||||
Factory.Markup(Environment.NewLine).With(SpanChunkGenerator.Null),
|
|
||||||
new DirectiveBlock(chunkGenerator,
|
|
||||||
Factory.CodeTransition(),
|
|
||||||
Factory.MetaCode("something").Accepts(AcceptedCharactersInternal.None),
|
|
||||||
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
|
||||||
Factory.Span(SpanKindInternal.Code, "Else", markup: false).AsDirectiveToken(somethingDescriptor.Tokens[0])),
|
|
||||||
Factory.EmptyHtml()));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DirectiveDescriptor_TokensMustBeSeparatedBySpace()
|
public void DirectiveDescriptor_TokensMustBeSeparatedBySpace()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue