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:
N. Taylor Mullen 2014-10-15 12:10:27 -07:00
parent e5a21520e5
commit f8020e8e85
2 changed files with 26 additions and 1 deletions

View File

@ -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)

View File

@ -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()
{