Naming improvements and test code cleanup

This commit is contained in:
Artak Mkrtchyan 2018-03-07 16:34:12 -08:00
parent 632c9dead7
commit 32e2c533c7
No known key found for this signature in database
GPG Key ID: 64D580ACBA8CA645
2 changed files with 19 additions and 21 deletions

View File

@ -614,8 +614,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{ {
if (NextIs(HtmlSymbolType.CloseAngle)) if (NextIs(HtmlSymbolType.CloseAngle))
{ {
// We're at the end of a comment. check the condition 2.3 to make sure the text ending is allowed. // Check condition 2.3: We're at the end of a comment. Check to make sure the text ending is allowed.
isValidComment = !EndsWithSymbolsSequence(p, HtmlSymbolType.OpenAngle, HtmlSymbolType.Bang, HtmlSymbolType.DoubleHyphen); isValidComment = !SymbolSequenceEndsWithItems(p, HtmlSymbolType.OpenAngle, HtmlSymbolType.Bang, HtmlSymbolType.DoubleHyphen);
breakLookahead = true; breakLookahead = true;
} }
else if (NextIs(ns => IsDashSymbol(ns) && NextIs(HtmlSymbolType.CloseAngle))) else if (NextIs(ns => IsDashSymbol(ns) && NextIs(HtmlSymbolType.CloseAngle)))
@ -645,17 +645,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return isValidComment; return isValidComment;
} }
private bool EndsWithSymbolsSequence(IEnumerable<HtmlSymbol> symbols, params HtmlSymbolType[] sequenceToMatchWith) internal static bool SymbolSequenceEndsWithItems(IEnumerable<HtmlSymbol> sequence, params HtmlSymbolType[] items)
{ {
int index = sequenceToMatchWith.Length; int index = items.Length;
foreach (var previousSymbol in symbols) foreach (var previousSymbol in sequence)
{ {
if (index == 0) if (index == 0)
{ {
break; break;
} }
if (sequenceToMatchWith[--index] != previousSymbol.Type) if (items[--index] != previousSymbol.Type)
return false; return false;
} }

View File

@ -60,11 +60,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public void LookaheadUntil_PassesThePreviousSymbolsInReverseOrder() public void LookaheadUntil_PassesThePreviousSymbolsInReverseOrder()
{ {
// Arrange // Arrange
var source = TestRazorSourceDocument.Create("asdf--fvd--<"); var tokenizer = CreateContentTokenizer("asdf--fvd--<");
var options = RazorParserOptions.CreateDefault();
var context = new ParserContext(source, options);
var tokenizer = new TestTokenizerBackedParser(HtmlLanguageCharacteristics.Instance, context);
// Act // Act
Stack<HtmlSymbol> symbols = new Stack<HtmlSymbol>(); Stack<HtmlSymbol> symbols = new Stack<HtmlSymbol>();
@ -86,11 +82,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public void LookaheadUntil_ReturnsFalseAfterIteratingOverAllSymbolsIfConditionIsNotMet() public void LookaheadUntil_ReturnsFalseAfterIteratingOverAllSymbolsIfConditionIsNotMet()
{ {
// Arrange // Arrange
var source = TestRazorSourceDocument.Create("asdf--fvd"); var tokenizer = CreateContentTokenizer("asdf--fvd");
var options = RazorParserOptions.CreateDefault();
var context = new ParserContext(source, options);
var tokenizer = new TestTokenizerBackedParser(HtmlLanguageCharacteristics.Instance, context);
// Act // Act
Stack<HtmlSymbol> symbols = new Stack<HtmlSymbol>(); Stack<HtmlSymbol> symbols = new Stack<HtmlSymbol>();
@ -112,11 +104,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public void LookaheadUntil_ReturnsTrueAndBreaksIteration() public void LookaheadUntil_ReturnsTrueAndBreaksIteration()
{ {
// Arrange // Arrange
var source = TestRazorSourceDocument.Create("asdf--fvd"); var tokenizer = CreateContentTokenizer("asdf--fvd");
var options = RazorParserOptions.CreateDefault();
var context = new ParserContext(source, options);
var tokenizer = new TestTokenizerBackedParser(HtmlLanguageCharacteristics.Instance, context);
// Act // Act
Stack<HtmlSymbol> symbols = new Stack<HtmlSymbol>(); Stack<HtmlSymbol> symbols = new Stack<HtmlSymbol>();
@ -133,6 +121,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Assert.Equal(new HtmlSymbol("asdf", HtmlSymbolType.Text), symbols.Pop()); Assert.Equal(new HtmlSymbol("asdf", HtmlSymbolType.Text), symbols.Pop());
} }
private static TestTokenizerBackedParser CreateContentTokenizer(string content)
{
var source = TestRazorSourceDocument.Create(content);
var options = RazorParserOptions.CreateDefault();
var context = new ParserContext(source, options);
var tokenizer = new TestTokenizerBackedParser(HtmlLanguageCharacteristics.Instance, context);
return tokenizer;
}
private class ExposedTokenizer : Tokenizer<CSharpSymbol, CSharpSymbolType> private class ExposedTokenizer : Tokenizer<CSharpSymbol, CSharpSymbolType>
{ {
public ExposedTokenizer(string input) public ExposedTokenizer(string input)