Handle single line directives properly

This commit is contained in:
Ajay Bhargav Baaskaran 2017-02-08 13:41:27 -08:00
parent d293547f24
commit 02675da467
2 changed files with 22 additions and 0 deletions

View File

@ -1568,6 +1568,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
{
case DirectiveDescriptorKind.SingleLine:
Optional(CSharpSymbolType.Semicolon);
AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: true));
if (At(CSharpSymbolType.NewLine))
{

View File

@ -218,6 +218,27 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
expectedErorr);
}
[Fact]
public void DirectiveDescriptor_NoErrorsSemicolonAfterDirective()
{
// Arrange
var descriptor = DirectiveDescriptorBuilder.Create("custom").AddString().Build();
// Act & Assert
ParseCodeBlockTest(
"@custom hello ; ",
new[] { descriptor },
new DirectiveBlock(
new DirectiveChunkGenerator(descriptor),
Factory.CodeTransition(),
Factory.MetaCode("custom").Accepts(AcceptedCharacters.None),
Factory.Span(SpanKind.Markup, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace),
Factory.Span(SpanKind.Markup, "hello", markup: false)
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
.Accepts(AcceptedCharacters.NonWhiteSpace),
Factory.Span(SpanKind.Markup, " ; ", markup: false).Accepts(AcceptedCharacters.WhiteSpace)));
}
[Fact]
public void DirectiveDescriptor_ErrorsExtraContentAfterDirective()
{