Final cleanup to remove all traces of ParseBlockTest (dotnet/aspnetcore-tooling#169)

\n\nCommit migrated from e160872142
This commit is contained in:
Ajay Bhargav Baaskaran 2019-01-24 12:42:10 -08:00 committed by GitHub
parent 67588374aa
commit 642a2f5789
2 changed files with 4 additions and 86 deletions

View File

@ -171,18 +171,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return Regex.Replace(content, "(?<!\r)\n", "\r\n", RegexOptions.None, TimeSpan.FromSeconds(10));
}
internal virtual void BaselineTest(RazorSyntaxTree syntaxTree, bool verifySyntaxTree = true, bool ensureFullFidelity = true, int? expectedParseLength = null)
internal virtual void BaselineTest(RazorSyntaxTree syntaxTree, bool verifySyntaxTree = true, bool ensureFullFidelity = true)
{
if (verifySyntaxTree)
{
SyntaxTreeVerifier.Verify(syntaxTree, ensureFullFidelity, expectedParseLength);
SyntaxTreeVerifier.Verify(syntaxTree, ensureFullFidelity);
}
AssertSyntaxTreeNodeMatchesBaseline(syntaxTree);
}
internal abstract RazorSyntaxTree ParseBlock(RazorLanguageVersion version, string document, IEnumerable<DirectiveDescriptor> directives, bool designTime);
internal RazorSyntaxTree ParseDocument(string document, bool designTime = false, IEnumerable<DirectiveDescriptor> directives = null, RazorParserFeatureFlags featureFlags = null)
{
return ParseDocument(RazorLanguageVersion.Latest, document, directives, designTime, featureFlags);
@ -218,85 +216,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return syntaxTree;
}
internal virtual RazorSyntaxTree ParseHtmlBlock(RazorLanguageVersion version, string document, IEnumerable<DirectiveDescriptor> directives, bool designTime = false)
{
directives = directives ?? Array.Empty<DirectiveDescriptor>();
var source = TestRazorSourceDocument.Create(document, filePath: null, relativePath: null, normalizeNewLines: true);
var options = CreateParserOptions(version, directives, designTime);
var context = new ParserContext(source, options);
var codeParser = new CSharpCodeParser(directives, context);
var markupParser = new HtmlMarkupParser(context);
codeParser.HtmlParser = markupParser;
markupParser.CodeParser = codeParser;
var root = markupParser.ParseBlock().CreateRed();
var diagnostics = context.ErrorSink.Errors;
var syntaxTree = RazorSyntaxTree.Create(root, source, diagnostics, options);
return syntaxTree;
}
internal virtual RazorSyntaxTree ParseCodeBlock(
RazorLanguageVersion version,
string document,
IEnumerable<DirectiveDescriptor> directives,
bool designTime)
{
directives = directives ?? Array.Empty<DirectiveDescriptor>();
var source = TestRazorSourceDocument.Create(document, filePath: null, relativePath: null, normalizeNewLines: true);
var options = CreateParserOptions(version, directives, designTime);
var context = new ParserContext(source, options);
var codeParser = new CSharpCodeParser(directives, context);
var markupParser = new HtmlMarkupParser(context);
codeParser.HtmlParser = markupParser;
markupParser.CodeParser = codeParser;
var root = codeParser.ParseBlock().CreateRed();
var diagnostics = context.ErrorSink.Errors;
var syntaxTree = RazorSyntaxTree.Create(root, source, diagnostics, options);
return syntaxTree;
}
internal virtual void ParseBlockTest(string document, int? expectedParseLength = null)
{
ParseBlockTest(document, null, false, expectedParseLength);
}
internal virtual void ParseBlockTest(string document, bool designTime, int? expectedParseLength = null)
{
ParseBlockTest(document, null, designTime, expectedParseLength);
}
internal virtual void ParseBlockTest(string document, IEnumerable<DirectiveDescriptor> directives, int? expectedParseLength = null)
{
ParseBlockTest(document, directives, false, expectedParseLength);
}
internal virtual void ParseBlockTest(string document, IEnumerable<DirectiveDescriptor> directives, bool designTime, int? expectedParseLength = null)
{
ParseBlockTest(RazorLanguageVersion.Latest, document, directives, designTime, expectedParseLength);
}
internal virtual void ParseBlockTest(RazorLanguageVersion version, string document, IEnumerable<DirectiveDescriptor> directives, bool designTime, int? expectedParseLength = null)
{
var result = ParseBlock(version, document, directives, designTime);
BaselineTest(result, expectedParseLength: expectedParseLength);
}
internal virtual void ParseDocumentTest(string document)
{
ParseDocumentTest(document, null, false);

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// Verifies recursively that a syntax tree has no gaps in terms of position/location.
internal class SyntaxTreeVerifier
{
public static void Verify(RazorSyntaxTree syntaxTree, bool ensureFullFidelity = true, int? expectedParseLength = null)
public static void Verify(RazorSyntaxTree syntaxTree, bool ensureFullFidelity = true)
{
var verifier = new Verifier(syntaxTree.Source);
verifier.Visit(syntaxTree.Root);
@ -21,8 +21,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{
var syntaxTreeString = syntaxTree.Root.ToFullString();
var builder = new StringBuilder(syntaxTree.Source.Length);
var sourceLength = expectedParseLength ?? syntaxTree.Source.Length;
for (var i = 0; i < sourceLength; i++)
for (var i = 0; i < syntaxTree.Source.Length; i++)
{
builder.Append(syntaxTree.Source[i]);
}