Make usage of FileName and FilePath consistent
FileName => "Foo.cshtml" FilePath => "/Bar/Baz/Foo.cshtml"
This commit is contained in:
parent
6ce71c24e5
commit
6860806213
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
ClassDeclarationIRNode @class,
|
ClassDeclarationIRNode @class,
|
||||||
MethodDeclarationIRNode method)
|
MethodDeclarationIRNode method)
|
||||||
{
|
{
|
||||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FileName;
|
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath;
|
||||||
|
|
||||||
base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
|
base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
|
||||||
@class.Name = CSharpIdentifier.GetClassNameFromPath(filePath);
|
@class.Name = CSharpIdentifier.GetClassNameFromPath(filePath);
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TryComputeNamespace(codeDocument.Source.FileName, directive, out var computedNamespace))
|
if (TryComputeNamespace(codeDocument.Source.FilePath, directive, out var computedNamespace))
|
||||||
{
|
{
|
||||||
// Beautify the class name since we're using a hierarchy for namespaces.
|
// Beautify the class name since we're using a hierarchy for namespaces.
|
||||||
var @class = visitor.FirstClass;
|
var @class = visitor.FirstClass;
|
||||||
var prefix = CSharpIdentifier.SanitizeClassName(Path.GetFileNameWithoutExtension(codeDocument.Source.FileName));
|
var prefix = CSharpIdentifier.SanitizeClassName(Path.GetFileNameWithoutExtension(codeDocument.Source.FilePath));
|
||||||
if (@class != null && irDocument.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind)
|
if (@class != null && irDocument.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind)
|
||||||
{
|
{
|
||||||
@class.Name = prefix + "_Page";
|
@class.Name = prefix + "_Page";
|
||||||
|
|
@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
// This code does a best-effort attempt to compute a namespace 'suffix' - the path difference between
|
// This code does a best-effort attempt to compute a namespace 'suffix' - the path difference between
|
||||||
// where the @namespace directive appears and where the current document is on disk.
|
// where the @namespace directive appears and where the current document is on disk.
|
||||||
//
|
//
|
||||||
// In the event that these two source either don't have filenames set or don't follow a coherent hierarchy,
|
// In the event that these two source either don't have FileNames set or don't follow a coherent hierarchy,
|
||||||
// we will just use the namespace verbatim.
|
// we will just use the namespace verbatim.
|
||||||
internal static bool TryComputeNamespace(string source, DirectiveIRNode directive, out string @namespace)
|
internal static bool TryComputeNamespace(string source, DirectiveIRNode directive, out string @namespace)
|
||||||
{
|
{
|
||||||
|
|
@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
|
|
||||||
var segments = source.Substring(directiveSource.Length).Split(Separators);
|
var segments = source.Substring(directiveSource.Length).Split(Separators);
|
||||||
|
|
||||||
// Skip the last segment because it's the filename.
|
// Skip the last segment because it's the FileName.
|
||||||
for (var i = 0; i < segments.Length - 1; i++)
|
for (var i = 0; i < segments.Length - 1; i++)
|
||||||
{
|
{
|
||||||
builder.Append('.');
|
builder.Append('.');
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
ClassDeclarationIRNode @class,
|
ClassDeclarationIRNode @class,
|
||||||
MethodDeclarationIRNode method)
|
MethodDeclarationIRNode method)
|
||||||
{
|
{
|
||||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FileName;
|
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath;
|
||||||
|
|
||||||
base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
|
base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
|
||||||
@class.BaseType = "global::Microsoft.AspNetCore.Mvc.RazorPages.Page";
|
@class.BaseType = "global::Microsoft.AspNetCore.Mvc.RazorPages.Page";
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SourceDocument.FileName != null &&
|
if (SourceDocument.FilePath != null &&
|
||||||
!string.Equals(SourceDocument.FileName, node.Source.Value.FilePath, StringComparison.OrdinalIgnoreCase))
|
!string.Equals(SourceDocument.FilePath, node.Source.Value.FilePath, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
// We don't want to generate line mappings for imports.
|
// We don't want to generate line mappings for imports.
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
var tokenKind = node.Descriptor.Kind;
|
var tokenKind = node.Descriptor.Kind;
|
||||||
if (!node.Source.HasValue ||
|
if (!node.Source.HasValue ||
|
||||||
!string.Equals(
|
!string.Equals(
|
||||||
context.SourceDocument?.FileName,
|
context.SourceDocument?.FilePath,
|
||||||
node.Source.Value.FilePath,
|
node.Source.Value.FilePath,
|
||||||
StringComparison.OrdinalIgnoreCase))
|
StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
{
|
{
|
||||||
context.Writer
|
context.Writer
|
||||||
.Write("#pragma checksum \"")
|
.Write("#pragma checksum \"")
|
||||||
.Write(node.FileName)
|
.Write(node.FilePath)
|
||||||
.Write("\" \"")
|
.Write("\" \"")
|
||||||
.Write(node.Guid)
|
.Write(node.Guid)
|
||||||
.Write("\" \"")
|
.Write("\" \"")
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
var import = imports[j];
|
var import = imports[j];
|
||||||
|
|
||||||
importsVisitor.FileName = import.Source.FileName;
|
importsVisitor.FilePath = import.Source.FilePath;
|
||||||
importsVisitor.VisitBlock(import.Root);
|
importsVisitor.VisitBlock(import.Root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var tagHelperPrefix = tagHelperContext?.Prefix;
|
var tagHelperPrefix = tagHelperContext?.Prefix;
|
||||||
var visitor = new MainSourceVisitor(document, builder, namespaces, tagHelperPrefix)
|
var visitor = new MainSourceVisitor(document, builder, namespaces, tagHelperPrefix)
|
||||||
{
|
{
|
||||||
FileName = syntaxTree.Source.FileName,
|
FilePath = syntaxTree.Source.FilePath,
|
||||||
};
|
};
|
||||||
|
|
||||||
visitor.VisitBlock(syntaxTree.Root);
|
visitor.VisitBlock(syntaxTree.Root);
|
||||||
|
|
@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
_namespaces = namespaces;
|
_namespaces = namespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FileName { get; set; }
|
public string FilePath { get; set; }
|
||||||
|
|
||||||
public override void VisitImportSpan(AddImportChunkGenerator chunkGenerator, Span span)
|
public override void VisitImportSpan(AddImportChunkGenerator chunkGenerator, Span span)
|
||||||
{
|
{
|
||||||
|
|
@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
}
|
}
|
||||||
|
|
||||||
var span = new SourceSpan(
|
var span = new SourceSpan(
|
||||||
node.Start.FilePath ?? FileName,
|
node.Start.FilePath ?? FilePath,
|
||||||
node.Start.AbsoluteIndex,
|
node.Start.AbsoluteIndex,
|
||||||
node.Start.LineIndex,
|
node.Start.LineIndex,
|
||||||
node.Start.CharacterIndex,
|
node.Start.CharacterIndex,
|
||||||
|
|
@ -331,7 +331,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
if (location != SourceLocation.Undefined)
|
if (location != SourceLocation.Undefined)
|
||||||
{
|
{
|
||||||
valueSpan = new SourceSpan(
|
valueSpan = new SourceSpan(
|
||||||
location.FilePath ?? FileName,
|
location.FilePath ?? FilePath,
|
||||||
location.AbsoluteIndex,
|
location.AbsoluteIndex,
|
||||||
location.LineIndex,
|
location.LineIndex,
|
||||||
location.CharacterIndex,
|
location.CharacterIndex,
|
||||||
|
|
@ -369,7 +369,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var contentLength = templateNode.Children.Sum(child => child.Source?.Length ?? 0);
|
var contentLength = templateNode.Children.Sum(child => child.Source?.Length ?? 0);
|
||||||
|
|
||||||
templateNode.Source = new SourceSpan(
|
templateNode.Source = new SourceSpan(
|
||||||
sourceRangeStart.Value.FilePath ?? FileName,
|
sourceRangeStart.Value.FilePath ?? FilePath,
|
||||||
sourceRangeStart.Value.AbsoluteIndex,
|
sourceRangeStart.Value.AbsoluteIndex,
|
||||||
sourceRangeStart.Value.LineIndex,
|
sourceRangeStart.Value.LineIndex,
|
||||||
sourceRangeStart.Value.CharacterIndex,
|
sourceRangeStart.Value.CharacterIndex,
|
||||||
|
|
@ -412,7 +412,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var contentLength = expressionNode.Children.Sum(child => child.Source?.Length ?? 0);
|
var contentLength = expressionNode.Children.Sum(child => child.Source?.Length ?? 0);
|
||||||
|
|
||||||
expressionNode.Source = new SourceSpan(
|
expressionNode.Source = new SourceSpan(
|
||||||
sourceRangeStart.Value.FilePath ?? FileName,
|
sourceRangeStart.Value.FilePath ?? FilePath,
|
||||||
sourceRangeStart.Value.AbsoluteIndex,
|
sourceRangeStart.Value.AbsoluteIndex,
|
||||||
sourceRangeStart.Value.LineIndex,
|
sourceRangeStart.Value.LineIndex,
|
||||||
sourceRangeStart.Value.CharacterIndex,
|
sourceRangeStart.Value.CharacterIndex,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// We have an exact match for the start of a line.
|
// We have an exact match for the start of a line.
|
||||||
Debug.Assert(_lineStarts[index] == position);
|
Debug.Assert(_lineStarts[index] == position);
|
||||||
|
|
||||||
return new SourceLocation(_document.FileName, position, index, characterIndex: 0);
|
return new SourceLocation(_document.FilePath, position, index, characterIndex: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -59,12 +59,12 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
// There's no preceding line, so it's based on the start of the string
|
// There's no preceding line, so it's based on the start of the string
|
||||||
return new SourceLocation(_document.FileName, position, 0, position);
|
return new SourceLocation(_document.FilePath, position, 0, position);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var characterIndex = position - _lineStarts[index];
|
var characterIndex = position - _lineStarts[index];
|
||||||
return new SourceLocation(_document.FileName, position, index, characterIndex);
|
return new SourceLocation(_document.FilePath, position, index, characterIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
|
||||||
|
|
||||||
public string Bytes { get; set; }
|
public string Bytes { get; set; }
|
||||||
|
|
||||||
public string FileName { get; set; }
|
public string FilePath { get; set; }
|
||||||
|
|
||||||
public string Guid { get; set; }
|
public string Guid { get; set; }
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
|
||||||
|
|
||||||
var node = new ChecksumIRNode()
|
var node = new ChecksumIRNode()
|
||||||
{
|
{
|
||||||
FileName = sourceDocument.FileName,
|
FilePath = sourceDocument.FilePath,
|
||||||
Guid = Sha1AlgorithmId
|
Guid = Sha1AlgorithmId
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
_chunkMaxLength = chunkMaxLength;
|
_chunkMaxLength = chunkMaxLength;
|
||||||
Encoding = encoding;
|
Encoding = encoding;
|
||||||
FileName = fileName;
|
FilePath = fileName;
|
||||||
|
|
||||||
ReadChunks(reader, _chunkMaxLength, out _length, out _chunks);
|
ReadChunks(reader, _chunkMaxLength, out _length, out _chunks);
|
||||||
_lines = new DefaultRazorSourceLineCollection(this);
|
_lines = new DefaultRazorSourceLineCollection(this);
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
public override Encoding Encoding { get; }
|
public override Encoding Encoding { get; }
|
||||||
|
|
||||||
public override string FileName { get; }
|
public override string FilePath { get; }
|
||||||
|
|
||||||
public override int Length => _length;
|
public override int Length => _length;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
var chars = new char[source.Length];
|
var chars = new char[source.Length];
|
||||||
source.CopyTo(0, chars, 0, source.Length);
|
source.CopyTo(0, chars, 0, source.Length);
|
||||||
|
|
||||||
Source = new SeekableTextReader(chars, source.FileName);
|
Source = new SeekableTextReader(chars, source.FilePath);
|
||||||
DesignTimeMode = options.DesignTime;
|
DesignTimeMode = options.DesignTime;
|
||||||
ParseOnlyLeadingDirectives = options.ParseOnlyLeadingDirectives;
|
ParseOnlyLeadingDirectives = options.ParseOnlyLeadingDirectives;
|
||||||
Builder = new SyntaxTreeBuilder();
|
Builder = new SyntaxTreeBuilder();
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Path of the file the content was read from.
|
/// Path of the file the content was read from.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract string FileName { get; }
|
public abstract string FilePath { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a character at given position.
|
/// Gets a character at given position.
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
public override Encoding Encoding => _innerSourceDocument.Encoding;
|
public override Encoding Encoding => _innerSourceDocument.Encoding;
|
||||||
|
|
||||||
public override string FileName => _innerSourceDocument.FileName;
|
public override string FilePath => _innerSourceDocument.FilePath;
|
||||||
|
|
||||||
public override int Length => _innerSourceDocument.Length;
|
public override int Length => _innerSourceDocument.Length;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
private readonly RazorSourceLineCollection _lines;
|
private readonly RazorSourceLineCollection _lines;
|
||||||
private byte[] _checksum;
|
private byte[] _checksum;
|
||||||
|
|
||||||
public StringSourceDocument(string content, Encoding encoding, string fileName)
|
public StringSourceDocument(string content, Encoding encoding, string filePath)
|
||||||
{
|
{
|
||||||
if (content == null)
|
if (content == null)
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
_content = content;
|
_content = content;
|
||||||
Encoding = encoding;
|
Encoding = encoding;
|
||||||
FileName = fileName;
|
FilePath = filePath;
|
||||||
|
|
||||||
_lines = new DefaultRazorSourceLineCollection(this);
|
_lines = new DefaultRazorSourceLineCollection(this);
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
public override Encoding Encoding { get; }
|
public override Encoding Encoding { get; }
|
||||||
|
|
||||||
public override string FileName { get; }
|
public override string FilePath { get; }
|
||||||
|
|
||||||
public override int Length => _content.Length;
|
public override int Length => _content.Length;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.CodeAnalysis.Remote.Razor
|
||||||
return Task.FromResult(directives ?? Enumerable.Empty<DirectiveDescriptor>());
|
return Task.FromResult(directives ?? Enumerable.Empty<DirectiveDescriptor>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<GeneratedDocument> GenerateDocumentAsync(Guid projectIdBytes, string projectDebugName, string filename, string text, CancellationToken cancellationToken = default(CancellationToken))
|
public Task<GeneratedDocument> GenerateDocumentAsync(Guid projectIdBytes, string projectDebugName, string filePath, string text, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
var projectId = ProjectId.CreateFromSerialized(projectIdBytes, projectDebugName);
|
var projectId = ProjectId.CreateFromSerialized(projectIdBytes, projectDebugName);
|
||||||
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.CodeAnalysis.Remote.Razor
|
||||||
stream.Write(bytes, 0, bytes.Length);
|
stream.Write(bytes, 0, bytes.Length);
|
||||||
|
|
||||||
stream.Seek(0L, SeekOrigin.Begin);
|
stream.Seek(0L, SeekOrigin.Begin);
|
||||||
source = RazorSourceDocument.ReadFrom(stream, filename, Encoding.UTF8);
|
source = RazorSourceDocument.ReadFrom(stream, filePath, Encoding.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
var code = RazorCodeDocument.Create(source);
|
var code = RazorCodeDocument.Create(source);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
[Export(typeof(IRazorEngineDocumentGenerator))]
|
[Export(typeof(IRazorEngineDocumentGenerator))]
|
||||||
internal class DefaultRazorEngineDocumentGenerator : IRazorEngineDocumentGenerator
|
internal class DefaultRazorEngineDocumentGenerator : IRazorEngineDocumentGenerator
|
||||||
{
|
{
|
||||||
public async Task<RazorEngineDocument> GenerateDocumentAsync(Workspace workspace, Project project, string filename, string text, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<RazorEngineDocument> GenerateDocumentAsync(Workspace workspace, Project project, string filePath, string text, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
|
|
||||||
using (var session = await client.CreateSessionAsync(project.Solution))
|
using (var session = await client.CreateSessionAsync(project.Solution))
|
||||||
{
|
{
|
||||||
var document = await session.InvokeAsync<RazorEngineDocument>("GenerateDocumentAsync", new object[] { project.Id.Id, "Foo", filename, text }).ConfigureAwait(false);
|
var document = await session.InvokeAsync<RazorEngineDocument>("GenerateDocumentAsync", new object[] { project.Id.Id, "Foo", filePath, text }).ConfigureAwait(false);
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,13 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
var span = spans[i];
|
var span = spans[i];
|
||||||
result[i] = new ClassifiedSpan(
|
result[i] = new ClassifiedSpan(
|
||||||
new SourceSpan(
|
new SourceSpan(
|
||||||
span.Start.FilePath ?? syntaxTree.Source.FileName,
|
span.Start.FilePath ?? syntaxTree.Source.FilePath,
|
||||||
span.Start.AbsoluteIndex,
|
span.Start.AbsoluteIndex,
|
||||||
span.Start.LineIndex,
|
span.Start.LineIndex,
|
||||||
span.Start.CharacterIndex,
|
span.Start.CharacterIndex,
|
||||||
span.Length),
|
span.Length),
|
||||||
new SourceSpan(
|
new SourceSpan(
|
||||||
span.Parent.Start.FilePath ?? syntaxTree.Source.FileName,
|
span.Parent.Start.FilePath ?? syntaxTree.Source.FilePath,
|
||||||
span.Parent.Start.AbsoluteIndex,
|
span.Parent.Start.AbsoluteIndex,
|
||||||
span.Parent.Start.LineIndex,
|
span.Parent.Start.LineIndex,
|
||||||
span.Parent.Start.CharacterIndex,
|
span.Parent.Start.CharacterIndex,
|
||||||
|
|
@ -111,7 +111,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
{
|
{
|
||||||
results.Add(new TagHelperSpan(
|
results.Add(new TagHelperSpan(
|
||||||
new SourceSpan(
|
new SourceSpan(
|
||||||
tagHelperNode.Start.FilePath ?? syntaxTree.Source.FileName,
|
tagHelperNode.Start.FilePath ?? syntaxTree.Source.FilePath,
|
||||||
tagHelperNode.Start.AbsoluteIndex,
|
tagHelperNode.Start.AbsoluteIndex,
|
||||||
tagHelperNode.Start.LineIndex,
|
tagHelperNode.Start.LineIndex,
|
||||||
tagHelperNode.Start.CharacterIndex,
|
tagHelperNode.Start.CharacterIndex,
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
throw new ArgumentNullException(nameof(textBuffer));
|
throw new ArgumentNullException(nameof(textBuffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's no document we can't find the filename, or look for a matching hierarchy.
|
// If there's no document we can't find the FileName, or look for a matching hierarchy.
|
||||||
if (!_documentFactory.TryGetTextDocument(textBuffer, out var textDocument))
|
if (!_documentFactory.TryGetTextDocument(textBuffer, out var textDocument))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
{
|
{
|
||||||
internal interface IRazorEngineDocumentGenerator
|
internal interface IRazorEngineDocumentGenerator
|
||||||
{
|
{
|
||||||
Task<RazorEngineDocument> GenerateDocumentAsync(Workspace workspace, Project project, string filename, string text, CancellationToken cancellationToken = default(CancellationToken));
|
Task<RazorEngineDocument> GenerateDocumentAsync(Workspace workspace, Project project, string filePath, string text, CancellationToken cancellationToken = default(CancellationToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -46,7 +46,7 @@ namespace RazorPageGenerator
|
||||||
.SetBaseType("Microsoft.Extensions.RazorViews.BaseView")
|
.SetBaseType("Microsoft.Extensions.RazorViews.BaseView")
|
||||||
.ConfigureClass((document, @class) =>
|
.ConfigureClass((document, @class) =>
|
||||||
{
|
{
|
||||||
@class.Name = Path.GetFileNameWithoutExtension(document.Source.FileName);
|
@class.Name = Path.GetFileNameWithoutExtension(document.Source.FilePath);
|
||||||
@class.AccessModifier = "internal";
|
@class.AccessModifier = "internal";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -614,7 +614,7 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
||||||
var text = new string(buffer);
|
var text = new string(buffer);
|
||||||
text = Regex.Replace(text, "(?<!\r)\n", "\r\n");
|
text = Regex.Replace(text, "(?<!\r)\n", "\r\n");
|
||||||
|
|
||||||
imports.Add(RazorSourceDocument.Create(text, DefaultImports.FileName, DefaultImports.Encoding));
|
imports.Add(RazorSourceDocument.Create(text, DefaultImports.FilePath, DefaultImports.Encoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MetadataReference BuildDynamicAssembly(
|
private static MetadataReference BuildDynamicAssembly(
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
public static string Serialize(RazorCSharpDocument csharpDocument, RazorSourceDocument sourceDocument)
|
public static string Serialize(RazorCSharpDocument csharpDocument, RazorSourceDocument sourceDocument)
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
var sourceFileName = sourceDocument.FileName;
|
var sourceFilePath = sourceDocument.FilePath;
|
||||||
var charBuffer = new char[sourceDocument.Length];
|
var charBuffer = new char[sourceDocument.Length];
|
||||||
sourceDocument.CopyTo(0, charBuffer, 0, sourceDocument.Length);
|
sourceDocument.CopyTo(0, charBuffer, 0, sourceDocument.Length);
|
||||||
var sourceContent = new string(charBuffer);
|
var sourceContent = new string(charBuffer);
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
for (var i = 0; i < csharpDocument.LineMappings.Count; i++)
|
for (var i = 0; i < csharpDocument.LineMappings.Count; i++)
|
||||||
{
|
{
|
||||||
var lineMapping = csharpDocument.LineMappings[i];
|
var lineMapping = csharpDocument.LineMappings[i];
|
||||||
if (!string.Equals(lineMapping.OriginalSpan.FilePath, sourceFileName, StringComparison.Ordinal))
|
if (!string.Equals(lineMapping.OriginalSpan.FilePath, sourceFilePath, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
Assert.Equal("AddUser_Page", @class.Name);
|
Assert.Equal("AddUser_Page", @class.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles cases where invalid characters appears in filenames. Note that we don't sanitize the part of
|
// Handles cases where invalid characters appears in FileNames. Note that we don't sanitize the part of
|
||||||
// the namespace that you put in an import, just the file-based-suffix. Garbage in, garbage out.
|
// the namespace that you put in an import, just the file-based-suffix. Garbage in, garbage out.
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Pass_SetsNamespaceAndClassName_SanitizesClassAndNamespace()
|
public void Pass_SetsNamespaceAndClassName_SanitizesClassAndNamespace()
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
|
|
||||||
var node = new ChecksumIRNode()
|
var node = new ChecksumIRNode()
|
||||||
{
|
{
|
||||||
FileName = "test.cshtml",
|
FilePath = "test.cshtml",
|
||||||
Guid = "SomeGuid",
|
Guid = "SomeGuid",
|
||||||
Bytes = "SomeFileHash"
|
Bytes = "SomeFileHash"
|
||||||
};
|
};
|
||||||
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
|
|
||||||
var node = new ChecksumIRNode()
|
var node = new ChecksumIRNode()
|
||||||
{
|
{
|
||||||
FileName = "test.cshtml",
|
FilePath = "test.cshtml",
|
||||||
Guid = "SomeGuid",
|
Guid = "SomeGuid",
|
||||||
Bytes = string.Empty
|
Bytes = string.Empty
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var codeDocument = TestRazorCodeDocument.Create(@"@using System");
|
var codeDocument = TestRazorCodeDocument.Create(@"@using System");
|
||||||
var expectedSourceLocation = new SourceSpan(codeDocument.Source.FileName, 1, 0, 1, 12);
|
var expectedSourceLocation = new SourceSpan(codeDocument.Source.FilePath, 1, 0, 1, 12);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var irDocument = Lower(codeDocument);
|
var irDocument = Lower(codeDocument);
|
||||||
|
|
|
||||||
|
|
@ -838,7 +838,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var errorSink = new ErrorSink();
|
var errorSink = new ErrorSink();
|
||||||
var phase = new DefaultRazorTagHelperBinderPhase();
|
var phase = new DefaultRazorTagHelperBinderPhase();
|
||||||
var document = RazorCodeDocument.Create(new StringSourceDocument("Test content", encoding: Encoding.UTF8, fileName: "TestFile"));
|
var document = RazorCodeDocument.Create(new StringSourceDocument("Test content", encoding: Encoding.UTF8, filePath: "TestFile"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var prefix = phase.ProcessTagHelperPrefix(((IEnumerable<TagHelperDirectiveDescriptor>)directiveDescriptors).ToList(), document, errorSink);
|
var prefix = phase.ProcessTagHelperPrefix(((IEnumerable<TagHelperDirectiveDescriptor>)directiveDescriptors).ToList(), document, errorSink);
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
public void GenerateCodeWithDefaults()
|
public void GenerateCodeWithDefaults()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var filePath = Path.Combine(TestProjectRoot, $"{Filename}.cshtml");
|
var filePath = Path.Combine(TestProjectRoot, $"{FileName}.cshtml");
|
||||||
var content = File.ReadAllText(filePath);
|
var content = File.ReadAllText(filePath);
|
||||||
var projectItem = new TestRazorProjectItem($"{Filename}.cshtml", "")
|
var projectItem = new TestRazorProjectItem($"{FileName}.cshtml", "")
|
||||||
{
|
{
|
||||||
Content = content,
|
Content = content,
|
||||||
};
|
};
|
||||||
|
|
@ -33,9 +33,9 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
public void GenerateCodeWithBaseType()
|
public void GenerateCodeWithBaseType()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var filePath = Path.Combine(TestProjectRoot, $"{Filename}.cshtml");
|
var filePath = Path.Combine(TestProjectRoot, $"{FileName}.cshtml");
|
||||||
var content = File.ReadAllText(filePath);
|
var content = File.ReadAllText(filePath);
|
||||||
var projectItem = new TestRazorProjectItem($"{Filename}.cshtml", "")
|
var projectItem = new TestRazorProjectItem($"{FileName}.cshtml", "")
|
||||||
{
|
{
|
||||||
Content = content,
|
Content = content,
|
||||||
};
|
};
|
||||||
|
|
@ -54,9 +54,9 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
public void GenerateCodeWithConfigureClass()
|
public void GenerateCodeWithConfigureClass()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var filePath = Path.Combine(TestProjectRoot, $"{Filename}.cshtml");
|
var filePath = Path.Combine(TestProjectRoot, $"{FileName}.cshtml");
|
||||||
var content = File.ReadAllText(filePath);
|
var content = File.ReadAllText(filePath);
|
||||||
var projectItem = new TestRazorProjectItem($"{Filename}.cshtml", "")
|
var projectItem = new TestRazorProjectItem($"{FileName}.cshtml", "")
|
||||||
{
|
{
|
||||||
Content = content,
|
Content = content,
|
||||||
};
|
};
|
||||||
|
|
@ -88,9 +88,9 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
public void GenerateCodeWithSetNamespace()
|
public void GenerateCodeWithSetNamespace()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var filePath = Path.Combine(TestProjectRoot, $"{Filename}.cshtml");
|
var filePath = Path.Combine(TestProjectRoot, $"{FileName}.cshtml");
|
||||||
var content = File.ReadAllText(filePath);
|
var content = File.ReadAllText(filePath);
|
||||||
var projectItem = new TestRazorProjectItem($"{Filename}.cshtml", "")
|
var projectItem = new TestRazorProjectItem($"{FileName}.cshtml", "")
|
||||||
{
|
{
|
||||||
Content = content,
|
Content = content,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -99,17 +99,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Test
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("test.cshtml")]
|
[InlineData("test.cshtml")]
|
||||||
[InlineData(null)]
|
[InlineData(null)]
|
||||||
public void Filename(string fileName)
|
public void FilePath(string filePath)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var stream = TestRazorSourceDocument.CreateStreamContent("abc");
|
var stream = TestRazorSourceDocument.CreateStreamContent("abc");
|
||||||
var reader = new StreamReader(stream, true);
|
var reader = new StreamReader(stream, true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var document = new LargeTextSourceDocument(reader, ChunkTestLength, Encoding.UTF8, fileName);
|
var document = new LargeTextSourceDocument(reader, ChunkTestLength, Encoding.UTF8, filePath);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(fileName, document.FileName);
|
Assert.Equal(filePath, document.FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsType<StreamSourceDocument>(document);
|
Assert.IsType<StreamSourceDocument>(document);
|
||||||
Assert.Equal("file.cshtml", document.FileName);
|
Assert.Equal("file.cshtml", document.FilePath);
|
||||||
Assert.Same(Encoding.UTF8, document.Encoding);
|
Assert.Same(Encoding.UTF8, document.Encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var document = RazorSourceDocument.ReadFrom(content, "file.cshtml", Encoding.UTF32);
|
var document = RazorSourceDocument.ReadFrom(content, "file.cshtml", Encoding.UTF32);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("file.cshtml", document.FileName);
|
Assert.Equal("file.cshtml", document.FilePath);
|
||||||
Assert.Same(Encoding.UTF32, Assert.IsType<StreamSourceDocument>(document).Encoding);
|
Assert.Same(Encoding.UTF32, Assert.IsType<StreamSourceDocument>(document).Encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var document = RazorSourceDocument.ReadFrom(content, "file.cshtml", Encoding.UTF32);
|
var document = RazorSourceDocument.ReadFrom(content, "file.cshtml", Encoding.UTF32);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("file.cshtml", document.FileName);
|
Assert.Equal("file.cshtml", document.FilePath);
|
||||||
Assert.Same(Encoding.UTF32, Assert.IsType<StreamSourceDocument>(document).Encoding);
|
Assert.Same(Encoding.UTF32, Assert.IsType<StreamSourceDocument>(document).Encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var document = RazorSourceDocument.ReadFrom(projectItem);
|
var document = RazorSourceDocument.ReadFrom(projectItem);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(projectItem.PhysicalPath, document.FileName);
|
Assert.Equal(projectItem.PhysicalPath, document.FilePath);
|
||||||
Assert.Equal(projectItem.Content, ReadContent(document));
|
Assert.Equal(projectItem.Content, ReadContent(document));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var document = RazorSourceDocument.ReadFrom(projectItem);
|
var document = RazorSourceDocument.ReadFrom(projectItem);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(projectItem.Path, document.FileName);
|
Assert.Equal(projectItem.Path, document.FilePath);
|
||||||
Assert.Equal(projectItem.Content, ReadContent(document));
|
Assert.Equal(projectItem.Content, ReadContent(document));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var document = RazorSourceDocument.Create(content, fileName);
|
var document = RazorSourceDocument.Create(content, fileName);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(fileName, document.FileName);
|
Assert.Equal(fileName, document.FilePath);
|
||||||
Assert.Equal(content, ReadContent(document));
|
Assert.Equal(content, ReadContent(document));
|
||||||
Assert.Same(Encoding.UTF8, document.Encoding);
|
Assert.Same(Encoding.UTF8, document.Encoding);
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var document = RazorSourceDocument.Create(content, fileName, encoding);
|
var document = RazorSourceDocument.Create(content, fileName, encoding);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(fileName, document.FileName);
|
Assert.Equal(fileName, document.FilePath);
|
||||||
Assert.Equal(content, ReadContent(document));
|
Assert.Equal(content, ReadContent(document));
|
||||||
Assert.Same(encoding, document.Encoding);
|
Assert.Same(encoding, document.Encoding);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var import = Assert.Single(imports);
|
var import = Assert.Single(imports);
|
||||||
Assert.Equal(projectItem.Path, import.FileName);
|
Assert.Equal(projectItem.Path, import.FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -207,8 +207,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(codeDocument.Imports,
|
Assert.Collection(codeDocument.Imports,
|
||||||
import => Assert.Equal("/MyImport.cshtml", import.FileName),
|
import => Assert.Equal("/MyImport.cshtml", import.FilePath),
|
||||||
import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FileName));
|
import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -236,8 +236,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(codeDocument.Imports,
|
Assert.Collection(codeDocument.Imports,
|
||||||
import => Assert.Same(defaultImport, import),
|
import => Assert.Same(defaultImport, import),
|
||||||
import => Assert.Equal("/MyImport.cshtml", import.FileName),
|
import => Assert.Equal("/MyImport.cshtml", import.FilePath),
|
||||||
import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FileName));
|
import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsType<StreamSourceDocument>(document);
|
Assert.IsType<StreamSourceDocument>(document);
|
||||||
Assert.Equal("file.cshtml", document.FileName);
|
Assert.Equal("file.cshtml", document.FilePath);
|
||||||
Assert.Equal(Encoding.UTF32, document.Encoding);
|
Assert.Equal(Encoding.UTF32, document.Encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsType<StreamSourceDocument>(document);
|
Assert.IsType<StreamSourceDocument>(document);
|
||||||
Assert.Equal("file.cshtml", document.FileName);
|
Assert.Equal("file.cshtml", document.FilePath);
|
||||||
Assert.Equal(Encoding.UTF32, document.Encoding);
|
Assert.Equal(Encoding.UTF32, document.Encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Assert
|
// Assert
|
||||||
var streamDocument = Assert.IsType<StreamSourceDocument>(document);
|
var streamDocument = Assert.IsType<StreamSourceDocument>(document);
|
||||||
Assert.IsType<LargeTextSourceDocument>(streamDocument._innerSourceDocument);
|
Assert.IsType<LargeTextSourceDocument>(streamDocument._innerSourceDocument);
|
||||||
Assert.Equal("file.cshtml", document.FileName);
|
Assert.Equal("file.cshtml", document.FilePath);
|
||||||
Assert.Same(Encoding.UTF8, document.Encoding);
|
Assert.Same(Encoding.UTF8, document.Encoding);
|
||||||
Assert.Equal(content, ReadContent(document));
|
Assert.Equal(content, ReadContent(document));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var expectedContent = "Hello, World!";
|
var expectedContent = "Hello, World!";
|
||||||
var indexerBuffer = new char[expectedContent.Length];
|
var indexerBuffer = new char[expectedContent.Length];
|
||||||
var document = new StringSourceDocument(expectedContent, Encoding.UTF8, fileName: "file.cshtml");
|
var document = new StringSourceDocument(expectedContent, Encoding.UTF8, filePath: "file.cshtml");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
for (var i = 0; i < document.Length; i++)
|
for (var i = 0; i < document.Length; i++)
|
||||||
|
|
@ -78,36 +78,36 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expectedContent = "Hello, World!";
|
var expectedContent = "Hello, World!";
|
||||||
var document = new StringSourceDocument(expectedContent, Encoding.UTF8, fileName: "file.cshtml");
|
var document = new StringSourceDocument(expectedContent, Encoding.UTF8, filePath: "file.cshtml");
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
Assert.Equal(expectedContent.Length, document.Length);
|
Assert.Equal(expectedContent.Length, document.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Filename()
|
public void FilePath()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello, World!";
|
var content = "Hello, World!";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: "file.cshtml");
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: "file.cshtml");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("file.cshtml", document.FileName);
|
Assert.Equal("file.cshtml", document.FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Filename_Null()
|
public void FilePath_Null()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello, World!";
|
var content = "Hello, World!";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Null(document.FileName);
|
Assert.Null(document.FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello, World!";
|
var content = "Hello, World!";
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
var expectedContent = "Hello";
|
var expectedContent = "Hello";
|
||||||
var charBuffer = new char[expectedContent.Length];
|
var charBuffer = new char[expectedContent.Length];
|
||||||
|
|
||||||
|
|
@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello, World!";
|
var content = "Hello, World!";
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
var expectedContent = "$Hello";
|
var expectedContent = "$Hello";
|
||||||
var charBuffer = new char[expectedContent.Length];
|
var charBuffer = new char[expectedContent.Length];
|
||||||
charBuffer[0] = '$';
|
charBuffer[0] = '$';
|
||||||
|
|
@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello, World!";
|
var content = "Hello, World!";
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
var expectedContent = "World";
|
var expectedContent = "World";
|
||||||
var charBuffer = new char[expectedContent.Length];
|
var charBuffer = new char[expectedContent.Length];
|
||||||
|
|
||||||
|
|
@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hi";
|
var content = "Hi";
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
var charBuffer = new char[2];
|
var charBuffer = new char[2];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hi";
|
var content = "Hi";
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
//
|
//
|
||||||
|
|
@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = string.Empty;
|
var content = string.Empty;
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.Count;
|
var actual = document.Lines.Count;
|
||||||
|
|
@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = string.Empty;
|
var content = string.Empty;
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLineLength(0);
|
var actual = document.Lines.GetLineLength(0);
|
||||||
|
|
@ -230,7 +230,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "hello\n";
|
var content = "hello\n";
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLineLength(0);
|
var actual = document.Lines.GetLineLength(0);
|
||||||
|
|
@ -244,7 +244,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "hello\r\n";
|
var content = "hello\r\n";
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLineLength(0);
|
var actual = document.Lines.GetLineLength(0);
|
||||||
|
|
@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
.Append("jumps over the lazy dog.")
|
.Append("jumps over the lazy dog.")
|
||||||
.ToString();
|
.ToString();
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = GetAllLineMappings(document);
|
var actual = GetAllLineMappings(document);
|
||||||
|
|
@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\r\nWorld!";
|
var content = "Hello\r\nWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = GetAllLineMappings(document);
|
var actual = GetAllLineMappings(document);
|
||||||
|
|
@ -293,7 +293,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\rWorld!";
|
var content = "Hello\rWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = GetAllLineMappings(document);
|
var actual = GetAllLineMappings(document);
|
||||||
|
|
@ -309,7 +309,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\rBig\r\nWorld!";
|
var content = "Hello\rBig\r\nWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = GetAllLineMappings(document);
|
var actual = GetAllLineMappings(document);
|
||||||
|
|
@ -324,7 +324,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\nWorld!";
|
var content = "Hello\nWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = GetAllLineMappings(document);
|
var actual = GetAllLineMappings(document);
|
||||||
|
|
@ -339,7 +339,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\u0085World!";
|
var content = "Hello\u0085World!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = GetAllLineMappings(document);
|
var actual = GetAllLineMappings(document);
|
||||||
|
|
@ -354,7 +354,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\u2028World!";
|
var content = "Hello\u2028World!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = GetAllLineMappings(document);
|
var actual = GetAllLineMappings(document);
|
||||||
|
|
@ -369,7 +369,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\u2029World!";
|
var content = "Hello\u2029World!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = GetAllLineMappings(document);
|
var actual = GetAllLineMappings(document);
|
||||||
|
|
@ -384,7 +384,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello, World!";
|
var content = "Hello, World!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: "Hi.cshtml");
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: "Hi.cshtml");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLocation(1);
|
var actual = document.Lines.GetLocation(1);
|
||||||
|
|
@ -402,7 +402,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\nBig\r\nWorld!";
|
var content = "Hello\nBig\r\nWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLocation(0);
|
var actual = document.Lines.GetLocation(0);
|
||||||
|
|
@ -418,7 +418,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\nBig\r\nWorld!";
|
var content = "Hello\nBig\r\nWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLocation(5);
|
var actual = document.Lines.GetLocation(5);
|
||||||
|
|
@ -434,7 +434,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\nBig\r\nWorld!";
|
var content = "Hello\nBig\r\nWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLocation(7);
|
var actual = document.Lines.GetLocation(7);
|
||||||
|
|
@ -450,7 +450,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\nBig\r\nWorld!";
|
var content = "Hello\nBig\r\nWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLocation(11);
|
var actual = document.Lines.GetLocation(11);
|
||||||
|
|
@ -466,7 +466,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = "Hello\nBig\r\nWorld!";
|
var content = "Hello\nBig\r\nWorld!";
|
||||||
|
|
||||||
var document = new StringSourceDocument(content, Encoding.UTF8, fileName: null);
|
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = document.Lines.GetLocation(16);
|
var actual = document.Lines.GetLocation(16);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
public abstract class IntegrationTestBase
|
public abstract class IntegrationTestBase
|
||||||
{
|
{
|
||||||
#if !NET46
|
#if !NET46
|
||||||
private static readonly AsyncLocal<string> _filename = new AsyncLocal<string>();
|
private static readonly AsyncLocal<string> _fileName = new AsyncLocal<string>();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected IntegrationTestBase()
|
protected IntegrationTestBase()
|
||||||
|
|
@ -40,53 +40,53 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
protected string TestProjectRoot { get; }
|
protected string TestProjectRoot { get; }
|
||||||
|
|
||||||
// Used by the test framework to set the 'base' name for test files.
|
// Used by the test framework to set the 'base' name for test files.
|
||||||
public static string Filename
|
public static string FileName
|
||||||
{
|
{
|
||||||
#if NET46
|
#if NET46
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var handle = (ObjectHandle)CallContext.LogicalGetData("IntegrationTestBase_Filename");
|
var handle = (ObjectHandle)CallContext.LogicalGetData("IntegrationTestBase_FileName");
|
||||||
return (string)handle.Unwrap();
|
return (string)handle.Unwrap();
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
CallContext.LogicalSetData("IntegrationTestBase_Filename", new ObjectHandle(value));
|
CallContext.LogicalSetData("IntegrationTestBase_FileName", new ObjectHandle(value));
|
||||||
}
|
}
|
||||||
#elif NETCOREAPP2_0
|
#elif NETCOREAPP2_0
|
||||||
get { return _filename.Value; }
|
get { return _fileName.Value; }
|
||||||
set { _filename.Value = value; }
|
set { _fileName.Value = value; }
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual RazorCodeDocument CreateCodeDocument()
|
protected virtual RazorCodeDocument CreateCodeDocument()
|
||||||
{
|
{
|
||||||
if (Filename == null)
|
if (FileName == null)
|
||||||
{
|
{
|
||||||
var message = $"{nameof(CreateCodeDocument)} should only be called from an integration test ({nameof(Filename)} is null).";
|
var message = $"{nameof(CreateCodeDocument)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||||
throw new InvalidOperationException(message);
|
throw new InvalidOperationException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
var suffixIndex = Filename.LastIndexOf("_");
|
var suffixIndex = FileName.LastIndexOf("_");
|
||||||
var normalizedFileName = suffixIndex == -1 ? Filename : Filename.Substring(0, suffixIndex);
|
var normalizedFileName = suffixIndex == -1 ? FileName : FileName.Substring(0, suffixIndex);
|
||||||
var sourceFilename = Path.ChangeExtension(normalizedFileName, ".cshtml");
|
var sourceFileName = Path.ChangeExtension(normalizedFileName, ".cshtml");
|
||||||
var testFile = TestFile.Create(sourceFilename, GetType().GetTypeInfo().Assembly);
|
var testFile = TestFile.Create(sourceFileName, GetType().GetTypeInfo().Assembly);
|
||||||
if (!testFile.Exists())
|
if (!testFile.Exists())
|
||||||
{
|
{
|
||||||
throw new XunitException($"The resource {sourceFilename} was not found.");
|
throw new XunitException($"The resource {sourceFileName} was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var source = TestRazorSourceDocument.CreateResource(sourceFilename, GetType(), normalizeNewLines: true);
|
var source = TestRazorSourceDocument.CreateResource(sourceFileName, GetType(), normalizeNewLines: true);
|
||||||
|
|
||||||
var imports = new List<RazorSourceDocument>();
|
var imports = new List<RazorSourceDocument>();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var importsFilename = Path.ChangeExtension(normalizedFileName + "_Imports" + imports.Count.ToString(), ".cshtml");
|
var importsFileName = Path.ChangeExtension(normalizedFileName + "_Imports" + imports.Count.ToString(), ".cshtml");
|
||||||
if (!TestFile.Create(importsFilename, GetType().GetTypeInfo().Assembly).Exists())
|
if (!TestFile.Create(importsFileName, GetType().GetTypeInfo().Assembly).Exists())
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
imports.Add(TestRazorSourceDocument.CreateResource(importsFilename, GetType(), normalizeNewLines: true));
|
imports.Add(TestRazorSourceDocument.CreateResource(importsFileName, GetType(), normalizeNewLines: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
OnCreatingCodeDocument(ref source, imports);
|
OnCreatingCodeDocument(ref source, imports);
|
||||||
|
|
@ -114,25 +114,25 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
|
|
||||||
protected void AssertIRMatchesBaseline(DocumentIRNode document)
|
protected void AssertIRMatchesBaseline(DocumentIRNode document)
|
||||||
{
|
{
|
||||||
if (Filename == null)
|
if (FileName == null)
|
||||||
{
|
{
|
||||||
var message = $"{nameof(AssertIRMatchesBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
var message = $"{nameof(AssertIRMatchesBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||||
throw new InvalidOperationException(message);
|
throw new InvalidOperationException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
var baselineFilename = Path.ChangeExtension(Filename, ".ir.txt");
|
var baselineFileName = Path.ChangeExtension(FileName, ".ir.txt");
|
||||||
|
|
||||||
if (GenerateBaselines)
|
if (GenerateBaselines)
|
||||||
{
|
{
|
||||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFilename);
|
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFileName);
|
||||||
File.WriteAllText(baselineFullPath, RazorIRNodeSerializer.Serialize(document));
|
File.WriteAllText(baselineFullPath, RazorIRNodeSerializer.Serialize(document));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var irFile = TestFile.Create(baselineFilename, GetType().GetTypeInfo().Assembly);
|
var irFile = TestFile.Create(baselineFileName, GetType().GetTypeInfo().Assembly);
|
||||||
if (!irFile.Exists())
|
if (!irFile.Exists())
|
||||||
{
|
{
|
||||||
throw new XunitException($"The resource {baselineFilename} was not found.");
|
throw new XunitException($"The resource {baselineFileName} was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseline = irFile.ReadAllText().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
var baseline = irFile.ReadAllText().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
@ -141,21 +141,21 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
|
|
||||||
protected void AssertCSharpDocumentMatchesBaseline(RazorCSharpDocument document)
|
protected void AssertCSharpDocumentMatchesBaseline(RazorCSharpDocument document)
|
||||||
{
|
{
|
||||||
if (Filename == null)
|
if (FileName == null)
|
||||||
{
|
{
|
||||||
var message = $"{nameof(AssertCSharpDocumentMatchesBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
var message = $"{nameof(AssertCSharpDocumentMatchesBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||||
throw new InvalidOperationException(message);
|
throw new InvalidOperationException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
var baselineFilename = Path.ChangeExtension(Filename, ".codegen.cs");
|
var baselineFileName = Path.ChangeExtension(FileName, ".codegen.cs");
|
||||||
var baselineDiagnosticsFilename = Path.ChangeExtension(Filename, ".diagnostics.txt");
|
var baselineDiagnosticsFileName = Path.ChangeExtension(FileName, ".diagnostics.txt");
|
||||||
|
|
||||||
if (GenerateBaselines)
|
if (GenerateBaselines)
|
||||||
{
|
{
|
||||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFilename);
|
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFileName);
|
||||||
File.WriteAllText(baselineFullPath, document.GeneratedCode);
|
File.WriteAllText(baselineFullPath, document.GeneratedCode);
|
||||||
|
|
||||||
var baselineDiagnosticsFullPath = Path.Combine(TestProjectRoot, baselineDiagnosticsFilename);
|
var baselineDiagnosticsFullPath = Path.Combine(TestProjectRoot, baselineDiagnosticsFileName);
|
||||||
var lines = document.Diagnostics.Select(RazorDiagnosticSerializer.Serialize).ToArray();
|
var lines = document.Diagnostics.Select(RazorDiagnosticSerializer.Serialize).ToArray();
|
||||||
if (lines.Any())
|
if (lines.Any())
|
||||||
{
|
{
|
||||||
|
|
@ -169,10 +169,10 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var codegenFile = TestFile.Create(baselineFilename, GetType().GetTypeInfo().Assembly);
|
var codegenFile = TestFile.Create(baselineFileName, GetType().GetTypeInfo().Assembly);
|
||||||
if (!codegenFile.Exists())
|
if (!codegenFile.Exists())
|
||||||
{
|
{
|
||||||
throw new XunitException($"The resource {baselineFilename} was not found.");
|
throw new XunitException($"The resource {baselineFileName} was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseline = codegenFile.ReadAllText();
|
var baseline = codegenFile.ReadAllText();
|
||||||
|
|
@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
Assert.Equal(baseline, actual);
|
Assert.Equal(baseline, actual);
|
||||||
|
|
||||||
var baselineDiagnostics = string.Empty;
|
var baselineDiagnostics = string.Empty;
|
||||||
var diagnosticsFile = TestFile.Create(baselineDiagnosticsFilename, GetType().GetTypeInfo().Assembly);
|
var diagnosticsFile = TestFile.Create(baselineDiagnosticsFileName, GetType().GetTypeInfo().Assembly);
|
||||||
if (diagnosticsFile.Exists())
|
if (diagnosticsFile.Exists())
|
||||||
{
|
{
|
||||||
baselineDiagnostics = diagnosticsFile.ReadAllText();
|
baselineDiagnostics = diagnosticsFile.ReadAllText();
|
||||||
|
|
@ -194,29 +194,29 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
|
|
||||||
protected void AssertLineMappingsMatchBaseline(RazorCodeDocument document)
|
protected void AssertLineMappingsMatchBaseline(RazorCodeDocument document)
|
||||||
{
|
{
|
||||||
if (Filename == null)
|
if (FileName == null)
|
||||||
{
|
{
|
||||||
var message = $"{nameof(AssertLineMappingsMatchBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
var message = $"{nameof(AssertLineMappingsMatchBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||||
throw new InvalidOperationException(message);
|
throw new InvalidOperationException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
var csharpDocument = document.GetCSharpDocument();
|
var csharpDocument = document.GetCSharpDocument();
|
||||||
Assert.NotNull(csharpDocument);
|
Assert.NotNull(csharpDocument);
|
||||||
|
|
||||||
var baselineFilename = Path.ChangeExtension(Filename, ".mappings.txt");
|
var baselineFileName = Path.ChangeExtension(FileName, ".mappings.txt");
|
||||||
var serializedMappings = LineMappingsSerializer.Serialize(csharpDocument, document.Source);
|
var serializedMappings = LineMappingsSerializer.Serialize(csharpDocument, document.Source);
|
||||||
|
|
||||||
if (GenerateBaselines)
|
if (GenerateBaselines)
|
||||||
{
|
{
|
||||||
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFilename);
|
var baselineFullPath = Path.Combine(TestProjectRoot, baselineFileName);
|
||||||
File.WriteAllText(baselineFullPath, serializedMappings);
|
File.WriteAllText(baselineFullPath, serializedMappings);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var testFile = TestFile.Create(baselineFilename, GetType().GetTypeInfo().Assembly);
|
var testFile = TestFile.Create(baselineFileName, GetType().GetTypeInfo().Assembly);
|
||||||
if (!testFile.Exists())
|
if (!testFile.Exists())
|
||||||
{
|
{
|
||||||
throw new XunitException($"The resource {baselineFilename} was not found.");
|
throw new XunitException($"The resource {baselineFileName} was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseline = testFile.ReadAllText();
|
var baseline = testFile.ReadAllText();
|
||||||
|
|
@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
{
|
{
|
||||||
public override void VisitClassDeclaration(ClassDeclarationIRNode node)
|
public override void VisitClassDeclaration(ClassDeclarationIRNode node)
|
||||||
{
|
{
|
||||||
node.Name = Filename.Replace('/', '_');
|
node.Name = FileName.Replace('/', '_');
|
||||||
node.AccessModifier = "public";
|
node.AccessModifier = "public";
|
||||||
|
|
||||||
VisitDefault(node);
|
VisitDefault(node);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
if (typeof(IntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo()))
|
if (typeof(IntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo()))
|
||||||
{
|
{
|
||||||
var typeName = methodUnderTest.DeclaringType.Name;
|
var typeName = methodUnderTest.DeclaringType.Name;
|
||||||
IntegrationTestBase.Filename = $"TestFiles/IntegrationTests/{typeName}/{methodUnderTest.Name}";
|
IntegrationTestBase.FileName = $"TestFiles/IntegrationTests/{typeName}/{methodUnderTest.Name}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||||
{
|
{
|
||||||
if (typeof(IntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo()))
|
if (typeof(IntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo()))
|
||||||
{
|
{
|
||||||
IntegrationTestBase.Filename = null;
|
IntegrationTestBase.FileName = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue