Parser tests clean up
This commit is contained in:
parent
f9a09372b7
commit
ed7c4e8f5c
|
|
@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpAutoCompleteTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpAutoCompleteTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FunctionsDirectiveAutoCompleteAtEOF()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpBlockTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpBlockTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBlock_NestedCodeBlockWithCSharpAt()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,11 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpDirectivesTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpDirectivesTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DirectiveDescriptor_FileScopedMultipleOccurring_CanHaveDuplicates()
|
||||
{
|
||||
|
|
@ -921,13 +916,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
var result = ParseCodeBlock(RazorLanguageVersion.Latest, document, descriptors, designTime: false);
|
||||
|
||||
if (UseBaselineTests && !IsTheory)
|
||||
{
|
||||
BaselineTest(result);
|
||||
return;
|
||||
}
|
||||
|
||||
EvaluateResults(result, expected, expectedErrors);
|
||||
BaselineTest(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpErrorTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpErrorTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBlockHandlesQuotesAfterTransition()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpExplicitExpressionTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpExplicitExpressionTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBlockShouldOutputZeroLengthCodeSpanIfExplicitExpressionIsEmpty()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpImplicitExpressionTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpImplicitExpressionTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBlockMethodParsesNullConditionalOperatorImplicitExpression_Bracket1()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpNestedStatementsTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpNestedStatementsTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NestedSimpleStatement()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpRazorCommentsTest : CsHtmlMarkupParserTestBase
|
||||
{
|
||||
public CSharpRazorCommentsTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnterminatedRazorComment()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpReservedWordsTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpReservedWordsTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReservedWord()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpSectionTest : CsHtmlMarkupParserTestBase
|
||||
{
|
||||
public CSharpSectionTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseSectionBlockCapturesNewlineImmediatelyFollowing()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpSpecialBlockTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpSpecialBlockTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NamespaceImportInsideCodeBlockCausesError()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,11 +16,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
|
||||
public class CSharpStatementTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpStatementTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ForStatement()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,12 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpTemplateTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpTemplateTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ParseBlockHandlesSingleLineTemplate()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpToMarkupSwitchTest : CsHtmlCodeParserTestBase
|
||||
{
|
||||
public CSharpToMarkupSwitchTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SingleAngleBracketDoesNotCauseSwitchIfOuterBlockIsTerminated()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
private const string TestExtraKeyword = "model";
|
||||
|
||||
public CSharpVerbatimBlockTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VerbatimBlock()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class CSharpWhitespaceHandlingTest : CsHtmlMarkupParserTestBase
|
||||
{
|
||||
public CSharpWhitespaceHandlingTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StatementBlockDoesNotAcceptTrailingNewlineIfNewlinesAreSignificantToAncestor()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -58,12 +58,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
SingleSpanBlockTest(document, document, blockKind, spanType, acceptedCharacters, expectedError);
|
||||
}
|
||||
|
||||
internal override void SingleSpanBlockTest(string document, string spanContent, BlockKindInternal blockKind, SpanKindInternal spanType, AcceptedCharactersInternal acceptedCharacters, params RazorDiagnostic[] expectedErrors)
|
||||
{
|
||||
var b = CreateSimpleBlockAndSpan(spanContent, blockKind, spanType, acceptedCharacters);
|
||||
ParseBlockTest(document, b, expectedErrors ?? new RazorDiagnostic[0]);
|
||||
}
|
||||
|
||||
internal void ImplicitExpressionTest(string input, string expected, AcceptedCharactersInternal acceptedCharacters, params RazorDiagnostic[] errors)
|
||||
{
|
||||
ParseBlockTest(SyntaxConstants.TransitionString + input);
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||
{
|
||||
public static class ExceptionHelpers
|
||||
{
|
||||
public static void ValidateArgumentException(string parameterName, string expectedMessage, ArgumentException exception)
|
||||
{
|
||||
Assert.Equal(string.Format("{0}{1}Parameter name: {2}", expectedMessage, Environment.NewLine, parameterName), exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class HtmlAttributeTest : CsHtmlMarkupParserTestBase
|
||||
{
|
||||
public HtmlAttributeTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SymbolBoundAttributes_BeforeEqualWhitespace1()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class HtmlBlockTest : CsHtmlMarkupParserTestBase
|
||||
{
|
||||
public HtmlBlockTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBlockHandlesUnbalancedTripleDashHTMLComments()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
private static readonly TestFile Nested1000 = TestFile.Create("TestFiles/nested-1000.html", typeof(HtmlDocumentTest));
|
||||
|
||||
public HtmlDocumentTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseDocument_NestedCodeBlockWithMarkupSetsDotAsMarkup()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class HtmlErrorTest : CsHtmlMarkupParserTestBase
|
||||
{
|
||||
public HtmlErrorTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBlockAllowsInvalidTagNamesAsLongAsParserCanIdentifyEndTag()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,11 +28,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
"wbr",
|
||||
};
|
||||
|
||||
public HtmlTagsTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyTagNestsLikeNormalTag()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class HtmlToCodeSwitchTest : CsHtmlMarkupParserTestBase
|
||||
{
|
||||
public HtmlToCodeSwitchTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseBlockSwitchesWhenCharacterBeforeSwapIsNonAlphanumeric()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,11 +15,5 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
return ParseHtmlBlock(version, document, directives, designTime);
|
||||
}
|
||||
|
||||
internal virtual void SingleSpanDocumentTest(string document, BlockKindInternal blockKind, SpanKindInternal spanType)
|
||||
{
|
||||
var b = CreateSimpleBlockAndSpan(document, blockKind, spanType);
|
||||
ParseDocumentTest(document, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
#if DEBUG
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
#endif
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||
{
|
||||
class MiscUtils
|
||||
{
|
||||
public const int TimeoutInSeconds = 1;
|
||||
|
||||
public static void DoWithTimeoutIfNotDebugging(Func<int, bool> withTimeout)
|
||||
{
|
||||
#if DEBUG
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
withTimeout(Timeout.Infinite);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
Assert.True(withTimeout((int)TimeSpan.FromSeconds(TimeoutInSeconds).TotalMilliseconds), "Timeout expired!");
|
||||
#if DEBUG
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -26,7 +25,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
var factory = new SpanFactory();
|
||||
var parser = new RazorParser();
|
||||
|
||||
// Act/Assert
|
||||
// Act
|
||||
var syntaxTree = parser.Parse(TestRazorSourceDocument.Create("foo @bar baz"));
|
||||
|
||||
// Assert
|
||||
ParserTestBase.EvaluateResults(parser.Parse(TestRazorSourceDocument.Create("foo @bar baz")),
|
||||
new MarkupBlock(
|
||||
factory.Markup("foo "),
|
||||
|
|
|
|||
|
|
@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class TagHelperBlockRewriterTest : TagHelperRewritingTestBase
|
||||
{
|
||||
public TagHelperBlockRewriterTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
public static TagHelperDescriptor[] SymbolBoundAttributes_Descriptors = new[]
|
||||
{
|
||||
TagHelperDescriptorBuilder.Create("CatchAllTagHelper", "SomeAssembly")
|
||||
|
|
|
|||
|
|
@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class TagHelperParseTreeRewriterTest : TagHelperRewritingTestBase
|
||||
{
|
||||
public TagHelperParseTreeRewriterTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
public static TheoryData GetAttributeNameValuePairsData
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -83,14 +83,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
.OrderBy(error => error.Span.AbsoluteIndex)
|
||||
.ToList();
|
||||
|
||||
if (UseBaselineTests && !IsTheory)
|
||||
{
|
||||
BaselineTest(actualTree, verifySyntaxTree: false, actualErrors.ToArray());
|
||||
return;
|
||||
}
|
||||
|
||||
EvaluateRazorErrors(actualErrors, expectedErrors.ToList());
|
||||
EvaluateParseTree(actualTree, expectedOutput);
|
||||
BaselineTest(actualTree, verifySyntaxTree: false, actualErrors.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
public class WhiteSpaceRewriterTest : CsHtmlMarkupParserTestBase
|
||||
{
|
||||
public WhiteSpaceRewriterTest()
|
||||
{
|
||||
UseBaselineTests = true;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
private static readonly AsyncLocal<bool> _isTheory = new AsyncLocal<bool>();
|
||||
#endif
|
||||
|
||||
internal static Block IgnoreOutput = new IgnoreOutputBlock();
|
||||
|
||||
internal ParserTestBase()
|
||||
{
|
||||
Factory = CreateSpanFactory();
|
||||
|
|
@ -55,8 +53,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
|
||||
protected string TestProjectRoot { get; }
|
||||
|
||||
protected bool UseBaselineTests { get; set; }
|
||||
|
||||
// Used by the test framework to set the 'base' name for test files.
|
||||
public static string FileName
|
||||
{
|
||||
|
|
@ -107,6 +103,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
if (IsTheory)
|
||||
{
|
||||
var message = $"{nameof(AssertSyntaxTreeNodeMatchesBaseline)} should not be called from a [Theory] test.";
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
var baselineFileName = Path.ChangeExtension(FileName, ".syntaxtree.txt");
|
||||
var baselineDiagnosticsFileName = Path.ChangeExtension(FileName, ".diagnostics.txt");
|
||||
|
||||
|
|
@ -218,7 +220,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
directives = directives ?? Array.Empty<DirectiveDescriptor>();
|
||||
|
||||
var source = TestRazorSourceDocument.Create(document, filePath: null, normalizeNewLines: UseBaselineTests);
|
||||
var source = TestRazorSourceDocument.Create(document, filePath: null, normalizeNewLines: true);
|
||||
|
||||
var options = CreateParserOptions(version, directives, designTime);
|
||||
var context = new ParserContext(source, options);
|
||||
|
|
@ -249,7 +251,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
directives = directives ?? Array.Empty<DirectiveDescriptor>();
|
||||
|
||||
var source = TestRazorSourceDocument.Create(document, filePath: null, normalizeNewLines: UseBaselineTests);
|
||||
var source = TestRazorSourceDocument.Create(document, filePath: null, normalizeNewLines: true);
|
||||
var options = CreateParserOptions(version, directives, designTime);
|
||||
var context = new ParserContext(source, options);
|
||||
|
||||
|
|
@ -280,7 +282,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
directives = directives ?? Array.Empty<DirectiveDescriptor>();
|
||||
|
||||
var source = TestRazorSourceDocument.Create(document, filePath: null, normalizeNewLines: UseBaselineTests);
|
||||
var source = TestRazorSourceDocument.Create(document, filePath: null, normalizeNewLines: true);
|
||||
var options = CreateParserOptions(version, directives, designTime);
|
||||
var context = new ParserContext(source, options);
|
||||
|
||||
|
|
@ -384,27 +386,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
var result = ParseBlock(version, document, directives, designTime);
|
||||
|
||||
if (UseBaselineTests && !IsTheory)
|
||||
{
|
||||
BaselineTest(result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (FixupSpans)
|
||||
{
|
||||
SpancestryCorrector.Correct(expected);
|
||||
|
||||
var span = expected.FindFirstDescendentSpan();
|
||||
span.ChangeStart(SourceLocation.Zero);
|
||||
}
|
||||
|
||||
SyntaxTreeVerifier.Verify(result);
|
||||
SyntaxTreeVerifier.Verify(expected);
|
||||
|
||||
if (!ReferenceEquals(expected, IgnoreOutput))
|
||||
{
|
||||
EvaluateResults(result, expected, expectedErrors);
|
||||
}
|
||||
BaselineTest(result);
|
||||
}
|
||||
|
||||
internal virtual void SingleSpanBlockTest(string document)
|
||||
|
|
@ -441,31 +423,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
var result = ParseBlock(document, designTime: false);
|
||||
|
||||
if (UseBaselineTests && !IsTheory)
|
||||
{
|
||||
BaselineTest(result);
|
||||
return;
|
||||
}
|
||||
|
||||
var builder = new BlockBuilder();
|
||||
builder.Type = blockKind;
|
||||
var expected = ConfigureAndAddSpanToBlock(builder, Factory.Span(spanType, spanContent, spanType == SpanKindInternal.Markup).Accepts(acceptedCharacters));
|
||||
|
||||
if (FixupSpans)
|
||||
{
|
||||
SpancestryCorrector.Correct(expected);
|
||||
|
||||
var span = expected.FindFirstDescendentSpan();
|
||||
span.ChangeStart(SourceLocation.Zero);
|
||||
}
|
||||
|
||||
SyntaxTreeVerifier.Verify(result);
|
||||
SyntaxTreeVerifier.Verify(expected);
|
||||
|
||||
if (!ReferenceEquals(expected, IgnoreOutput))
|
||||
{
|
||||
EvaluateResults(result, expected, expectedErrors);
|
||||
}
|
||||
BaselineTest(result);
|
||||
}
|
||||
|
||||
internal virtual void ParseDocumentTest(string document)
|
||||
|
|
@ -512,49 +470,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
var result = ParseDocument(document, directives, designTime);
|
||||
|
||||
if (UseBaselineTests && !IsTheory)
|
||||
{
|
||||
BaselineTest(result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (FixupSpans)
|
||||
{
|
||||
SpancestryCorrector.Correct(expected);
|
||||
|
||||
var span = expected.FindFirstDescendentSpan();
|
||||
span.ChangeStart(SourceLocation.Zero);
|
||||
}
|
||||
|
||||
SyntaxTreeVerifier.Verify(result);
|
||||
SyntaxTreeVerifier.Verify(expected);
|
||||
|
||||
if (!ReferenceEquals(expected, IgnoreOutput))
|
||||
{
|
||||
EvaluateResults(result, expected, expectedErrors);
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("PARSER_TRACE")]
|
||||
private void WriteNode(int indent, SyntaxTreeNode node)
|
||||
{
|
||||
var content = node.ToString().Replace("\r", "\\r")
|
||||
.Replace("\n", "\\n")
|
||||
.Replace("{", "{{")
|
||||
.Replace("}", "}}");
|
||||
if (indent > 0)
|
||||
{
|
||||
content = new String('.', indent * 2) + content;
|
||||
}
|
||||
WriteTraceLine(content);
|
||||
var block = node as Block;
|
||||
if (block != null)
|
||||
{
|
||||
foreach (SyntaxTreeNode child in block.Children)
|
||||
{
|
||||
WriteNode(indent + 1, child);
|
||||
}
|
||||
}
|
||||
BaselineTest(result);
|
||||
}
|
||||
|
||||
internal static void EvaluateResults(RazorSyntaxTree result, Block expectedRoot)
|
||||
|
|
@ -594,35 +510,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
}
|
||||
}
|
||||
|
||||
private static void EvaluateTagHelperAttribute(
|
||||
ErrorCollector collector,
|
||||
TagHelperAttributeNode actual,
|
||||
TagHelperAttributeNode expected)
|
||||
{
|
||||
if (actual.Name != expected.Name)
|
||||
{
|
||||
collector.AddError("{0} - FAILED :: Attribute names do not match", expected.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
collector.AddMessage("{0} - PASSED :: Attribute names match", expected.Name);
|
||||
}
|
||||
|
||||
if (actual.AttributeStructure != expected.AttributeStructure)
|
||||
{
|
||||
collector.AddError("{0} - FAILED :: Attribute value styles do not match", expected.AttributeStructure.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
collector.AddMessage("{0} - PASSED :: Attribute value style match", expected.AttributeStructure);
|
||||
}
|
||||
|
||||
if (actual.AttributeStructure != AttributeStructure.Minimized)
|
||||
{
|
||||
EvaluateSyntaxTreeNode(collector, actual.Value, expected.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void EvaluateSyntaxTreeNode(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
|
||||
{
|
||||
if (actual == null)
|
||||
|
|
@ -741,6 +628,35 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
}
|
||||
}
|
||||
|
||||
private static void EvaluateTagHelperAttribute(
|
||||
ErrorCollector collector,
|
||||
TagHelperAttributeNode actual,
|
||||
TagHelperAttributeNode expected)
|
||||
{
|
||||
if (actual.Name != expected.Name)
|
||||
{
|
||||
collector.AddError("{0} - FAILED :: Attribute names do not match", expected.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
collector.AddMessage("{0} - PASSED :: Attribute names match", expected.Name);
|
||||
}
|
||||
|
||||
if (actual.AttributeStructure != expected.AttributeStructure)
|
||||
{
|
||||
collector.AddError("{0} - FAILED :: Attribute value styles do not match", expected.AttributeStructure.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
collector.AddMessage("{0} - PASSED :: Attribute value style match", expected.AttributeStructure);
|
||||
}
|
||||
|
||||
if (actual.AttributeStructure != AttributeStructure.Minimized)
|
||||
{
|
||||
EvaluateSyntaxTreeNode(collector, actual.Value, expected.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddPassedMessage(ErrorCollector collector, SyntaxTreeNode expected)
|
||||
{
|
||||
collector.AddMessage("{0} - PASSED", expected);
|
||||
|
|
@ -801,35 +717,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Trace.WriteLine(string.Format(format, args));
|
||||
}
|
||||
|
||||
internal virtual Block CreateSimpleBlockAndSpan(string spanContent, BlockKindInternal blockKind, SpanKindInternal spanType, AcceptedCharactersInternal acceptedCharacters = AcceptedCharactersInternal.Any)
|
||||
{
|
||||
var span = Factory.Span(spanType, spanContent, spanType == SpanKindInternal.Markup).Accepts(acceptedCharacters);
|
||||
var b = new BlockBuilder()
|
||||
{
|
||||
Type = blockKind
|
||||
};
|
||||
return ConfigureAndAddSpanToBlock(b, span);
|
||||
}
|
||||
|
||||
internal virtual Block ConfigureAndAddSpanToBlock(BlockBuilder block, SpanConstructor span)
|
||||
{
|
||||
switch (block.Type)
|
||||
{
|
||||
case BlockKindInternal.Markup:
|
||||
span.With(new MarkupChunkGenerator());
|
||||
break;
|
||||
case BlockKindInternal.Statement:
|
||||
span.With(new StatementChunkGenerator());
|
||||
break;
|
||||
case BlockKindInternal.Expression:
|
||||
block.ChunkGenerator = new ExpressionChunkGenerator();
|
||||
span.With(new ExpressionChunkGenerator());
|
||||
break;
|
||||
}
|
||||
block.Children.Add(span);
|
||||
return block.Build();
|
||||
}
|
||||
|
||||
private static RazorParserOptions CreateParserOptions(
|
||||
RazorLanguageVersion version,
|
||||
IEnumerable<DirectiveDescriptor> directives,
|
||||
|
|
@ -841,46 +728,5 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
parseLeadingDirectives: false,
|
||||
version: version);
|
||||
}
|
||||
|
||||
private class IgnoreOutputBlock : Block
|
||||
{
|
||||
public IgnoreOutputBlock() : base(BlockKindInternal.Template, new SyntaxTreeNode[0], null) { }
|
||||
}
|
||||
|
||||
// Corrects the parents and previous/next information for spans
|
||||
internal class SpancestryCorrector : ParserVisitor
|
||||
{
|
||||
private SpancestryCorrector()
|
||||
{
|
||||
}
|
||||
|
||||
protected Block CurrentBlock { get; set; }
|
||||
|
||||
protected Span LastSpan { get; set; }
|
||||
|
||||
public static void Correct(Block block)
|
||||
{
|
||||
new SpancestryCorrector().VisitBlock(block);
|
||||
}
|
||||
|
||||
public override void VisitBlock(Block block)
|
||||
{
|
||||
CurrentBlock = block;
|
||||
base.VisitBlock(block);
|
||||
}
|
||||
|
||||
public override void VisitSpan(Span span)
|
||||
{
|
||||
span.Parent = CurrentBlock;
|
||||
|
||||
span.Previous = LastSpan;
|
||||
if (LastSpan != null)
|
||||
{
|
||||
LastSpan.Next = span;
|
||||
}
|
||||
|
||||
LastSpan = span;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Write(tagHelperBlock.TagName);
|
||||
|
||||
// Write descriptors
|
||||
foreach (var descriptor in tagHelperBlock.Binding.Descriptors)
|
||||
foreach (var descriptor in tagHelperBlock.Binding?.Descriptors ?? Array.Empty<TagHelperDescriptor>())
|
||||
{
|
||||
WriteSeparator();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue