Allow nullable types with generic arguments in directives

This commit is contained in:
Ajay Bhargav Baaskaran 2017-08-09 15:17:21 -07:00
parent 4fe07f2298
commit 364fc1a55d
2 changed files with 30 additions and 1 deletions

View File

@ -959,7 +959,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
if (Optional(CSharpSymbolType.Identifier) || Optional(CSharpSymbolType.Keyword))
{
Optional(CSharpSymbolType.QuestionMark); // Nullable
if (Optional(CSharpSymbolType.DoubleColon))
{
if (!Optional(CSharpSymbolType.Identifier))
@ -975,6 +974,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
NamespaceOrTypeName();
}
Optional(CSharpSymbolType.QuestionMark); // Nullable
while (At(CSharpSymbolType.LeftBracket))
{
Balance(BalancingModes.None);

View File

@ -784,6 +784,33 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Factory.MetaCode(" ; ").Accepts(AcceptedCharactersInternal.WhiteSpace)));
}
[Theory]
[InlineData("string?")]
[InlineData("string?[]")]
[InlineData("global::System.Int32?")]
[InlineData("KeyValuePair<string, string>?")]
[InlineData("KeyValuePair<string, string>?[]")]
[InlineData("global::System.Collections.Generic.KeyValuePair<string, string>?[]")]
public void DirectiveDescriptor_AllowsNullableTypes(string expectedType)
{
// Arrange
var descriptor = DirectiveDescriptor.CreateDirective(
"custom",
DirectiveKind.SingleLine,
b => b.AddTypeToken());
// Act & Assert
ParseCodeBlockTest(
$"@custom {expectedType}",
new[] { descriptor },
new DirectiveBlock(
new DirectiveChunkGenerator(descriptor),
Factory.CodeTransition(),
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
Factory.Span(SpanKindInternal.Code, expectedType, markup: false).AsDirectiveToken(descriptor.Tokens[0])));
}
[Fact]
public void DirectiveDescriptor_ErrorsExtraContentAfterDirective()
{