Make @addtaghelper directive not be nested.
- Whenever we encounter an @addtaghelper directive we add it to the CodeTree at the top level (not nested in any chunk blocks). - Added a test to validate that @addtaghelper inside of a ChunkBlock doesn't add to the ChunkBlock's children. #195.
This commit is contained in:
parent
e5a21520e5
commit
f8020e8e85
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|||
AddChunk(new AddTagHelperChunk
|
||||
{
|
||||
LookupText = lookupText
|
||||
}, association);
|
||||
}, association, topLevel: true);
|
||||
}
|
||||
|
||||
public void AddLiteralChunk(string literal, SyntaxTreeNode association)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,36 @@ using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
|||
using Microsoft.AspNet.Razor.Test.Framework;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
|
||||
namespace Microsoft.AspNet.Razor
|
||||
{
|
||||
public class CodeTreeBuilderTest
|
||||
{
|
||||
[Fact]
|
||||
public void AddAddTagHelperChunk_AddsChunkToTopLevelCodeTree()
|
||||
{
|
||||
// Arrange
|
||||
var spanFactory = SpanFactory.CreateCsHtml();
|
||||
var builder = new CodeTreeBuilder();
|
||||
var block = new ExpressionBlock();
|
||||
var addTagHelperDirective = spanFactory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ");
|
||||
|
||||
// Act
|
||||
builder.StartChunkBlock<ExpressionBlockChunk>(block);
|
||||
builder.AddAddTagHelperChunk("some text", addTagHelperDirective);
|
||||
builder.EndChunkBlock();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, builder.CodeTree.Chunks.Count);
|
||||
|
||||
var chunkBlock = Assert.IsType<ExpressionBlockChunk>(builder.CodeTree.Chunks.First());
|
||||
Assert.Empty(chunkBlock.Children);
|
||||
|
||||
var addTagHelperChunk = Assert.IsType<AddTagHelperChunk>(builder.CodeTree.Chunks.Last());
|
||||
Assert.Equal(addTagHelperChunk.LookupText, "some text");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddLiteralChunk_AddsChunkToCodeTree()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue