Skip to content

Commit

Permalink
add - Added full nullable support (pt. 1)
Browse files Browse the repository at this point in the history
---

We've added full nullable support to the entire Nitrocid API, fixing some bugs in the process. However, this is not complete, so build will fail.

---

Type: add
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 5, 2024
1 parent 3fe9031 commit f857bbe
Show file tree
Hide file tree
Showing 519 changed files with 3,233 additions and 4,246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Nitrocid.Analyzers.Test.Verifiers;
using System;

namespace Nitrocid.Analyzers.Test
{
Expand All @@ -33,7 +34,8 @@ public Test()
{
SolutionTransforms.Add((solution, projectId) =>
{
var compilationOptions = solution.GetProject(projectId).CompilationOptions;
var compilationOptions = solution.GetProject(projectId)?.CompilationOptions ??
throw new Exception("Can't get compilation options.");
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(
compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings));
solution = solution.WithProjectCompilationOptions(projectId, compilationOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Nitrocid.Analyzers.Test.Verifiers;
using System;

namespace Nitrocid.Analyzers.Test
{
Expand All @@ -35,7 +36,8 @@ public Test()
{
SolutionTransforms.Add((solution, projectId) =>
{
var compilationOptions = solution.GetProject(projectId).CompilationOptions;
var compilationOptions = solution.GetProject(projectId)?.CompilationOptions ??
throw new Exception("Can't get compilation options.");
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(
compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings));
solution = solution.WithProjectCompilationOptions(projectId, compilationOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Nitrocid.Analyzers.Test.Verifiers;
using System;

namespace Nitrocid.Analyzers.Test
{
Expand All @@ -33,7 +34,8 @@ public Test()
{
SolutionTransforms.Add((solution, projectId) =>
{
var compilationOptions = solution.GetProject(projectId).CompilationOptions;
var compilationOptions = solution.GetProject(projectId)?.CompilationOptions ??
throw new Exception("Can't get compilation options.");
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(
compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings));
solution = solution.WithProjectCompilationOptions(projectId, compilationOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ namespace Nitrocid.Generators.KnownAddons
internal class KnownAddonInfo
{
[JsonProperty("name")]
public string Name { get; set; }
public string Name { get; set; } = "";

[JsonProperty("display")]
public string Display { get; set; }
public string Display { get; set; } = "";

[JsonProperty("project")]
public string Project { get; set; }
public string Project { get; set; } = "";
}

}
10 changes: 5 additions & 5 deletions private/Nitrocid.Tests/Arguments/ArgumentInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Nitrocid.Tests.Arguments
[TestClass]
public class ArgumentInfoTests
{
private static ArgumentExecutor ArgumentInstance;
private static ArgumentExecutor? ArgumentInstance;

/// <summary>
/// Tests initializing ArgumentInfo instance from a command line argument
Expand Down Expand Up @@ -75,7 +75,7 @@ public void TestInitializeArgumentFromBase()
public void TestInitializedArgumentExecution()
{
var parameters = new ArgumentParameters("", [], "", [], [], "test");
Should.NotThrow(new Action(() => ArgumentInstance.Execute(parameters)));
Should.NotThrow(new Action(() => ArgumentInstance?.Execute(parameters)));
}

/// <summary>
Expand All @@ -86,7 +86,7 @@ public void TestInitializedArgumentExecution()
public void TestInitializedArgumentExecutionWithArguments()
{
var parameters = new ArgumentParameters("Hello World", ["Hello", "World"], "Hello World", ["Hello", "World"], [], "test");
Should.NotThrow(new Action(() => ArgumentInstance.Execute(parameters)));
Should.NotThrow(new Action(() => ArgumentInstance?.Execute(parameters)));
}

/// <summary>
Expand All @@ -97,7 +97,7 @@ public void TestInitializedArgumentExecutionWithArguments()
public void TestInitializedArgumentExecutionWithSwitches()
{
var parameters = new ArgumentParameters("", [], "-s", [], ["-s"], "test");
Should.NotThrow(new Action(() => ArgumentInstance.Execute(parameters)));
Should.NotThrow(new Action(() => ArgumentInstance?.Execute(parameters)));
}

/// <summary>
Expand All @@ -108,7 +108,7 @@ public void TestInitializedArgumentExecutionWithSwitches()
public void TestInitializedArgumentExecutionWithArgumentsAndSwitches()
{
var parameters = new ArgumentParameters("Hello!", ["Hello!"], "-s Hello!", ["Hello!"], ["-s"], "test");
Should.NotThrow(new Action(() => ArgumentInstance.Execute(parameters)));
Should.NotThrow(new Action(() => ArgumentInstance?.Execute(parameters)));
}
}
}
24 changes: 12 additions & 12 deletions private/Nitrocid.Tests/Drivers/RegexpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void TestIsMatch(string text, string pattern, bool expected)
[Description("Action")]
public void TestMatch(string text, string pattern)
{
Match match = default;
Match? match = default;
Should.NotThrow(() => match = RegexpTools.Match(text, pattern));
}

Expand All @@ -73,7 +73,7 @@ public void TestMatch(string text, string pattern)
[Description("Action")]
public void TestMatchInvalid(string text, string pattern)
{
Match match = default;
Match? match = default;
Should.Throw(() => match = RegexpTools.Match(text, pattern), typeof(KernelException));
}

Expand All @@ -86,7 +86,7 @@ public void TestMatchInvalid(string text, string pattern)
[Description("Action")]
public void TestMatches(string text, string pattern)
{
MatchCollection match = default;
MatchCollection? match = default;
Should.NotThrow(() => match = RegexpTools.Matches(text, pattern));
}

Expand All @@ -97,7 +97,7 @@ public void TestMatches(string text, string pattern)
[Description("Action")]
public void TestMatchesInvalid(string text, string pattern)
{
MatchCollection match = default;
MatchCollection? match = default;
Should.Throw(() => match = RegexpTools.Matches(text, pattern), typeof(KernelException));
}

Expand All @@ -110,7 +110,7 @@ public void TestMatchesInvalid(string text, string pattern)
[Description("Action")]
public void TestFilter(string text, string pattern, string expected)
{
string filtered = default;
string? filtered = default;
Should.NotThrow(() => filtered = RegexpTools.Filter(text, pattern));
filtered.ShouldBe(expected);
}
Expand All @@ -122,7 +122,7 @@ public void TestFilter(string text, string pattern, string expected)
[Description("Action")]
public void TestFilterInvalid(string text, string pattern)
{
string filtered = default;
string? filtered = default;
Should.Throw(() => filtered = RegexpTools.Filter(text, pattern), typeof(KernelException));
}

Expand All @@ -135,7 +135,7 @@ public void TestFilterInvalid(string text, string pattern)
[Description("Action")]
public void TestFilter(string text, string pattern, string replaceWith, string expected)
{
string filtered = default;
string? filtered = default;
Should.NotThrow(() => filtered = RegexpTools.Filter(text, pattern, replaceWith));
filtered.ShouldBe(expected);
}
Expand All @@ -147,7 +147,7 @@ public void TestFilter(string text, string pattern, string replaceWith, string e
[Description("Action")]
public void TestFilterInvalid(string text, string pattern, string replaceWith)
{
string filtered = default;
string? filtered = default;
Should.Throw(() => filtered = RegexpTools.Filter(text, pattern, replaceWith), typeof(KernelException));
}

Expand All @@ -160,7 +160,7 @@ public void TestFilterInvalid(string text, string pattern, string replaceWith)
[Description("Action")]
public void TestSplit(string text, string pattern, string[] expected)
{
string[] split = default;
string[]? split = default;
Should.NotThrow(() => split = RegexpTools.Split(text, pattern));
split.ShouldBe(expected);
}
Expand All @@ -172,7 +172,7 @@ public void TestSplit(string text, string pattern, string[] expected)
[Description("Action")]
public void TestSplitInvalid(string text, string pattern)
{
string[] split = default;
string[]? split = default;
Should.Throw(() => split = RegexpTools.Split(text, pattern), typeof(KernelException));
}

Expand All @@ -194,7 +194,7 @@ public void TestSplitInvalid(string text, string pattern)
[Description("Action")]
public void TestEscape(string text, string expected)
{
string final = default;
string? final = default;
Should.NotThrow(() => final = RegexpTools.Escape(text));
final.ShouldBe(expected);
}
Expand All @@ -217,7 +217,7 @@ public void TestEscape(string text, string expected)
[Description("Action")]
public void TestUnescape(string text, string expected)
{
string final = default;
string? final = default;
Should.NotThrow(() => final = RegexpTools.Unescape(text));
final.ShouldBe(expected);
}
Expand Down
8 changes: 4 additions & 4 deletions private/Nitrocid.Tests/Kernel/Debugging/DebugAssertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void TestAssertNullFailing()
{
DriverHandler.RegisterDriver(DriverTypes.Console, new MyCustomConsoleDriver());
DriverHandler.SetDriver<IConsoleDriver>("MyCustom");
Should.Throw(() => DebugCheck.AssertNull<string[]>(null), typeof(KernelException));
Should.Throw(() => DebugCheck.AssertNull<string[]?>(null), typeof(KernelException));
}

/// <summary>
Expand All @@ -150,7 +150,7 @@ public void TestAssertNullMessageFailing()
{
DriverHandler.RegisterDriver(DriverTypes.Console, new MyCustomConsoleDriver());
DriverHandler.SetDriver<IConsoleDriver>("MyCustom");
Should.Throw(() => DebugCheck.AssertNull<string[]>(null, "Always false"), typeof(KernelException));
Should.Throw(() => DebugCheck.AssertNull<string[]?>(null, "Always false"), typeof(KernelException));
}

/// <summary>
Expand All @@ -159,7 +159,7 @@ public void TestAssertNullMessageFailing()
[TestMethod]
[Description("Misc")]
public void TestAssertNotNull() =>
Should.NotThrow(() => DebugCheck.AssertNotNull<string[]>(null));
Should.NotThrow(() => DebugCheck.AssertNotNull<string[]?>(null));

/// <summary>
/// Tests assertion...
Expand All @@ -179,7 +179,7 @@ public void TestAssertNotNullFailing()
[TestMethod]
[Description("Misc")]
public void TestAssertNotNullMessage() =>
Should.NotThrow(() => DebugCheck.AssertNotNull<string[]>(null, "Always true"));
Should.NotThrow(() => DebugCheck.AssertNotNull<string[]?>(null, "Always true"));

/// <summary>
/// Tests assertion...
Expand Down
Loading

0 comments on commit f857bbe

Please sign in to comment.