From 8eef4a4bb38dbc86ccebc22c2004b94f524868f5 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Wed, 27 Jun 2018 15:37:38 -0700 Subject: [PATCH] Convert HtmlDocumentTest --- .../Legacy/HtmlDocumentTest.cs | 694 ++---------------- ...ndTagWithNoMatchingStartTag.syntaxtree.txt | 13 + ...dOutputsZeroLengthCodeSpan.diagnostics.txt | 1 + ...ndOutputsZeroLengthCodeSpan.syntaxtree.txt | 10 + ...dlesOddlySpacedHTMLElements.syntaxtree.txt | 42 ++ ...MarkupWithEmbeddedStatement.syntaxtree.txt | 29 + ...ewLineAtTheEndOfMarkupBlock.syntaxtree.txt | 21 + ...atimBlockIfNoNewlinePresent.syntaxtree.txt | 21 + ...LineAtTheEndOfVerbatimBlock.syntaxtree.txt | 19 + ...atimBlockIfFollowedByCSharp.syntaxtree.txt | 32 + ...LineAtTheEndOfVerbatimBlock.syntaxtree.txt | 20 + ...ReturnErrorOnMismatchedTags.syntaxtree.txt | 29 + ...deOnEmailAddressInAttribute.syntaxtree.txt | 27 + ...hToCodeOnEmailAddressInText.syntaxtree.txt | 3 + ...tSignAsMarkupIfAtEndOfFile.diagnostics.txt | 1 + ...AtSignAsMarkupIfAtEndOfFile.syntaxtree.txt | 11 + ...rstCharacterIsSwapCharacter.syntaxtree.txt | 10 + ...neBeforeMarkupInNestedBlock.syntaxtree.txt | 42 ++ ...wLineAndMarkupInNestedBlock.syntaxtree.txt | 37 + ...HandlesNewLineInNestedBlock.syntaxtree.txt | 33 + ...gnEncounteredAndEmitsOutput.syntaxtree.txt | 12 + ...esTagsInContentsOfScriptTag.syntaxtree.txt | 28 + ...sDollarOpenBraceCombination.syntaxtree.txt | 14 + ...pSpanIfContentIsEmptyString.syntaxtree.txt | 3 + ...sSingleWhitespaceMarkupSpan.syntaxtree.txt | 3 + ...fNoSwapCharacterEncountered.syntaxtree.txt | 5 + ...rbatimBlockIfFollowedByHtml.syntaxtree.txt | 42 ++ ...fFollowedByMarkupTransition.syntaxtree.txt | 42 ++ ...endersTextPseudoTagAsMarkup.syntaxtree.txt | 17 + ...ntIfNoCodeBlocksEncountered.syntaxtree.txt | 25 + ...sNotCreateDocumentLevelSpan.syntaxtree.txt | 37 + ...ckWithMarkupSetsDotAsMarkup.syntaxtree.txt | 55 ++ ...AttributeValue_DoesNotThrow.syntaxtree.txt | 28 + ...AttributeValue_DoesNotThrow.syntaxtree.txt | 28 + ...AttributeValue_DoesNotThrow.syntaxtree.txt | 32 + ...AttributeValue_DoesNotThrow.syntaxtree.txt | 26 + ...nsitionInEmail_DoesNotThrow.syntaxtree.txt | 39 + ...nsitionInRegex_DoesNotThrow.syntaxtree.txt | 72 ++ ...xpressionBlock_DoesNotThrow.syntaxtree.txt | 141 ++++ ...onsInAttributeValue_Throws.diagnostics.txt | 2 + ...ionsInAttributeValue_Throws.syntaxtree.txt | 31 + ...esTagsInContentsOfScriptTag.syntaxtree.txt | 52 ++ 42 files changed, 1215 insertions(+), 614 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentAcceptsEndTagWithNoMatchingStartTag.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentAcceptsSwapTokenAtEndOfFileAndOutputsZeroLengthCodeSpan.diagnostics.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentAcceptsSwapTokenAtEndOfFileAndOutputsZeroLengthCodeSpan.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentCorrectlyHandlesOddlySpacedHTMLElements.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentCorrectlyHandlesSingleLineOfMarkupWithEmbeddedStatement.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentDoesNotIgnoreNewLineAtTheEndOfMarkupBlock.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentDoesNotIgnoreWhitespaceAtTheEndOfVerbatimBlockIfNoNewlinePresent.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentDoesNotRenderExtraNewLineAtTheEndOfVerbatimBlock.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentDoesNotRenderExtraNewlineAtTheEndTextTagInVerbatimBlockIfFollowedByCSharp.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentDoesNotRenderExtraWhitespaceAndNewLineAtTheEndOfVerbatimBlock.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentDoesNotReturnErrorOnMismatchedTags.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentDoesNotSwitchToCodeOnEmailAddressInAttribute.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentDoesNotSwitchToCodeOnEmailAddressInText.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentEmitsAtSignAsMarkupIfAtEndOfFile.diagnostics.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentEmitsAtSignAsMarkupIfAtEndOfFile.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentEmitsCodeBlockIfFirstCharacterIsSwapCharacter.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentHandlesExtraNewLineBeforeMarkupInNestedBlock.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentHandlesNewLineAndMarkupInNestedBlock.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentHandlesNewLineInNestedBlock.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentHandsParsingOverToCodeParserWhenAtSignEncounteredAndEmitsOutput.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentIgnoresTagsInContentsOfScriptTag.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentNoLongerSupportsDollarOpenBraceCombination.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentOutputsEmptyBlockWithEmptyMarkupSpanIfContentIsEmptyString.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentOutputsWhitespaceOnlyContentAsSingleWhitespaceMarkupSpan.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentParsesWholeContentAsOneSpanIfNoSwapCharacterEncountered.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentRendersExtraNewlineAtTheEndTextTagInVerbatimBlockIfFollowedByHtml.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentRendersExtraNewlineAtTheEndTextTagInVerbatimBlockIfFollowedByMarkupTransition.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentRendersTextPseudoTagAsMarkup.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentReturnsOneMarkupSegmentIfNoCodeBlocksEncountered.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocumentWithinSectionDoesNotCreateDocumentLevelSpan.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_NestedCodeBlockWithMarkupSetsDotAsMarkup.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithDoubleTransitionAtBeginningOfAttributeValue_DoesNotThrow.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithDoubleTransitionAtEndOfAttributeValue_DoesNotThrow.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithDoubleTransitionBetweenAttributeValue_DoesNotThrow.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithDoubleTransitionInAttributeValue_DoesNotThrow.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithDoubleTransitionInEmail_DoesNotThrow.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithDoubleTransitionInRegex_DoesNotThrow.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithDoubleTransitionWithExpressionBlock_DoesNotThrow.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithUnexpectedTransitionsInAttributeValue_Throws.diagnostics.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseDocument_WithUnexpectedTransitionsInAttributeValue_Throws.syntaxtree.txt create mode 100644 test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/HtmlDocumentTest/ParseSectionIgnoresTagsInContentsOfScriptTag.syntaxtree.txt diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlDocumentTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlDocumentTest.cs index b7f5eeb87d..7929c9a14c 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlDocumentTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlDocumentTest.cs @@ -12,92 +12,45 @@ 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() { - ParseDocumentTest("@if (true) { @if(false) {
@something.
} }", - new MarkupBlock( - Factory.EmptyHtml(), - new StatementBlock( - Factory.CodeTransition(), - Factory.Code("if (true) { ").AsStatement(), - new StatementBlock( - Factory.CodeTransition(), - Factory.Code("if(false) {").AsStatement(), - new MarkupBlock( - Factory.Markup(" "), - BlockFactory.MarkupTagBlock("
", AcceptedCharactersInternal.None), - Factory.EmptyHtml(), - new ExpressionBlock( - Factory.CodeTransition(), - Factory.Code("something") - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false) - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), - Factory.Markup("."), - BlockFactory.MarkupTagBlock("
", AcceptedCharactersInternal.None), - Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None)), - Factory.Code("}").AsStatement()), - Factory.Code(" }").AsStatement()))); + ParseDocumentTest("@if (true) { @if(false) {
@something.
} }"); } [Fact] public void ParseDocumentOutputsEmptyBlockWithEmptyMarkupSpanIfContentIsEmptyString() { - ParseDocumentTest(string.Empty, new MarkupBlock(Factory.EmptyHtml())); + ParseDocumentTest(string.Empty); } [Fact] public void ParseDocumentOutputsWhitespaceOnlyContentAsSingleWhitespaceMarkupSpan() { - SingleSpanDocumentTest(" ", BlockKindInternal.Markup, SpanKindInternal.Markup); + ParseDocumentTest(" "); } [Fact] public void ParseDocumentAcceptsSwapTokenAtEndOfFileAndOutputsZeroLengthCodeSpan() { - ParseDocumentTest("@", - new MarkupBlock( - Factory.EmptyHtml(), - new ExpressionBlock( - Factory.CodeTransition(), - Factory.EmptyCSharp() - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), - Factory.EmptyHtml()), - RazorDiagnosticFactory.CreateParsing_UnexpectedEndOfFileAtStartOfCodeBlock( - new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1))); + ParseDocumentTest("@"); } [Fact] public void ParseDocumentCorrectlyHandlesOddlySpacedHTMLElements() { - ParseDocumentTest("

Foo

", - new MarkupBlock( - BlockFactory.MarkupTagBlock("
"), - new MarkupTagBlock( - Factory.Markup("(" class = '", 8, 0, 8), suffix: new LocationTagged("'", 21, 0, 21)), - Factory.Markup(" class = '").With(SpanChunkGenerator.Null), - Factory.Markup("bar").With(new LiteralAttributeChunkGenerator(prefix: new LocationTagged(string.Empty, 18, 0, 18), value: new LocationTagged("bar", 18, 0, 18))), - Factory.Markup("'").With(SpanChunkGenerator.Null)), - Factory.Markup(">")), - Factory.Markup(" Foo "), - BlockFactory.MarkupTagBlock("

"), - BlockFactory.MarkupTagBlock("
"))); + ParseDocumentTest("

Foo

"); } [Fact] public void ParseDocumentCorrectlyHandlesSingleLineOfMarkupWithEmbeddedStatement() { - ParseDocumentTest("
Foo @if(true) {} Bar
", - new MarkupBlock( - BlockFactory.MarkupTagBlock("
"), - Factory.Markup("Foo "), - new StatementBlock( - Factory.CodeTransition(), - Factory.Code("if(true) {}").AsStatement()), - Factory.Markup(" Bar"), - BlockFactory.MarkupTagBlock("
"))); + ParseDocumentTest("
Foo @if(true) {} Bar
"); } [Fact] @@ -106,367 +59,139 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy ParseDocumentTest("@section Foo {" + Environment.NewLine + " " + Environment.NewLine + "}", - new[] { SectionDirective.Directive, }, - new MarkupBlock( - Factory.EmptyHtml(), - new DirectiveBlock(new DirectiveChunkGenerator(SectionDirective.Directive), - Factory.CodeTransition(), - Factory.MetaCode("section").Accepts(AcceptedCharactersInternal.None), - Factory.Span(SpanKindInternal.Code, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.WhiteSpace), - Factory.Span(SpanKindInternal.Code, "Foo", CSharpSymbolType.Identifier).AsDirectiveToken(SectionDirective.Directive.Tokens[0]), - Factory.Span(SpanKindInternal.Markup, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.AllWhiteSpace), - Factory.MetaCode("{").AutoCompleteWith(null, atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None), - new MarkupBlock( - Factory.Markup(Environment.NewLine + " "), - BlockFactory.MarkupTagBlock(""), - BlockFactory.MarkupTagBlock(""), - Factory.Markup(Environment.NewLine)), - Factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)), - Factory.EmptyHtml())); + new[] { SectionDirective.Directive, }); } [Fact] public void ParseDocumentParsesWholeContentAsOneSpanIfNoSwapCharacterEncountered() { - SingleSpanDocumentTest("foo baz", BlockKindInternal.Markup, SpanKindInternal.Markup); + ParseDocumentTest("foo baz"); } [Fact] public void ParseDocumentHandsParsingOverToCodeParserWhenAtSignEncounteredAndEmitsOutput() { - ParseDocumentTest("foo @bar baz", - new MarkupBlock( - Factory.Markup("foo "), - new ExpressionBlock( - Factory.CodeTransition(), - Factory.Code("bar") - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), - Factory.Markup(" baz"))); + ParseDocumentTest("foo @bar baz"); } [Fact] public void ParseDocumentEmitsAtSignAsMarkupIfAtEndOfFile() { - ParseDocumentTest("foo @", - new MarkupBlock( - Factory.Markup("foo "), - new ExpressionBlock( - Factory.CodeTransition(), - Factory.EmptyCSharp() - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), - Factory.EmptyHtml()), - RazorDiagnosticFactory.CreateParsing_UnexpectedEndOfFileAtStartOfCodeBlock( - new SourceSpan(new SourceLocation(5, 0, 5), contentLength: 1))); + ParseDocumentTest("foo @"); } [Fact] public void ParseDocumentEmitsCodeBlockIfFirstCharacterIsSwapCharacter() { - ParseDocumentTest("@bar", - new MarkupBlock( - Factory.EmptyHtml(), - new ExpressionBlock( - Factory.CodeTransition(), - Factory.Code("bar") - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) - .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), - Factory.EmptyHtml())); + ParseDocumentTest("@bar"); } [Fact] public void ParseDocumentDoesNotSwitchToCodeOnEmailAddressInText() { - SingleSpanDocumentTest("anurse@microsoft.com", BlockKindInternal.Markup, SpanKindInternal.Markup); + ParseDocument("example@microsoft.com"); } [Fact] public void ParseDocumentDoesNotSwitchToCodeOnEmailAddressInAttribute() { - ParseDocumentTest("Email me", - new MarkupBlock( - new MarkupTagBlock( - Factory.Markup("(" href=\"", 2, 0, 2), new LocationTagged("\"", 36, 0, 36)), - Factory.Markup(" href=\"").With(SpanChunkGenerator.Null), - Factory.Markup("mailto:anurse@microsoft.com") - .With(new LiteralAttributeChunkGenerator(new LocationTagged(string.Empty, 9, 0, 9), new LocationTagged("mailto:anurse@microsoft.com", 9, 0, 9))), - Factory.Markup("\"").With(SpanChunkGenerator.Null)), - Factory.Markup(">")), - Factory.Markup("Email me"), - BlockFactory.MarkupTagBlock(""))); + ParseDocumentTest("Email me"); } [Fact] public void ParseDocumentDoesNotReturnErrorOnMismatchedTags() { - ParseDocumentTest("Foo

Baz", - new MarkupBlock( - Factory.Markup("Foo "), - BlockFactory.MarkupTagBlock("
"), - BlockFactory.MarkupTagBlock("

"), - BlockFactory.MarkupTagBlock("

"), - BlockFactory.MarkupTagBlock("

"), - Factory.Markup(" Baz"))); + ParseDocumentTest("Foo

Baz"); } [Fact] public void ParseDocumentReturnsOneMarkupSegmentIfNoCodeBlocksEncountered() { - ParseDocumentTest("Foo BazBarBar] - SpanEditHandler;Accepts:None - (14:0,14) - Symbols:2 + HtmlSymbolType.DoubleHyphen;[--]; + HtmlSymbolType.CloseAngle;[>]; + Markup span - Gen - [Bar] - SpanEditHandler;Accepts:Any - (17:0,17) - Symbols:1 + HtmlSymbolType.Text;[Bar]; + Markup span - Gen - [