Fix test to work with TH rewriters.
- Added understanding to the ParserTestBase for TagHelperBlock's - Added a helper class MarkupTagHelperBlock to make building test TagHelpers easier. - Fixed some existing tests that "new"d up the RazorParser and didn't obide by the new contract (to provide optimizers). #71
This commit is contained in:
parent
3cba84104d
commit
bb3ad0ede4
|
|
@ -2,8 +2,10 @@
|
||||||
// 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.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||||
|
using Microsoft.AspNet.Razor.Parser.TagHelpers;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Razor.Test.Framework
|
namespace Microsoft.AspNet.Razor.Test.Framework
|
||||||
{
|
{
|
||||||
|
|
@ -174,6 +176,33 @@ namespace Microsoft.AspNet.Razor.Test.Framework
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MarkupTagHelperBlock : TagHelperBlock
|
||||||
|
{
|
||||||
|
public MarkupTagHelperBlock(string tagName)
|
||||||
|
: this(tagName, new Dictionary<string, SyntaxTreeNode>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkupTagHelperBlock(string tagName,
|
||||||
|
IDictionary<string, SyntaxTreeNode> attributes)
|
||||||
|
: this(tagName, attributes, new SyntaxTreeNode[0])
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkupTagHelperBlock(string tagName,
|
||||||
|
params SyntaxTreeNode[] children)
|
||||||
|
: this(tagName, new Dictionary<string, SyntaxTreeNode>(), children)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkupTagHelperBlock(string tagName,
|
||||||
|
IDictionary<string, SyntaxTreeNode> attributes,
|
||||||
|
params SyntaxTreeNode[] children)
|
||||||
|
: base(new TagHelperBlockBuilder(tagName, attributes, children))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class SectionBlock : Block
|
public class SectionBlock : Block
|
||||||
{
|
{
|
||||||
private const BlockType ThisBlockType = BlockType.Section;
|
private const BlockType ThisBlockType = BlockType.Section;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ using System.Text;
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
using Microsoft.AspNet.Razor.Parser;
|
using Microsoft.AspNet.Razor.Parser;
|
||||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||||
|
using Microsoft.AspNet.Razor.Parser.TagHelpers;
|
||||||
using Microsoft.AspNet.Razor.Text;
|
using Microsoft.AspNet.Razor.Text;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -291,6 +292,22 @@ namespace Microsoft.AspNet.Razor.Test.Framework
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void EvaluateTagHelperAttribute(ErrorCollector collector,
|
||||||
|
KeyValuePair<string, SyntaxTreeNode> actual,
|
||||||
|
KeyValuePair<string, SyntaxTreeNode> expected)
|
||||||
|
{
|
||||||
|
if (actual.Key != expected.Key)
|
||||||
|
{
|
||||||
|
collector.AddError("{0} - FAILED :: Attribute names do not match", expected.Key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
collector.AddMessage("{0} - PASSED :: Attribute names match", expected.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
EvaluateSyntaxTreeNode(collector, actual.Value, expected.Value);
|
||||||
|
}
|
||||||
|
|
||||||
private static void EvaluateSpan(ErrorCollector collector, Span actual, Span expected)
|
private static void EvaluateSpan(ErrorCollector collector, Span actual, Span expected)
|
||||||
{
|
{
|
||||||
if (!Equals(expected, actual))
|
if (!Equals(expected, actual))
|
||||||
|
|
@ -311,11 +328,16 @@ namespace Microsoft.AspNet.Razor.Test.Framework
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (actual is TagHelperBlock)
|
||||||
|
{
|
||||||
|
EvaluateTagHelperBlock(collector, actual as TagHelperBlock, expected as TagHelperBlock);
|
||||||
|
}
|
||||||
|
|
||||||
AddPassedMessage(collector, expected);
|
AddPassedMessage(collector, expected);
|
||||||
using (collector.Indent())
|
using (collector.Indent())
|
||||||
{
|
{
|
||||||
IEnumerator<SyntaxTreeNode> expectedNodes = expected.Children.GetEnumerator();
|
var expectedNodes = expected.Children.GetEnumerator();
|
||||||
IEnumerator<SyntaxTreeNode> actualNodes = actual.Children.GetEnumerator();
|
var actualNodes = actual.Children.GetEnumerator();
|
||||||
while (expectedNodes.MoveNext())
|
while (expectedNodes.MoveNext())
|
||||||
{
|
{
|
||||||
if (!actualNodes.MoveNext())
|
if (!actualNodes.MoveNext())
|
||||||
|
|
@ -335,6 +357,35 @@ namespace Microsoft.AspNet.Razor.Test.Framework
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void EvaluateTagHelperBlock(ErrorCollector collector, TagHelperBlock actual, TagHelperBlock expected)
|
||||||
|
{
|
||||||
|
if (expected == null)
|
||||||
|
{
|
||||||
|
AddMismatchError(collector, actual, expected);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var expectedAttributes = expected.Attributes.GetEnumerator();
|
||||||
|
var actualAttributes = actual.Attributes.GetEnumerator();
|
||||||
|
|
||||||
|
while (expectedAttributes.MoveNext())
|
||||||
|
{
|
||||||
|
if (!actualAttributes.MoveNext())
|
||||||
|
{
|
||||||
|
collector.AddError("{0} - FAILED :: No more attributes on this node", expectedAttributes.Current);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EvaluateTagHelperAttribute(collector, actualAttributes.Current, expectedAttributes.Current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (actualAttributes.MoveNext())
|
||||||
|
{
|
||||||
|
collector.AddError("End of Attributes - FAILED :: Found Attribute: {0}", actualAttributes.Current.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -28,24 +28,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
|
||||||
Assert.Same(block, span.Parent);
|
Assert.Same(block, span.Parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ConstructorCopiesBasicValuesFromBlockBuilder()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
BlockBuilder builder = new BlockBuilder()
|
|
||||||
{
|
|
||||||
Name = "Foo",
|
|
||||||
Type = BlockType.Helper
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
|
||||||
Block actual = builder.Build();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal("Foo", actual.Name);
|
|
||||||
Assert.Equal(BlockType.Helper, actual.Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ConstructorTransfersInstanceOfCodeGeneratorFromBlockBuilder()
|
public void ConstructorTransfersInstanceOfCodeGeneratorFromBlockBuilder()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue