From 6f515bb7637fcf70b4a692a626c92e84e5ef208c Mon Sep 17 00:00:00 2001 From: Artak Mkrtchyan Date: Tue, 20 Feb 2018 22:20:48 -0800 Subject: [PATCH] Fixed all the tests to reflect HtmlComment block type support --- .../Legacy/HtmlDocumentTest.cs | 8 +++++++- .../Legacy/HtmlTagsTest.cs | 2 +- .../Legacy/HtmlToCodeSwitchTest.cs | 15 +++++++------- .../Legacy/TagHelperParseTreeRewriterTest.cs | 20 +++++++++---------- ...lCommentWithQuote_Double_DesignTime.ir.txt | 4 +++- ...HtmlCommentWithQuote_Double_Runtime.ir.txt | 4 +++- ...lCommentWithQuote_Single_DesignTime.ir.txt | 4 +++- ...HtmlCommentWithQuote_Single_Runtime.ir.txt | 4 +++- .../Language/Legacy/BlockFactory.cs | 16 +++++++-------- 9 files changed, 45 insertions(+), 32 deletions(-) diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlDocumentTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlDocumentTest.cs index 0f06fe578a..9f0e11218b 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlDocumentTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlDocumentTest.cs @@ -214,7 +214,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy [Fact] public void ParseDocumentReturnsOneMarkupSegmentIfNoCodeBlocksEncountered() { - SingleSpanDocumentTest("Foo BazBarBar Bar", new MarkupBlock( - Factory.Markup("").Accepts(AcceptedCharactersInternal.None), + BlockFactory.HtmlCommentBlock("Foo"), Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None))); } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlToCodeSwitchTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlToCodeSwitchTest.cs index 29c1dfb81a..928762fbc6 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlToCodeSwitchTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlToCodeSwitchTest.cs @@ -112,13 +112,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy new MarkupBlock( new MarkupTagBlock( Factory.Markup("").Accepts(AcceptedCharactersInternal.None)), - Factory.Markup("").Accepts(AcceptedCharactersInternal.None), + BlockFactory.HtmlCommentBlock(Factory, f => new SyntaxTreeNode[] { + f.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace), + new ExpressionBlock( + f.CodeTransition(), + f.Code("foo") + .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) + .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), + f.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace) }), new MarkupTagBlock( Factory.Markup("").Accepts(AcceptedCharactersInternal.None)))); } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs index ceca9e86f2..425b728716 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs @@ -1278,13 +1278,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy blockFactory.MarkupTagBlock(""), factory.Markup(literal), blockFactory.MarkupTagBlock(""), - blockFactory.HtmlCommentBlock( - factory.Markup(part1).Accepts(AcceptedCharactersInternal.WhiteSpace), + BlockFactory.HtmlCommentBlock(factory, f => new SyntaxTreeNode[] { + f.Markup(part1).Accepts(AcceptedCharactersInternal.WhiteSpace), new ExpressionBlock( - factory.CodeTransition(), - factory.Code(part2) + f.CodeTransition(), + f.Code(part2) .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) - .Accepts(AcceptedCharactersInternal.NonWhiteSpace))))); + .Accepts(AcceptedCharactersInternal.NonWhiteSpace)) }))); // Act & Assert EvaluateData( @@ -4104,14 +4104,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy new MarkupBlock( new MarkupTagBlock( factory.Markup("")), - blockFactory.HtmlCommentBlock( - factory.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace), + BlockFactory.HtmlCommentBlock(factory, f=> new SyntaxTreeNode[]{ + f.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace), new ExpressionBlock( - factory.CodeTransition(), - factory.Code("foo") + f.CodeTransition(), + f.Code("foo") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .Accepts(AcceptedCharactersInternal.NonWhiteSpace)), - factory.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace)), + factory.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace) }), new MarkupTagBlock( factory.Markup(""))) }; diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/HtmlCommentWithQuote_Double_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/HtmlCommentWithQuote_Double_DesignTime.ir.txt index 615f0fce97..4523eae7a3 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/HtmlCommentWithQuote_Double_DesignTime.ir.txt +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/HtmlCommentWithQuote_Double_DesignTime.ir.txt @@ -10,7 +10,9 @@ Document - IntermediateToken - - CSharp - #pragma warning restore 0414 MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync HtmlContent - (0:0,0 [45] HtmlCommentWithQuote_Double.cshtml) - IntermediateToken - (0:0,0 [10] HtmlCommentWithQuote_Double.cshtml) - Html - + IntermediateToken - (0:0,0 [4] HtmlCommentWithQuote_Double.cshtml) - Html - IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Double.cshtml) - Html - \n IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Double.cshtml) - Html - + IntermediateToken - (0:0,0 [4] HtmlCommentWithQuote_Double.cshtml) - Html - IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Double.cshtml) - Html - \n IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Double.cshtml) - Html - + IntermediateToken - (0:0,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Single.cshtml) - Html - \n IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - + IntermediateToken - (0:0,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Single.cshtml) - Html - \n IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - ").Accepts(AcceptedCharactersInternal.None) }); + return HtmlCommentBlock(_factory, f => new SyntaxTreeNode[] { f.Markup(content).Accepts(AcceptedCharactersInternal.WhiteSpace) }); } - public HtmlCommentBlock HtmlCommentBlock(params SyntaxTreeNode[] syntaxTreeNodes) + public static HtmlCommentBlock HtmlCommentBlock(SpanFactory factory, Func> nodesBuilder = null) { var nodes = new List(); - nodes.Add(_factory.Markup("").Accepts(AcceptedCharactersInternal.None)); + nodes.Add(factory.Markup("-->").Accepts(AcceptedCharactersInternal.None)); return new HtmlCommentBlock(nodes.ToArray()); }