Fixed all the tests to reflect HtmlComment block type support

This commit is contained in:
Artak Mkrtchyan 2018-02-20 22:20:48 -08:00
parent e1fbea24f1
commit 6f515bb763
No known key found for this signature in database
GPG Key ID: 64D580ACBA8CA645
9 changed files with 45 additions and 32 deletions

View File

@ -214,7 +214,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
[Fact] [Fact]
public void ParseDocumentReturnsOneMarkupSegmentIfNoCodeBlocksEncountered() public void ParseDocumentReturnsOneMarkupSegmentIfNoCodeBlocksEncountered()
{ {
SingleSpanDocumentTest("Foo Baz<!--Foo-->Bar<!--F> Qux", BlockKindInternal.Markup, SpanKindInternal.Markup); ParseDocumentTest("Foo Baz<!--Foo-->Bar<!--F> Qux",
new MarkupBlock(
Factory.Markup("Foo Baz"),
BlockFactory.HtmlCommentBlock("Foo"),
Factory.Markup("Bar"),
new HtmlCommentBlock(Factory.Markup("<!--").Accepts(AcceptedCharactersInternal.None)),
Factory.Markup("F> Qux").Accepts(AcceptedCharactersInternal.WhiteSpace)));
} }
[Fact] [Fact]

View File

@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{ {
ParseBlockTest("<!--Foo--> Bar", ParseBlockTest("<!--Foo--> Bar",
new MarkupBlock( new MarkupBlock(
Factory.Markup("<!--Foo-->").Accepts(AcceptedCharactersInternal.None), BlockFactory.HtmlCommentBlock("Foo"),
Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None))); Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None)));
} }

View File

@ -112,13 +112,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
new MarkupBlock( new MarkupBlock(
new MarkupTagBlock( new MarkupTagBlock(
Factory.Markup("<foo>").Accepts(AcceptedCharactersInternal.None)), Factory.Markup("<foo>").Accepts(AcceptedCharactersInternal.None)),
Factory.Markup("<!-- "), BlockFactory.HtmlCommentBlock(Factory, f => new SyntaxTreeNode[] {
new ExpressionBlock( f.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace),
Factory.CodeTransition(), new ExpressionBlock(
Factory.Code("foo") f.CodeTransition(),
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords) f.Code("foo")
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)), .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
Factory.Markup(" -->").Accepts(AcceptedCharactersInternal.None), .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
f.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace) }),
new MarkupTagBlock( new MarkupTagBlock(
Factory.Markup("</foo>").Accepts(AcceptedCharactersInternal.None)))); Factory.Markup("</foo>").Accepts(AcceptedCharactersInternal.None))));
} }

View File

@ -1278,13 +1278,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
blockFactory.MarkupTagBlock("<b>"), blockFactory.MarkupTagBlock("<b>"),
factory.Markup(literal), factory.Markup(literal),
blockFactory.MarkupTagBlock("</b>"), blockFactory.MarkupTagBlock("</b>"),
blockFactory.HtmlCommentBlock( BlockFactory.HtmlCommentBlock(factory, f => new SyntaxTreeNode[] {
factory.Markup(part1).Accepts(AcceptedCharactersInternal.WhiteSpace), f.Markup(part1).Accepts(AcceptedCharactersInternal.WhiteSpace),
new ExpressionBlock( new ExpressionBlock(
factory.CodeTransition(), f.CodeTransition(),
factory.Code(part2) f.Code(part2)
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
.Accepts(AcceptedCharactersInternal.NonWhiteSpace))))); .Accepts(AcceptedCharactersInternal.NonWhiteSpace)) })));
// Act & Assert // Act & Assert
EvaluateData( EvaluateData(
@ -4104,14 +4104,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
new MarkupBlock( new MarkupBlock(
new MarkupTagBlock( new MarkupTagBlock(
factory.Markup("<foo>")), factory.Markup("<foo>")),
blockFactory.HtmlCommentBlock( BlockFactory.HtmlCommentBlock(factory, f=> new SyntaxTreeNode[]{
factory.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace), f.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace),
new ExpressionBlock( new ExpressionBlock(
factory.CodeTransition(), f.CodeTransition(),
factory.Code("foo") f.Code("foo")
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)), .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
factory.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace)), factory.Markup(" ").Accepts(AcceptedCharactersInternal.WhiteSpace) }),
new MarkupTagBlock( new MarkupTagBlock(
factory.Markup("</foo>"))) factory.Markup("</foo>")))
}; };

View File

@ -10,7 +10,9 @@ Document -
IntermediateToken - - CSharp - #pragma warning restore 0414 IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [45] HtmlCommentWithQuote_Double.cshtml) 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 - (4:0,4 [3] HtmlCommentWithQuote_Double.cshtml) - Html - "
IntermediateToken - (7:0,7 [3] HtmlCommentWithQuote_Double.cshtml) - Html - -->
IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Double.cshtml) - Html - \n IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Double.cshtml) - Html - \n
IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Double.cshtml) - Html - <img IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Double.cshtml) - Html - <img
IntermediateToken - (16:1,4 [26] HtmlCommentWithQuote_Double.cshtml) - Html - src="~/images/submit.png" IntermediateToken - (16:1,4 [26] HtmlCommentWithQuote_Double.cshtml) - Html - src="~/images/submit.png"

View File

@ -5,7 +5,9 @@ Document -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_HtmlCommentWithQuote_Double_Runtime - - ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_HtmlCommentWithQuote_Double_Runtime - -
MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [45] HtmlCommentWithQuote_Double.cshtml) 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 - (4:0,4 [3] HtmlCommentWithQuote_Double.cshtml) - Html - "
IntermediateToken - (7:0,7 [3] HtmlCommentWithQuote_Double.cshtml) - Html - -->
IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Double.cshtml) - Html - \n IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Double.cshtml) - Html - \n
IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Double.cshtml) - Html - <img IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Double.cshtml) - Html - <img
IntermediateToken - (16:1,4 [26] HtmlCommentWithQuote_Double.cshtml) - Html - src="~/images/submit.png" IntermediateToken - (16:1,4 [26] HtmlCommentWithQuote_Double.cshtml) - Html - src="~/images/submit.png"

View File

@ -10,7 +10,9 @@ Document -
IntermediateToken - - CSharp - #pragma warning restore 0414 IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [45] HtmlCommentWithQuote_Single.cshtml) HtmlContent - (0:0,0 [45] HtmlCommentWithQuote_Single.cshtml)
IntermediateToken - (0:0,0 [10] HtmlCommentWithQuote_Single.cshtml) - Html - <!-- ' --> IntermediateToken - (0:0,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - <!--
IntermediateToken - (4:0,4 [3] HtmlCommentWithQuote_Single.cshtml) - Html - '
IntermediateToken - (7:0,7 [3] HtmlCommentWithQuote_Single.cshtml) - Html - -->
IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Single.cshtml) - Html - \n IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Single.cshtml) - Html - \n
IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - <img IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - <img
IntermediateToken - (16:1,4 [26] HtmlCommentWithQuote_Single.cshtml) - Html - src="~/images/submit.png" IntermediateToken - (16:1,4 [26] HtmlCommentWithQuote_Single.cshtml) - Html - src="~/images/submit.png"

View File

@ -5,7 +5,9 @@ Document -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_HtmlCommentWithQuote_Single_Runtime - - ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_HtmlCommentWithQuote_Single_Runtime - -
MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync MethodDeclaration - - public async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [45] HtmlCommentWithQuote_Single.cshtml) HtmlContent - (0:0,0 [45] HtmlCommentWithQuote_Single.cshtml)
IntermediateToken - (0:0,0 [10] HtmlCommentWithQuote_Single.cshtml) - Html - <!-- ' --> IntermediateToken - (0:0,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - <!--
IntermediateToken - (4:0,4 [3] HtmlCommentWithQuote_Single.cshtml) - Html - '
IntermediateToken - (7:0,7 [3] HtmlCommentWithQuote_Single.cshtml) - Html - -->
IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Single.cshtml) - Html - \n IntermediateToken - (10:0,10 [2] HtmlCommentWithQuote_Single.cshtml) - Html - \n
IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - <img IntermediateToken - (12:1,0 [4] HtmlCommentWithQuote_Single.cshtml) - Html - <img
IntermediateToken - (16:1,4 [26] HtmlCommentWithQuote_Single.cshtml) - Html - src="~/images/submit.png" IntermediateToken - (16:1,4 [26] HtmlCommentWithQuote_Single.cshtml) - Html - src="~/images/submit.png"

View File

@ -1,6 +1,7 @@
// 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;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Legacy namespace Microsoft.AspNetCore.Razor.Language.Legacy
@ -57,21 +58,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public HtmlCommentBlock HtmlCommentBlock(string content) public HtmlCommentBlock HtmlCommentBlock(string content)
{ {
return new HtmlCommentBlock(new SyntaxTreeNode[] { return HtmlCommentBlock(_factory, f => new SyntaxTreeNode[] { f.Markup(content).Accepts(AcceptedCharactersInternal.WhiteSpace) });
_factory.Markup("<!--").Accepts(AcceptedCharactersInternal.None),
_factory.Markup(content).Accepts(AcceptedCharactersInternal.WhiteSpace),
_factory.Markup("-->").Accepts(AcceptedCharactersInternal.None) });
} }
public HtmlCommentBlock HtmlCommentBlock(params SyntaxTreeNode[] syntaxTreeNodes) public static HtmlCommentBlock HtmlCommentBlock(SpanFactory factory, Func<SpanFactory, IEnumerable<SyntaxTreeNode>> nodesBuilder = null)
{ {
var nodes = new List<SyntaxTreeNode>(); var nodes = new List<SyntaxTreeNode>();
nodes.Add(_factory.Markup("<!--").Accepts(AcceptedCharactersInternal.None)); nodes.Add(factory.Markup("<!--").Accepts(AcceptedCharactersInternal.None));
if (syntaxTreeNodes != null) if (nodesBuilder != null)
{ {
nodes.AddRange(syntaxTreeNodes); nodes.AddRange(nodesBuilder(factory));
} }
nodes.Add(_factory.Markup("-->").Accepts(AcceptedCharactersInternal.None)); nodes.Add(factory.Markup("-->").Accepts(AcceptedCharactersInternal.None));
return new HtmlCommentBlock(nodes.ToArray()); return new HtmlCommentBlock(nodes.ToArray());
} }