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 class CSharpAutoCompleteTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpAutoCompleteTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void FunctionsDirectiveAutoCompleteAtEOF()
|
public void FunctionsDirectiveAutoCompleteAtEOF()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpBlockTest : CsHtmlCodeParserTestBase
|
public class CSharpBlockTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpBlockTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseBlock_NestedCodeBlockWithCSharpAt()
|
public void ParseBlock_NestedCodeBlockWithCSharpAt()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpDirectivesTest : CsHtmlCodeParserTestBase
|
public class CSharpDirectivesTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpDirectivesTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DirectiveDescriptor_FileScopedMultipleOccurring_CanHaveDuplicates()
|
public void DirectiveDescriptor_FileScopedMultipleOccurring_CanHaveDuplicates()
|
||||||
{
|
{
|
||||||
|
|
@ -921,13 +916,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
var result = ParseCodeBlock(RazorLanguageVersion.Latest, document, descriptors, designTime: false);
|
var result = ParseCodeBlock(RazorLanguageVersion.Latest, document, descriptors, designTime: false);
|
||||||
|
|
||||||
if (UseBaselineTests && !IsTheory)
|
BaselineTest(result);
|
||||||
{
|
|
||||||
BaselineTest(result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EvaluateResults(result, expected, expectedErrors);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpErrorTest : CsHtmlCodeParserTestBase
|
public class CSharpErrorTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpErrorTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseBlockHandlesQuotesAfterTransition()
|
public void ParseBlockHandlesQuotesAfterTransition()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpExplicitExpressionTest : CsHtmlCodeParserTestBase
|
public class CSharpExplicitExpressionTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpExplicitExpressionTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseBlockShouldOutputZeroLengthCodeSpanIfExplicitExpressionIsEmpty()
|
public void ParseBlockShouldOutputZeroLengthCodeSpanIfExplicitExpressionIsEmpty()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpImplicitExpressionTest : CsHtmlCodeParserTestBase
|
public class CSharpImplicitExpressionTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpImplicitExpressionTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseBlockMethodParsesNullConditionalOperatorImplicitExpression_Bracket1()
|
public void ParseBlockMethodParsesNullConditionalOperatorImplicitExpression_Bracket1()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpNestedStatementsTest : CsHtmlCodeParserTestBase
|
public class CSharpNestedStatementsTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpNestedStatementsTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NestedSimpleStatement()
|
public void NestedSimpleStatement()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpRazorCommentsTest : CsHtmlMarkupParserTestBase
|
public class CSharpRazorCommentsTest : CsHtmlMarkupParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpRazorCommentsTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void UnterminatedRazorComment()
|
public void UnterminatedRazorComment()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpReservedWordsTest : CsHtmlCodeParserTestBase
|
public class CSharpReservedWordsTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpReservedWordsTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ReservedWord()
|
public void ReservedWord()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpSectionTest : CsHtmlMarkupParserTestBase
|
public class CSharpSectionTest : CsHtmlMarkupParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpSectionTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseSectionBlockCapturesNewlineImmediatelyFollowing()
|
public void ParseSectionBlockCapturesNewlineImmediatelyFollowing()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpSpecialBlockTest : CsHtmlCodeParserTestBase
|
public class CSharpSpecialBlockTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpSpecialBlockTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NamespaceImportInsideCodeBlockCausesError()
|
public void NamespaceImportInsideCodeBlockCausesError()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
|
|
||||||
public class CSharpStatementTest : CsHtmlCodeParserTestBase
|
public class CSharpStatementTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpStatementTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ForStatement()
|
public void ForStatement()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpTemplateTest : CsHtmlCodeParserTestBase
|
public class CSharpTemplateTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpTemplateTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseBlockHandlesSingleLineTemplate()
|
public void ParseBlockHandlesSingleLineTemplate()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpToMarkupSwitchTest : CsHtmlCodeParserTestBase
|
public class CSharpToMarkupSwitchTest : CsHtmlCodeParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpToMarkupSwitchTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SingleAngleBracketDoesNotCauseSwitchIfOuterBlockIsTerminated()
|
public void SingleAngleBracketDoesNotCauseSwitchIfOuterBlockIsTerminated()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
private const string TestExtraKeyword = "model";
|
private const string TestExtraKeyword = "model";
|
||||||
|
|
||||||
public CSharpVerbatimBlockTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void VerbatimBlock()
|
public void VerbatimBlock()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class CSharpWhitespaceHandlingTest : CsHtmlMarkupParserTestBase
|
public class CSharpWhitespaceHandlingTest : CsHtmlMarkupParserTestBase
|
||||||
{
|
{
|
||||||
public CSharpWhitespaceHandlingTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void StatementBlockDoesNotAcceptTrailingNewlineIfNewlinesAreSignificantToAncestor()
|
public void StatementBlockDoesNotAcceptTrailingNewlineIfNewlinesAreSignificantToAncestor()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -58,12 +58,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
SingleSpanBlockTest(document, document, blockKind, spanType, acceptedCharacters, expectedError);
|
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)
|
internal void ImplicitExpressionTest(string input, string expected, AcceptedCharactersInternal acceptedCharacters, params RazorDiagnostic[] errors)
|
||||||
{
|
{
|
||||||
ParseBlockTest(SyntaxConstants.TransitionString + input);
|
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 class HtmlAttributeTest : CsHtmlMarkupParserTestBase
|
||||||
{
|
{
|
||||||
public HtmlAttributeTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SymbolBoundAttributes_BeforeEqualWhitespace1()
|
public void SymbolBoundAttributes_BeforeEqualWhitespace1()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class HtmlBlockTest : CsHtmlMarkupParserTestBase
|
public class HtmlBlockTest : CsHtmlMarkupParserTestBase
|
||||||
{
|
{
|
||||||
public HtmlBlockTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseBlockHandlesUnbalancedTripleDashHTMLComments()
|
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));
|
private static readonly TestFile Nested1000 = TestFile.Create("TestFiles/nested-1000.html", typeof(HtmlDocumentTest));
|
||||||
|
|
||||||
public HtmlDocumentTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseDocument_NestedCodeBlockWithMarkupSetsDotAsMarkup()
|
public void ParseDocument_NestedCodeBlockWithMarkupSetsDotAsMarkup()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class HtmlErrorTest : CsHtmlMarkupParserTestBase
|
public class HtmlErrorTest : CsHtmlMarkupParserTestBase
|
||||||
{
|
{
|
||||||
public HtmlErrorTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseBlockAllowsInvalidTagNamesAsLongAsParserCanIdentifyEndTag()
|
public void ParseBlockAllowsInvalidTagNamesAsLongAsParserCanIdentifyEndTag()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
"wbr",
|
"wbr",
|
||||||
};
|
};
|
||||||
|
|
||||||
public HtmlTagsTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void EmptyTagNestsLikeNormalTag()
|
public void EmptyTagNestsLikeNormalTag()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class HtmlToCodeSwitchTest : CsHtmlMarkupParserTestBase
|
public class HtmlToCodeSwitchTest : CsHtmlMarkupParserTestBase
|
||||||
{
|
{
|
||||||
public HtmlToCodeSwitchTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseBlockSwitchesWhenCharacterBeforeSwapIsNonAlphanumeric()
|
public void ParseBlockSwitchesWhenCharacterBeforeSwapIsNonAlphanumeric()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,5 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
return ParseHtmlBlock(version, document, directives, designTime);
|
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.
|
// 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.
|
// 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 System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -26,7 +25,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
var factory = new SpanFactory();
|
var factory = new SpanFactory();
|
||||||
var parser = new RazorParser();
|
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")),
|
ParserTestBase.EvaluateResults(parser.Parse(TestRazorSourceDocument.Create("foo @bar baz")),
|
||||||
new MarkupBlock(
|
new MarkupBlock(
|
||||||
factory.Markup("foo "),
|
factory.Markup("foo "),
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class TagHelperBlockRewriterTest : TagHelperRewritingTestBase
|
public class TagHelperBlockRewriterTest : TagHelperRewritingTestBase
|
||||||
{
|
{
|
||||||
public TagHelperBlockRewriterTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TagHelperDescriptor[] SymbolBoundAttributes_Descriptors = new[]
|
public static TagHelperDescriptor[] SymbolBoundAttributes_Descriptors = new[]
|
||||||
{
|
{
|
||||||
TagHelperDescriptorBuilder.Create("CatchAllTagHelper", "SomeAssembly")
|
TagHelperDescriptorBuilder.Create("CatchAllTagHelper", "SomeAssembly")
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class TagHelperParseTreeRewriterTest : TagHelperRewritingTestBase
|
public class TagHelperParseTreeRewriterTest : TagHelperRewritingTestBase
|
||||||
{
|
{
|
||||||
public TagHelperParseTreeRewriterTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TheoryData GetAttributeNameValuePairsData
|
public static TheoryData GetAttributeNameValuePairsData
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
||||||
|
|
@ -83,14 +83,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.OrderBy(error => error.Span.AbsoluteIndex)
|
.OrderBy(error => error.Span.AbsoluteIndex)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
if (UseBaselineTests && !IsTheory)
|
BaselineTest(actualTree, verifySyntaxTree: false, actualErrors.ToArray());
|
||||||
{
|
|
||||||
BaselineTest(actualTree, verifySyntaxTree: false, actualErrors.ToArray());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EvaluateRazorErrors(actualErrors, expectedErrors.ToList());
|
|
||||||
EvaluateParseTree(actualTree, expectedOutput);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
public class WhiteSpaceRewriterTest : CsHtmlMarkupParserTestBase
|
public class WhiteSpaceRewriterTest : CsHtmlMarkupParserTestBase
|
||||||
{
|
{
|
||||||
public WhiteSpaceRewriterTest()
|
|
||||||
{
|
|
||||||
UseBaselineTests = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block()
|
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>();
|
private static readonly AsyncLocal<bool> _isTheory = new AsyncLocal<bool>();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal static Block IgnoreOutput = new IgnoreOutputBlock();
|
|
||||||
|
|
||||||
internal ParserTestBase()
|
internal ParserTestBase()
|
||||||
{
|
{
|
||||||
Factory = CreateSpanFactory();
|
Factory = CreateSpanFactory();
|
||||||
|
|
@ -55,8 +53,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
|
|
||||||
protected string TestProjectRoot { get; }
|
protected string TestProjectRoot { get; }
|
||||||
|
|
||||||
protected bool UseBaselineTests { get; set; }
|
|
||||||
|
|
||||||
// Used by the test framework to set the 'base' name for test files.
|
// Used by the test framework to set the 'base' name for test files.
|
||||||
public static string FileName
|
public static string FileName
|
||||||
{
|
{
|
||||||
|
|
@ -107,6 +103,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
throw new InvalidOperationException(message);
|
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 baselineFileName = Path.ChangeExtension(FileName, ".syntaxtree.txt");
|
||||||
var baselineDiagnosticsFileName = Path.ChangeExtension(FileName, ".diagnostics.txt");
|
var baselineDiagnosticsFileName = Path.ChangeExtension(FileName, ".diagnostics.txt");
|
||||||
|
|
||||||
|
|
@ -218,7 +220,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
directives = directives ?? Array.Empty<DirectiveDescriptor>();
|
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 options = CreateParserOptions(version, directives, designTime);
|
||||||
var context = new ParserContext(source, options);
|
var context = new ParserContext(source, options);
|
||||||
|
|
@ -249,7 +251,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
directives = directives ?? Array.Empty<DirectiveDescriptor>();
|
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 options = CreateParserOptions(version, directives, designTime);
|
||||||
var context = new ParserContext(source, options);
|
var context = new ParserContext(source, options);
|
||||||
|
|
||||||
|
|
@ -280,7 +282,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
directives = directives ?? Array.Empty<DirectiveDescriptor>();
|
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 options = CreateParserOptions(version, directives, designTime);
|
||||||
var context = new ParserContext(source, options);
|
var context = new ParserContext(source, options);
|
||||||
|
|
||||||
|
|
@ -384,27 +386,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
var result = ParseBlock(version, document, directives, designTime);
|
var result = ParseBlock(version, document, directives, designTime);
|
||||||
|
|
||||||
if (UseBaselineTests && !IsTheory)
|
BaselineTest(result);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual void SingleSpanBlockTest(string document)
|
internal virtual void SingleSpanBlockTest(string document)
|
||||||
|
|
@ -441,31 +423,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
var result = ParseBlock(document, designTime: false);
|
var result = ParseBlock(document, designTime: false);
|
||||||
|
|
||||||
if (UseBaselineTests && !IsTheory)
|
BaselineTest(result);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual void ParseDocumentTest(string document)
|
internal virtual void ParseDocumentTest(string document)
|
||||||
|
|
@ -512,49 +470,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
var result = ParseDocument(document, directives, designTime);
|
var result = ParseDocument(document, directives, designTime);
|
||||||
|
|
||||||
if (UseBaselineTests && !IsTheory)
|
BaselineTest(result);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void EvaluateResults(RazorSyntaxTree result, Block expectedRoot)
|
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)
|
private static void EvaluateSyntaxTreeNode(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
|
||||||
{
|
{
|
||||||
if (actual == null)
|
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)
|
private static void AddPassedMessage(ErrorCollector collector, SyntaxTreeNode expected)
|
||||||
{
|
{
|
||||||
collector.AddMessage("{0} - PASSED", expected);
|
collector.AddMessage("{0} - PASSED", expected);
|
||||||
|
|
@ -801,35 +717,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
Trace.WriteLine(string.Format(format, args));
|
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(
|
private static RazorParserOptions CreateParserOptions(
|
||||||
RazorLanguageVersion version,
|
RazorLanguageVersion version,
|
||||||
IEnumerable<DirectiveDescriptor> directives,
|
IEnumerable<DirectiveDescriptor> directives,
|
||||||
|
|
@ -841,46 +728,5 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
parseLeadingDirectives: false,
|
parseLeadingDirectives: false,
|
||||||
version: version);
|
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(tagHelperBlock.TagName);
|
||||||
|
|
||||||
// Write descriptors
|
// Write descriptors
|
||||||
foreach (var descriptor in tagHelperBlock.Binding.Descriptors)
|
foreach (var descriptor in tagHelperBlock.Binding?.Descriptors ?? Array.Empty<TagHelperDescriptor>())
|
||||||
{
|
{
|
||||||
WriteSeparator();
|
WriteSeparator();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue