Remove literal directive tokens.

- Literal directive tokens acted as a way for a user to provide markup bits to be required when parsing a directive.
- Removed source implementations.
- Removed tests validating the feature.

#969
This commit is contained in:
N. Taylor Mullen 2017-02-02 15:06:06 -08:00
parent a801a49377
commit 3f5d1bb2d6
9 changed files with 4 additions and 109 deletions

View File

@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
const string TypeHelper = "__typeHelper";
var tokenKind = node.Descriptor.Kind;
if (node.Source == null || node.Descriptor.Kind == DirectiveTokenKind.Literal)
if (node.Source == null)
{
return;
}

View File

@ -68,18 +68,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
return this;
}
public IDirectiveDescriptorBuilder AddLiteral(string literal)
{
var descriptor = new DirectiveTokenDescriptor()
{
Kind = DirectiveTokenKind.Literal,
Value = literal,
};
_tokenDescriptors.Add(descriptor);
return this;
}
public DirectiveDescriptor Build()
{
var descriptor = new DirectiveDescriptor

View File

@ -6,7 +6,5 @@ namespace Microsoft.AspNetCore.Razor.Evolution
public class DirectiveTokenDescriptor
{
public DirectiveTokenKind Kind { get; set; }
public string Value { get; set; }
}
}

View File

@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
}
return descriptorX != null &&
string.Equals(descriptorX.Value, descriptorY.Value, StringComparison.Ordinal) &&
descriptorX.Kind == descriptorY.Kind;
}
@ -34,11 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
throw new ArgumentNullException(nameof(descriptor));
}
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(descriptor.Value, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.Kind);
return hashCodeCombiner.CombinedHash;
return descriptor.Kind.GetHashCode();
}
}
}

View File

@ -8,6 +8,5 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Type,
Member,
String,
Literal
}
}

View File

@ -11,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
IDirectiveDescriptorBuilder AddString();
IDirectiveDescriptorBuilder AddLiteral(string literal);
DirectiveDescriptor Build();
}
}

View File

@ -1551,20 +1551,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
case DirectiveTokenKind.String:
AcceptAndMoveNext();
break;
case DirectiveTokenKind.Literal:
if (string.Equals(CurrentSymbol.Content, tokenDescriptor.Value, StringComparison.Ordinal))
{
AcceptAndMoveNext();
}
else
{
Context.ErrorSink.OnError(
CurrentStart,
LegacyResources.FormatUnexpectedDirectiveLiteral(descriptor.Name, tokenDescriptor.Value),
CurrentSymbol.Content.Length);
return;
}
break;
}
Span.ChunkGenerator = new DirectiveTokenChunkGenerator(tokenDescriptor);

View File

@ -79,21 +79,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Assert.Equal(DirectiveTokenKind.String, token.Kind);
}
[Fact]
public void AddLiteral_AddsToken()
{
// Arrange
var builder = DirectiveDescriptorBuilder.Create("custom");
// Act
var descriptor = builder.AddLiteral(",").Build();
// Assert
var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.Literal, token.Kind);
Assert.Equal(",", token.Value);
}
[Fact]
public void AddX_MaintainsMultipleTokens()
{
@ -105,19 +90,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution
.AddType()
.AddMember()
.AddString()
.AddLiteral(",")
.Build();
// Assert
Assert.Collection(descriptor.Tokens,
token => Assert.Equal(DirectiveTokenKind.Type, token.Kind),
token => Assert.Equal(DirectiveTokenKind.Member, token.Kind),
token => Assert.Equal(DirectiveTokenKind.String, token.Kind),
token =>
{
Assert.Equal(DirectiveTokenKind.Literal, token.Kind);
Assert.Equal(",", token.Value);
});
token => Assert.Equal(DirectiveTokenKind.String, token.Kind));
}
}
}

View File

@ -70,26 +70,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
.Accepts(AcceptedCharacters.NonWhiteSpace)));
}
[Fact]
public void DirectiveDescriptor_UnderstandsLiteralTokens()
{
// Arrange
var descriptor = DirectiveDescriptorBuilder.Create("custom").AddLiteral("!").Build();
// Act & Assert
ParseCodeBlockTest(
"@custom !",
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, "!", markup: false)
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
.Accepts(AcceptedCharacters.NonWhiteSpace)));
}
[Fact]
public void DirectiveDescriptor_UnderstandsMultipleTokens()
{
@ -98,12 +78,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
.AddType()
.AddMember()
.AddString()
.AddLiteral("!")
.Build();
// Act & Assert
ParseCodeBlockTest(
"@custom System.Text.Encoding.ASCIIEncoding Some_Member AString !",
"@custom System.Text.Encoding.ASCIIEncoding Some_Member AString",
new[] { descriptor },
new DirectiveBlock(
new DirectiveChunkGenerator(descriptor),
@ -123,11 +102,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
Factory.Span(SpanKind.Markup, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace),
Factory.Span(SpanKind.Markup, "AString", markup: false)
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[2]))
.Accepts(AcceptedCharacters.NonWhiteSpace),
Factory.Span(SpanKind.Markup, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace),
Factory.Span(SpanKind.Markup, "!", markup: false)
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[3]))
.Accepts(AcceptedCharacters.NonWhiteSpace)));
}
@ -244,28 +218,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
expectedErorr);
}
[Fact]
public void DirectiveDescriptor_ErrorsForUnmatchedLiteralTokens()
{
// Arrange
var descriptor = DirectiveDescriptorBuilder.Create("custom").AddLiteral("!").Build();
var expectedErorr = new RazorError(
LegacyResources.FormatUnexpectedDirectiveLiteral("custom", "!"),
new SourceLocation(8, 0, 8),
length: 2);
// Act & Assert
ParseCodeBlockTest(
"@custom hi",
new[] { descriptor },
new DirectiveBlock(
new DirectiveChunkGenerator(descriptor),
Factory.CodeTransition(),
Factory.MetaCode("custom").Accepts(AcceptedCharacters.None),
Factory.Span(SpanKind.Markup, " ", markup: false).Accepts(AcceptedCharacters.WhiteSpace)),
expectedErorr);
}
[Fact]
public void DirectiveDescriptor_ErrorsExtraContentAfterDirective()
{