Plumb `ParserErrorSink` through to `CodeBuilderContext`
- precursor for #129 - remove unused `GeneratorResults` ctor to avoid duplicating `ParserResults` code nit: make a few `ParserResults` properties immutable - also change `ParserErrors` type to `IEnumerable<RazorError>`
This commit is contained in:
parent
8c47f6a67e
commit
26afdbd889
|
|
@ -1,6 +1,8 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. 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 Microsoft.AspNet.Razor.Parser;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Razor.Generator
|
namespace Microsoft.AspNet.Razor.Generator
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -12,9 +14,14 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
/// Instantiates a new instance of the <see cref="CodeBuilderContext"/> object.
|
/// Instantiates a new instance of the <see cref="CodeBuilderContext"/> object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="generatorContext">A <see cref="CodeGeneratorContext"/> to copy information from.</param>
|
/// <param name="generatorContext">A <see cref="CodeGeneratorContext"/> to copy information from.</param>
|
||||||
public CodeBuilderContext(CodeGeneratorContext generatorContext)
|
/// <param name="errorSink">
|
||||||
|
/// The <see cref="ParserErrorSink"/> used to collect <see cref="Parser.SyntaxTree.RazorError"/>s encountered
|
||||||
|
/// when parsing the current Razor document.
|
||||||
|
/// </param>
|
||||||
|
public CodeBuilderContext(CodeGeneratorContext generatorContext, ParserErrorSink errorSink)
|
||||||
: base(generatorContext)
|
: base(generatorContext)
|
||||||
{
|
{
|
||||||
|
ErrorSink = errorSink;
|
||||||
ExpressionRenderingMode = ExpressionRenderingMode.WriteToOutput;
|
ExpressionRenderingMode = ExpressionRenderingMode.WriteToOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,9 +30,11 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
string className,
|
string className,
|
||||||
string rootNamespace,
|
string rootNamespace,
|
||||||
string sourceFile,
|
string sourceFile,
|
||||||
bool shouldGenerateLinePragmas)
|
bool shouldGenerateLinePragmas,
|
||||||
|
ParserErrorSink errorSink)
|
||||||
: base(host, className, rootNamespace, sourceFile, shouldGenerateLinePragmas)
|
: base(host, className, rootNamespace, sourceFile, shouldGenerateLinePragmas)
|
||||||
{
|
{
|
||||||
|
ErrorSink = errorSink;
|
||||||
ExpressionRenderingMode = ExpressionRenderingMode.WriteToOutput;
|
ExpressionRenderingMode = ExpressionRenderingMode.WriteToOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,5 +65,10 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
/// <see cref="CodeGeneratorContext.SourceFile"/>.
|
/// <see cref="CodeGeneratorContext.SourceFile"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Checksum { get; set; }
|
public string Checksum { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to aggregate <see cref="Parser.SyntaxTree.RazorError"/>s.
|
||||||
|
/// </summary>
|
||||||
|
public ParserErrorSink ErrorSink { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||||
|
using Microsoft.AspNet.Razor.Parser;
|
||||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||||
using Microsoft.AspNet.Razor.TagHelpers;
|
using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
|
|
||||||
|
|
@ -24,7 +25,7 @@ namespace Microsoft.AspNet.Razor
|
||||||
[NotNull] CodeTree codeTree)
|
[NotNull] CodeTree codeTree)
|
||||||
: this(parserResults.Document,
|
: this(parserResults.Document,
|
||||||
parserResults.TagHelperDescriptors,
|
parserResults.TagHelperDescriptors,
|
||||||
parserResults.ParserErrors,
|
parserResults.ErrorSink,
|
||||||
codeBuilderResult,
|
codeBuilderResult,
|
||||||
codeTree)
|
codeTree)
|
||||||
{
|
{
|
||||||
|
|
@ -34,35 +35,21 @@ namespace Microsoft.AspNet.Razor
|
||||||
/// Instantiates a new <see cref="GeneratorResults"/> instance.
|
/// Instantiates a new <see cref="GeneratorResults"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="document">The <see cref="Block"/> for the syntax tree.</param>
|
/// <param name="document">The <see cref="Block"/> for the syntax tree.</param>
|
||||||
/// <param name="tagHelperDescriptors"><see cref="TagHelperDescriptor"/>s for the document.</param>
|
/// <param name="tagHelperDescriptors">
|
||||||
/// <param name="parserErrors"><see cref="RazorError"/>s encountered when parsing the document.</param>
|
/// The <see cref="TagHelperDescriptor"/>s that apply to the current Razor document.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="errorSink">
|
||||||
|
/// The <see cref="ParserErrorSink"/> used to collect <see cref="RazorError"/>s encountered when parsing the
|
||||||
|
/// current Razor document.
|
||||||
|
/// </param>
|
||||||
/// <param name="codeBuilderResult">The results of generating code for the document.</param>
|
/// <param name="codeBuilderResult">The results of generating code for the document.</param>
|
||||||
/// <param name="codeTree">A <see cref="CodeTree"/> for the document.</param>
|
/// <param name="codeTree">A <see cref="CodeTree"/> for the document.</param>
|
||||||
public GeneratorResults([NotNull] Block document,
|
public GeneratorResults([NotNull] Block document,
|
||||||
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
|
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
|
||||||
[NotNull] IList<RazorError> parserErrors,
|
[NotNull] ParserErrorSink errorSink,
|
||||||
[NotNull] CodeBuilderResult codeBuilderResult,
|
[NotNull] CodeBuilderResult codeBuilderResult,
|
||||||
[NotNull] CodeTree codeTree)
|
[NotNull] CodeTree codeTree)
|
||||||
: this(parserErrors.Count == 0, document, tagHelperDescriptors, parserErrors, codeBuilderResult, codeTree)
|
: base(document, tagHelperDescriptors, errorSink)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Instantiates a new <see cref="GeneratorResults"/> instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="success"><c>true</c> if parsing was successful, <c>false</c> otherwise.</param>
|
|
||||||
/// <param name="document">The <see cref="Block"/> for the syntax tree.</param>
|
|
||||||
/// <param name="tagHelperDescriptors"><see cref="TagHelperDescriptor"/>s for the document.</param>
|
|
||||||
/// <param name="parserErrors"><see cref="RazorError"/>s encountered when parsing the document.</param>
|
|
||||||
/// <param name="codeBuilderResult">The results of generating code for the document.</param>
|
|
||||||
/// <param name="codeTree">A <see cref="CodeTree"/> for the document.</param>
|
|
||||||
protected GeneratorResults(bool success,
|
|
||||||
[NotNull] Block document,
|
|
||||||
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
|
|
||||||
[NotNull] IList<RazorError> parserErrors,
|
|
||||||
[NotNull] CodeBuilderResult codeBuilderResult,
|
|
||||||
[NotNull] CodeTree codeTree)
|
|
||||||
: base(success, document, tagHelperDescriptors, parserErrors)
|
|
||||||
{
|
{
|
||||||
GeneratedCode = codeBuilderResult.Code;
|
GeneratedCode = codeBuilderResult.Code;
|
||||||
DesignTimeLineMappings = codeBuilderResult.DesignTimeLineMappings;
|
DesignTimeLineMappings = codeBuilderResult.DesignTimeLineMappings;
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
// TagHelperDescriptors are not found by default. The RazorParser is responsible
|
// TagHelperDescriptors are not found by default. The RazorParser is responsible
|
||||||
// for identifying TagHelperDescriptors and rebuilding ParserResults.
|
// for identifying TagHelperDescriptors and rebuilding ParserResults.
|
||||||
tagHelperDescriptors: Enumerable.Empty<TagHelperDescriptor>(),
|
tagHelperDescriptors: Enumerable.Empty<TagHelperDescriptor>(),
|
||||||
parserErrors: _errorSink.Errors.ToList());
|
errorSink: _errorSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
[Conditional("DEBUG")]
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the new result
|
// Return the new result
|
||||||
return new ParserResults(syntaxTree, descriptors, errorSink.Errors.ToList());
|
return new ParserResults(syntaxTree, descriptors, errorSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
// 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.Parser;
|
||||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||||
using Microsoft.AspNet.Razor.TagHelpers;
|
using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
|
|
||||||
|
|
@ -15,15 +17,18 @@ namespace Microsoft.AspNet.Razor
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instantiates a new <see cref="ParserResults"/> instance.
|
/// Instantiates a new <see cref="ParserResults"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="document">The Razor syntax tree.</param>
|
/// <param name="document">The <see cref="Block"/> for the syntax tree.</param>
|
||||||
/// <param name="tagHelperDescriptors"><see cref="TagHelperDescriptor"/>s that apply to the current Razor
|
/// <param name="tagHelperDescriptors">
|
||||||
/// document.</param>
|
/// The <see cref="TagHelperDescriptor"/>s that apply to the current Razor document.
|
||||||
/// <param name="parserErrors"><see cref="RazorError"/>s encountered when parsing the current Razor
|
/// </param>
|
||||||
/// document.</param>
|
/// <param name="errorSink">
|
||||||
|
/// The <see cref="ParserErrorSink"/> used to collect <see cref="RazorError"/>s encountered when parsing the
|
||||||
|
/// current Razor document.
|
||||||
|
/// </param>
|
||||||
public ParserResults([NotNull] Block document,
|
public ParserResults([NotNull] Block document,
|
||||||
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
|
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
|
||||||
[NotNull] IList<RazorError> parserErrors)
|
[NotNull] ParserErrorSink errorSink)
|
||||||
: this(parserErrors == null || parserErrors.Count == 0, document, tagHelperDescriptors, parserErrors)
|
: this(!errorSink.Errors.Any(), document, tagHelperDescriptors, errorSink)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,40 +36,50 @@ namespace Microsoft.AspNet.Razor
|
||||||
/// Instantiates a new <see cref="ParserResults"/> instance.
|
/// Instantiates a new <see cref="ParserResults"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="success"><c>true</c> if parsing was successful, <c>false</c> otherwise.</param>
|
/// <param name="success"><c>true</c> if parsing was successful, <c>false</c> otherwise.</param>
|
||||||
/// <param name="document">The Razor syntax tree.</param>
|
/// <param name="document">The <see cref="Block"/> for the syntax tree.</param>
|
||||||
/// <param name="tagHelperDescriptors"><see cref="TagHelperDescriptor"/>s that apply to the current Razor
|
/// <param name="tagHelperDescriptors">
|
||||||
/// document.</param>
|
/// The <see cref="TagHelperDescriptor"/>s that apply to the current Razor document.
|
||||||
/// <param name="errors"><see cref="RazorError"/>s encountered when parsing the current Razor
|
/// </param>
|
||||||
/// document.</param>
|
/// <param name="errorSink">
|
||||||
|
/// The <see cref="ParserErrorSink"/> used to collect <see cref="RazorError"/>s encountered when parsing the
|
||||||
|
/// current Razor document.
|
||||||
|
/// </param>
|
||||||
protected ParserResults(bool success,
|
protected ParserResults(bool success,
|
||||||
[NotNull] Block document,
|
[NotNull] Block document,
|
||||||
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
|
[NotNull] IEnumerable<TagHelperDescriptor> tagHelperDescriptors,
|
||||||
[NotNull] IList<RazorError> errors)
|
[NotNull] ParserErrorSink errorSink)
|
||||||
{
|
{
|
||||||
Success = success;
|
Success = success;
|
||||||
Document = document;
|
Document = document;
|
||||||
TagHelperDescriptors = tagHelperDescriptors;
|
TagHelperDescriptors = tagHelperDescriptors;
|
||||||
ParserErrors = errors ?? new List<RazorError>();
|
ErrorSink = errorSink;
|
||||||
|
ParserErrors = errorSink.Errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates if parsing was successful (no errors)
|
/// Indicates if parsing was successful (no errors).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Success { get; private set; }
|
/// <value><c>true</c> if parsing was successful, <c>false</c> otherwise.</value>
|
||||||
|
public bool Success { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The root node in the document's syntax tree
|
/// The root node in the document's syntax tree.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Block Document { get; private set; }
|
public Block Document { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to aggregate <see cref="RazorError"/>s.
|
||||||
|
/// </summary>
|
||||||
|
public ParserErrorSink ErrorSink { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of errors which occurred during parsing.
|
/// The list of errors which occurred during parsing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IList<RazorError> ParserErrors { get; private set; }
|
public IEnumerable<RazorError> ParserErrors { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="TagHelperDescriptor"/>s found for the current Razor document.
|
/// The <see cref="TagHelperDescriptor"/>s found for the current Razor document.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<TagHelperDescriptor> TagHelperDescriptors { get; private set; }
|
public IEnumerable<TagHelperDescriptor> TagHelperDescriptors { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ namespace Microsoft.AspNet.Razor
|
||||||
generator.DesignTimeMode = Host.DesignTimeMode;
|
generator.DesignTimeMode = Host.DesignTimeMode;
|
||||||
generator.Visit(results);
|
generator.Visit(results);
|
||||||
|
|
||||||
var codeBuilderContext = new CodeBuilderContext(generator.Context);
|
var codeBuilderContext = new CodeBuilderContext(generator.Context, results.ErrorSink);
|
||||||
codeBuilderContext.Checksum = checksum;
|
codeBuilderContext.Checksum = checksum;
|
||||||
var builder = CreateCodeBuilder(codeBuilderContext);
|
var builder = CreateCodeBuilder(codeBuilderContext);
|
||||||
var builderResult = builder.Build();
|
var builderResult = builder.Build();
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,8 @@ namespace Microsoft.AspNet.Razor.Test
|
||||||
"myclass",
|
"myclass",
|
||||||
"myns",
|
"myns",
|
||||||
string.Empty,
|
string.Empty,
|
||||||
shouldGenerateLinePragmas: false);
|
shouldGenerateLinePragmas: false,
|
||||||
|
errorSink: new ParserErrorSink());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var generator = language.CreateCodeBuilder(codeBuilderContext);
|
var generator = language.CreateCodeBuilder(codeBuilderContext);
|
||||||
|
|
|
||||||
|
|
@ -434,28 +434,30 @@ namespace Microsoft.AspNet.Razor.Test.Framework
|
||||||
collector.AddError("{0} - FAILED :: Actual: << Null >>", expected);
|
collector.AddError("{0} - FAILED :: Actual: << Null >>", expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void EvaluateRazorErrors(IList<RazorError> actualErrors, IList<RazorError> expectedErrors)
|
public static void EvaluateRazorErrors(IEnumerable<RazorError> actualErrors, IList<RazorError> expectedErrors)
|
||||||
{
|
{
|
||||||
|
var realCount = actualErrors.Count();
|
||||||
|
|
||||||
// Evaluate the errors
|
// Evaluate the errors
|
||||||
if (expectedErrors == null || expectedErrors.Count == 0)
|
if (expectedErrors == null || expectedErrors.Count == 0)
|
||||||
{
|
{
|
||||||
Assert.True(actualErrors.Count == 0,
|
Assert.True(realCount == 0,
|
||||||
String.Format("Expected that no errors would be raised, but the following errors were:\r\n{0}", FormatErrors(actualErrors)));
|
String.Format("Expected that no errors would be raised, but the following errors were:\r\n{0}", FormatErrors(actualErrors)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Assert.True(expectedErrors.Count == actualErrors.Count,
|
Assert.True(expectedErrors.Count == realCount,
|
||||||
String.Format("Expected that {0} errors would be raised, but {1} errors were.\r\nExpected Errors: \r\n{2}\r\nActual Errors: \r\n{3}",
|
String.Format("Expected that {0} errors would be raised, but {1} errors were.\r\nExpected Errors: \r\n{2}\r\nActual Errors: \r\n{3}",
|
||||||
expectedErrors.Count,
|
expectedErrors.Count,
|
||||||
actualErrors.Count,
|
realCount,
|
||||||
FormatErrors(expectedErrors),
|
FormatErrors(expectedErrors),
|
||||||
FormatErrors(actualErrors)));
|
FormatErrors(actualErrors)));
|
||||||
Assert.Equal(expectedErrors.ToArray(), actualErrors.ToArray());
|
Assert.Equal(expectedErrors, actualErrors);
|
||||||
}
|
}
|
||||||
WriteTraceLine("Expected Errors were raised:\r\n{0}", FormatErrors(expectedErrors));
|
WriteTraceLine("Expected Errors were raised:\r\n{0}", FormatErrors(expectedErrors));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string FormatErrors(IList<RazorError> errors)
|
public static string FormatErrors(IEnumerable<RazorError> errors)
|
||||||
{
|
{
|
||||||
if (errors == null)
|
if (errors == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
||||||
|
using Microsoft.AspNet.Razor.Parser;
|
||||||
using Microsoft.AspNet.Razor.TagHelpers;
|
using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -161,7 +162,8 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
"MyClass",
|
"MyClass",
|
||||||
"MyNamespace",
|
"MyNamespace",
|
||||||
string.Empty,
|
string.Empty,
|
||||||
shouldGenerateLinePragmas: true));
|
shouldGenerateLinePragmas: true),
|
||||||
|
new ParserErrorSink());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TrackingUniqueIdsTagHelperCodeRenderer : CSharpTagHelperCodeRenderer
|
private class TrackingUniqueIdsTagHelperCodeRenderer : CSharpTagHelperCodeRenderer
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#if !ASPNETCORE50
|
#if !ASPNETCORE50
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
|
using Microsoft.AspNet.Razor.Parser;
|
||||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||||
using Microsoft.AspNet.Razor.Test.Utils;
|
using Microsoft.AspNet.Razor.Test.Utils;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -23,7 +24,8 @@ namespace Microsoft.AspNet.Razor.Test.Generator.CodeTree
|
||||||
"TestClass",
|
"TestClass",
|
||||||
"TestNamespace",
|
"TestNamespace",
|
||||||
"Foo.cs",
|
"Foo.cs",
|
||||||
shouldGenerateLinePragmas: false);
|
shouldGenerateLinePragmas: false,
|
||||||
|
errorSink: new ParserErrorSink());
|
||||||
codeBuilderContext.CodeTreeBuilder.AddUsingChunk("FakeNamespace1", syntaxTreeNode.Object);
|
codeBuilderContext.CodeTreeBuilder.AddUsingChunk("FakeNamespace1", syntaxTreeNode.Object);
|
||||||
codeBuilderContext.CodeTreeBuilder.AddUsingChunk("FakeNamespace2.SubNamespace", syntaxTreeNode.Object);
|
codeBuilderContext.CodeTreeBuilder.AddUsingChunk("FakeNamespace2.SubNamespace", syntaxTreeNode.Object);
|
||||||
var codeBuilder = language.CreateCodeBuilder(codeBuilderContext);
|
var codeBuilder = language.CreateCodeBuilder(codeBuilderContext);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#if !ASPNETCORE50
|
#if !ASPNETCORE50
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||||
|
using Microsoft.AspNet.Razor.Parser;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -34,7 +35,8 @@ namespace Microsoft.AspNet.Razor
|
||||||
"myclass",
|
"myclass",
|
||||||
"myns",
|
"myns",
|
||||||
string.Empty,
|
string.Empty,
|
||||||
shouldGenerateLinePragmas: false);
|
shouldGenerateLinePragmas: false,
|
||||||
|
errorSink: new ParserErrorSink());
|
||||||
var writer = Mock.Of<CodeWriter>();
|
var writer = Mock.Of<CodeWriter>();
|
||||||
return new Mock<ChunkVisitor<CodeWriter>>(writer, codeBuilderContext);
|
return new Mock<ChunkVisitor<CodeWriter>>(writer, codeBuilderContext);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.Html
|
||||||
var rewritten = rewritingContext.SyntaxTree;
|
var rewritten = rewritingContext.SyntaxTree;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(0, results.ParserErrors.Count);
|
Assert.Equal(0, results.ParserErrors.Count());
|
||||||
EvaluateParseTree(rewritten,
|
EvaluateParseTree(rewritten,
|
||||||
new MarkupBlock(
|
new MarkupBlock(
|
||||||
new MarkupTagBlock(
|
new MarkupTagBlock(
|
||||||
|
|
@ -277,7 +277,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.Html
|
||||||
var rewritten = rewritingContext.SyntaxTree;
|
var rewritten = rewritingContext.SyntaxTree;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(0, results.ParserErrors.Count);
|
Assert.Equal(0, results.ParserErrors.Count());
|
||||||
Assert.Equal(rewritten.Children.Count(), results.Document.Children.Count());
|
Assert.Equal(rewritten.Children.Count(), results.Document.Children.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,10 @@ namespace Microsoft.AspNet.Razor.Test.Parser
|
||||||
public void VisitThrowsOnNullVisitor()
|
public void VisitThrowsOnNullVisitor()
|
||||||
{
|
{
|
||||||
ParserVisitor target = null;
|
ParserVisitor target = null;
|
||||||
|
var errorSink = new ParserErrorSink();
|
||||||
var results = new ParserResults(new BlockBuilder() { Type = BlockType.Comment }.Build(),
|
var results = new ParserResults(new BlockBuilder() { Type = BlockType.Comment }.Build(),
|
||||||
Enumerable.Empty<TagHelperDescriptor>(),
|
Enumerable.Empty<TagHelperDescriptor>(),
|
||||||
parserErrors: new List<RazorError>());
|
errorSink);
|
||||||
|
|
||||||
Assert.Throws<ArgumentNullException>("self", () => target.Visit(results));
|
Assert.Throws<ArgumentNullException>("self", () => target.Visit(results));
|
||||||
}
|
}
|
||||||
|
|
@ -39,9 +40,10 @@ namespace Microsoft.AspNet.Razor.Test.Parser
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
||||||
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
||||||
|
var errorSink = new ParserErrorSink();
|
||||||
var results = new ParserResults(root,
|
var results = new ParserResults(root,
|
||||||
Enumerable.Empty<TagHelperDescriptor>(),
|
Enumerable.Empty<TagHelperDescriptor>(),
|
||||||
parserErrors: new List<RazorError>());
|
errorSink);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
targetMock.Object.Visit(results);
|
targetMock.Object.Visit(results);
|
||||||
|
|
@ -56,11 +58,17 @@ namespace Microsoft.AspNet.Razor.Test.Parser
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
||||||
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
||||||
List<RazorError> errors = new List<RazorError>() {
|
var errorSink = new ParserErrorSink();
|
||||||
|
List<RazorError> errors = new List<RazorError>
|
||||||
|
{
|
||||||
new RazorError("Foo", 1, 0, 1),
|
new RazorError("Foo", 1, 0, 1),
|
||||||
new RazorError("Bar", 2, 0, 2)
|
new RazorError("Bar", 2, 0, 2),
|
||||||
};
|
};
|
||||||
var results = new ParserResults(root, Enumerable.Empty<TagHelperDescriptor>(), errors);
|
foreach (var error in errors)
|
||||||
|
{
|
||||||
|
errorSink.OnError(error);
|
||||||
|
}
|
||||||
|
var results = new ParserResults(root, Enumerable.Empty<TagHelperDescriptor>(), errorSink);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
targetMock.Object.Visit(results);
|
targetMock.Object.Visit(results);
|
||||||
|
|
@ -76,11 +84,10 @@ namespace Microsoft.AspNet.Razor.Test.Parser
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
||||||
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
||||||
List<RazorError> errors = new List<RazorError>() {
|
var errorSink = new ParserErrorSink();
|
||||||
new RazorError("Foo", 1, 0, 1),
|
errorSink.OnError(new RazorError("Foo", 1, 0, 1));
|
||||||
new RazorError("Bar", 2, 0, 2)
|
errorSink.OnError(new RazorError("Bar", 2, 0, 2));
|
||||||
};
|
var results = new ParserResults(root, Enumerable.Empty<TagHelperDescriptor>(), errorSink);
|
||||||
var results = new ParserResults(root, Enumerable.Empty<TagHelperDescriptor>(), errors);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
targetMock.Object.Visit(results);
|
targetMock.Object.Visit(results);
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,8 @@ namespace Microsoft.AspNet.Razor.Test
|
||||||
"different-class",
|
"different-class",
|
||||||
"different-ns",
|
"different-ns",
|
||||||
string.Empty,
|
string.Empty,
|
||||||
shouldGenerateLinePragmas: true);
|
shouldGenerateLinePragmas: true,
|
||||||
|
errorSink: new ParserErrorSink());
|
||||||
|
|
||||||
var expected = new CSharpCodeBuilder(codeBuilderContext);
|
var expected = new CSharpCodeBuilder(codeBuilderContext);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue