Link syntax tree Span nodes
This commit is contained in:
parent
e3d2b48b89
commit
f4e9ddad22
|
|
@ -1,4 +1,4 @@
|
||||||
// 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.
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
|
|
@ -88,6 +88,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
var rootBuilder = _blockStack.Pop();
|
var rootBuilder = _blockStack.Pop();
|
||||||
var root = rootBuilder.Build();
|
var root = rootBuilder.Build();
|
||||||
|
|
||||||
|
root.LinkNodes();
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// 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.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
|
|
@ -21,9 +22,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseMethodCallsParseDocumentOnMarkupParserAndReturnsResults()
|
public void ParseMethodCallsParseDocumentOnMarkupParserAndReturnsResults()
|
||||||
{
|
{
|
||||||
var factory = new SpanFactory();
|
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var factory = new SpanFactory();
|
||||||
var parser = new RazorParser();
|
var parser = new RazorParser();
|
||||||
|
|
||||||
// Act/Assert
|
// Act/Assert
|
||||||
|
|
@ -41,9 +41,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseMethodUsesProvidedParserListenerIfSpecified()
|
public void ParseMethodUsesProvidedParserListenerIfSpecified()
|
||||||
{
|
{
|
||||||
var factory = new SpanFactory();
|
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var factory = new SpanFactory();
|
||||||
var parser = new RazorParser();
|
var parser = new RazorParser();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -60,5 +59,28 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
|
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
|
||||||
factory.Markup(" baz")));
|
factory.Markup(" baz")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Parse_SyntaxTreeSpansAreLinked()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var factory = new SpanFactory();
|
||||||
|
var parser = new RazorParser();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var results = parser.Parse(TestRazorSourceDocument.Create("foo @bar baz"));
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var spans = results.Root.Flatten().ToArray();
|
||||||
|
for (var i = 0; i < spans.Length - 1; i++)
|
||||||
|
{
|
||||||
|
Assert.Same(spans[i + 1], spans[i].Next);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = spans.Length - 1; i > 0; i--)
|
||||||
|
{
|
||||||
|
Assert.Same(spans[i - 1], spans[i].Previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue