Skip to content

Commit

Permalink
Nullable annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred committed Oct 8, 2024
1 parent 3450d02 commit 8704d08
Showing 1 changed file with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -85,15 +83,15 @@ public RazorIntegrationTestBase()
/// Gets a hardcoded document kind to be added to each code document that's created. This can
/// be used to generate components.
/// </summary>
internal virtual string FileKind { get; }
internal virtual string? FileKind { get; }

internal virtual VirtualRazorProjectFileSystem FileSystem { get; }

// Used to force a specific style of line-endings for testing. This matters
// for the baseline tests that exercise line mappings. Even though we normalize
// newlines for testing, the difference between platforms affects the data through
// the *count* of characters written.
internal virtual string LineEnding { get; }
internal virtual string? LineEnding { get; }

internal virtual string PathSeparator { get; }

Expand All @@ -104,7 +102,7 @@ public RazorIntegrationTestBase()
internal virtual string WorkingDirectory { get; }

// intentionally private - we don't want individual tests messing with the project engine
private RazorProjectEngine CreateProjectEngine(RazorConfiguration configuration, MetadataReference[] references, bool supportLocalizedComponentNames, CSharpParseOptions csharpParseOptions)
private RazorProjectEngine CreateProjectEngine(RazorConfiguration configuration, MetadataReference[] references, bool supportLocalizedComponentNames, CSharpParseOptions? csharpParseOptions)
{
return RazorProjectEngine.Create(configuration, FileSystem, b =>
{
Expand Down Expand Up @@ -140,7 +138,7 @@ private RazorProjectEngine CreateProjectEngine(RazorConfiguration configuration,
});
}

internal RazorProjectItem CreateProjectItem(string cshtmlRelativePath, string cshtmlContent, string fileKind = null, string cssScope = null)
internal RazorProjectItem CreateProjectItem(string cshtmlRelativePath, string cshtmlContent, string? fileKind = null, string? cssScope = null)
{
var fullPath = WorkingDirectory + PathSeparator + cshtmlRelativePath;

Expand Down Expand Up @@ -178,12 +176,12 @@ protected CompileToCSharpResult CompileToCSharp(string cshtmlContent, params Dia

protected CompileToCSharpResult CompileToCSharp(
string cshtmlContent,
string cssScope = null,
string? cssScope = null,
bool supportLocalizedComponentNames = false,
bool nullableEnable = false,
RazorConfiguration configuration = null,
CSharpCompilation baseCompilation = null,
CSharpParseOptions csharpParseOptions = null,
RazorConfiguration? configuration = null,
CSharpCompilation? baseCompilation = null,
CSharpParseOptions? csharpParseOptions = null,
params DiagnosticDescription[] expectedCSharpDiagnostics)
{
return CompileToCSharp(
Expand All @@ -201,13 +199,13 @@ protected CompileToCSharpResult CompileToCSharp(
protected CompileToCSharpResult CompileToCSharp(
string cshtmlRelativePath,
string cshtmlContent,
string fileKind = null,
string cssScope = null,
string? fileKind = null,
string? cssScope = null,
bool supportLocalizedComponentNames = false,
bool nullableEnable = false,
RazorConfiguration configuration = null,
CSharpCompilation baseCompilation = null,
CSharpParseOptions csharpParseOptions = null,
RazorConfiguration? configuration = null,
CSharpCompilation? baseCompilation = null,
CSharpParseOptions? csharpParseOptions = null,
params DiagnosticDescription[] expectedCSharpDiagnostics)
{
if (DeclarationOnly && DesignTime)
Expand Down Expand Up @@ -393,7 +391,7 @@ protected INamedTypeSymbol CompileToComponent(CompileToAssemblyResult assemblyRe
return componentType;
}

protected static CSharpSyntaxTree Parse(string text, CSharpParseOptions? parseOptions = null, string path = null)
protected static CSharpSyntaxTree Parse(string text, CSharpParseOptions? parseOptions = null, string path = "")
{
return (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(text, parseOptions ?? CSharpParseOptions, path: path);
}
Expand All @@ -403,7 +401,7 @@ protected static void AssertSourceEquals(string expected, CompileToCSharpResult
// Normalize the paths inside the expected result to match the OS paths
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var windowsPath = Path.Combine(ArbitraryWindowsPath, generated.CodeDocument.Source.RelativePath).Replace('/', '\\');
var windowsPath = Path.Combine(ArbitraryWindowsPath, generated.CodeDocument.Source.RelativePath ?? "").Replace('/', '\\');
expected = expected.Replace(windowsPath, generated.CodeDocument.Source.FilePath);
}

Expand All @@ -414,18 +412,18 @@ protected static void AssertSourceEquals(string expected, CompileToCSharpResult
protected class CompileToCSharpResult
{
// A compilation that can be used *with* this code to compile an assembly
public Compilation BaseCompilation { get; set; }
public RazorCodeDocument CodeDocument { get; set; }
public string Code { get; set; }
public IEnumerable<RazorDiagnostic> RazorDiagnostics { get; set; }
public CSharpParseOptions ParseOptions { get; set; }
public required Compilation BaseCompilation { get; set; }
public required RazorCodeDocument CodeDocument { get; set; }
public required string Code { get; set; }
public required IEnumerable<RazorDiagnostic> RazorDiagnostics { get; set; }
public CSharpParseOptions? ParseOptions { get; set; }
}

protected class CompileToAssemblyResult
{
public Compilation Compilation { get; set; }
public string VerboseLog { get; set; }
public IEnumerable<Diagnostic> CSharpDiagnostics { get; set; }
public required Compilation Compilation { get; set; }
public string? VerboseLog { get; set; }
public required IEnumerable<Diagnostic> CSharpDiagnostics { get; set; }
}

private class CompilationFailedException : XunitException
Expand Down Expand Up @@ -480,7 +478,7 @@ private class SuppressChecksum : IConfigureRazorCodeGenerationOptionsFeature
{
public int Order => 0;

public RazorEngine Engine { get; set; }
public RazorEngine? Engine { get; set; }

public void Configure(RazorCodeGenerationOptionsBuilder options)
{
Expand All @@ -492,7 +490,7 @@ private class SupportLocalizedComponentNames : IConfigureRazorCodeGenerationOpti
{
public int Order => 0;

public RazorEngine Engine { get; set; }
public RazorEngine? Engine { get; set; }

public void Configure(RazorCodeGenerationOptionsBuilder options)
{
Expand All @@ -512,7 +510,7 @@ public ForceLineEndingPhase(string lineEnding)
protected override void ExecuteCore(RazorCodeDocument codeDocument)
{
var field = typeof(CodeRenderingContext).GetField("NewLineString", BindingFlags.Static | BindingFlags.NonPublic);
var key = field.GetValue(null);
var key = field!.GetValue(null);
codeDocument.Items[key] = LineEnding;
}
}
Expand All @@ -526,7 +524,7 @@ public TestImportProjectFeature(List<RazorProjectItem> imports)
_imports = imports;
}

public RazorProjectEngine ProjectEngine { get; set; }
public RazorProjectEngine? ProjectEngine { get; set; }

public IReadOnlyList<RazorProjectItem> GetImports(RazorProjectItem projectItem)
{
Expand Down

0 comments on commit 8704d08

Please sign in to comment.