Naming improvements and test code cleanup
This commit is contained in:
parent
632c9dead7
commit
32e2c533c7
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue