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

View File

@ -60,11 +60,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public void LookaheadUntil_PassesThePreviousSymbolsInReverseOrder()
{
// Arrange
var source = TestRazorSourceDocument.Create("asdf--fvd--<");
var options = RazorParserOptions.CreateDefault();
var context = new ParserContext(source, options);
var tokenizer = new TestTokenizerBackedParser(HtmlLanguageCharacteristics.Instance, context);
var tokenizer = CreateContentTokenizer("asdf--fvd--<");
// Act
Stack<HtmlSymbol> symbols = new Stack<HtmlSymbol>();
@ -86,11 +82,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public void LookaheadUntil_ReturnsFalseAfterIteratingOverAllSymbolsIfConditionIsNotMet()
{
// Arrange
var source = TestRazorSourceDocument.Create("asdf--fvd");
var options = RazorParserOptions.CreateDefault();
var context = new ParserContext(source, options);
var tokenizer = new TestTokenizerBackedParser(HtmlLanguageCharacteristics.Instance, context);
var tokenizer = CreateContentTokenizer("asdf--fvd");
// Act
Stack<HtmlSymbol> symbols = new Stack<HtmlSymbol>();
@ -112,11 +104,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public void LookaheadUntil_ReturnsTrueAndBreaksIteration()
{
// Arrange
var source = TestRazorSourceDocument.Create("asdf--fvd");
var options = RazorParserOptions.CreateDefault();
var context = new ParserContext(source, options);
var tokenizer = new TestTokenizerBackedParser(HtmlLanguageCharacteristics.Instance, context);
var tokenizer = CreateContentTokenizer("asdf--fvd");
// Act
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());
}
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>
{
public ExposedTokenizer(string input)