Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ModVerify.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<Folder Name="/PetroglyphTools/">
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem.Test/PG.StarWarsGame.Engine.FileSystem.Test.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/PG.StarWarsGame.Engine.FileSystem.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Engine.Test/PG.StarWarsGame.Engine.Test.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Engine.Testing/PG.StarWarsGame.Engine.Testing.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Engine/PG.StarWarsGame.Engine.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Files.ALO/PG.StarWarsGame.Files.ALO.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Files.ChunkFiles/PG.StarWarsGame.Files.ChunkFiles.csproj" />
Expand All @@ -46,4 +48,5 @@
<Project Path="src/ModVerify.CliApp/ModVerify.CliApp.csproj" />
<Project Path="src/ModVerify/ModVerify.csproj" />
<Project Path="test/ModVerify.CliApp.Test/ModVerify.CliApp.Test.csproj" />
<Project Path="test/ModVerify.Test/ModVerify.Test.csproj" />
</Solution>
4 changes: 2 additions & 2 deletions src/ModVerify.CliApp/Reporting/BaselineSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private bool TryPromptForEmbeddedBaseline(GameEngineType engineType,
? $"Apply the default baseline for engine '{engineType}' as a base? Findings already covered by it will be excluded from your new baseline."
: $"Do you want to load the default baseline for game engine '{engineType}'?";

if (!ConsoleUtilities.UserYesNoQuestion(question))
if (!ConsoleUtilities.UserYesNoQuestion(question, defaultAnswer: true))
return false;

return TryLoadEmbeddedBaseline(engineType, out baseline, out identifier);
Expand Down Expand Up @@ -197,6 +197,6 @@ private bool ShouldUseBaseline(VerificationBaseline baseline, string baselinePat
? "Use it as a base? Findings already covered by it will be excluded from your new baseline."
: "Do you want to use it?";
Console.ResetColor();
return ConsoleUtilities.UserYesNoQuestion(question);
return ConsoleUtilities.UserYesNoQuestion(question, defaultAnswer: true);
}
}
2 changes: 1 addition & 1 deletion src/ModVerify.CliApp/Updates/ModVerifyUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ await updater.CheckForUpdateAsync(branch, CancellationToken.None),

if (mode == ModVerifyUpdateMode.InteractiveUpdate)
{
var shallUpdate = ConsoleUtilities.UserYesNoQuestion("Do you want to update now?");
var shallUpdate = ConsoleUtilities.UserYesNoQuestion("Do you want to update now?", defaultAnswer: true);
if (!shallUpdate)
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/ModVerify/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("ModVerify.Test")]
1 change: 0 additions & 1 deletion src/ModVerify/Reporting/Engine/XmlParseErrorReporter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Xml;
using AET.ModVerify.Utilities;
using AET.ModVerify.Verifiers;
using Microsoft.Extensions.DependencyInjection;
Expand Down
2 changes: 1 addition & 1 deletion src/ModVerify/Verifiers/GuiDialogs/GuiDialogsVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace AET.ModVerify.Verifiers.GuiDialogs;

sealed class GuiDialogsVerifier : GameVerifier
public sealed class GuiDialogsVerifier : GameVerifier
{
internal const string DefaultComponentIdentifier = "<<DEFAULT>>";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using PG.StarWarsGame.Engine.IO;
using PG.StarWarsGame.Engine.Utilities;
using Xunit;
#if NETFRAMEWORK
Expand All @@ -10,34 +11,37 @@ namespace PG.StarWarsGame.Engine.FileSystem.Test.IO;

public partial class PetroglyphFileSystemTests
{
private static string Sep = PetroglyphFileSystem.DirectorySeparatorChar.ToString();
private static string AltSep = PetroglyphFileSystem.AltDirectorySeparatorChar.ToString();
private static string OsSep = Path.DirectorySeparatorChar.ToString();

// Mirrors TestData_JoinTwoPaths, but with CombinePath semantics: a rooted second path replaces the
// first entirely. Null cases are omitted because CombinePath throws on null (see the dedicated facts).
public static TheoryData<string, string, string> TestData_CombineTwoPaths = new()
{
{ "", "", "" },
{ Sep, "", Sep },
{ AltSep, "", AltSep },
{ "", Sep, Sep },
{ "", AltSep, AltSep },
{ Sep, Sep, Sep },
{ AltSep, AltSep, AltSep },
{ "a", "", "a" },
{ "", "a", "a" },
{ "a", "a", $"a{OsSep}a" },
{ $"a{Sep}", "a", $"a{Sep}a" },
{ "a", $"{Sep}a", $"{Sep}a" },
{ $"a{Sep}", $"{Sep}a", $"{Sep}a" },
{ "a", $"a{Sep}", $"a{OsSep}a{Sep}" },
{ $"a{AltSep}", "a", $"a{AltSep}a" },
{ "a", $"{AltSep}a", $"{AltSep}a" },
{ $"a{Sep}", $"{AltSep}a", $"{AltSep}a" },
{ $"a{AltSep}", $"{AltSep}a", $"{AltSep}a" },
{ "a", $"a{AltSep}", $"a{OsSep}a{AltSep}" }
};

[Theory]
#if Windows
[InlineData("a", "b", "a\\b")]
[InlineData("a/", "b", "a/b")]
[InlineData("a\\", "b", "a\\b")]
[InlineData("", "b", "b")]
[InlineData("a", "", "a")]
[InlineData("/", "b", "/b")]
[InlineData("a", "/b", "/b")]
[InlineData("a", "\\b", "\\b")]
[InlineData("a/b", "c/d", "a/b\\c/d")]
[InlineData("a\\b", "c\\d", "a\\b\\c\\d")]
[InlineData("a/b/", "c/d", "a/b/c/d")]
[InlineData("a\\b\\", "c\\d", "a\\b\\c\\d")]
#else
[InlineData("a", "b", "a/b")]
[InlineData("a/", "b", "a/b")]
[InlineData("a\\", "b", "a\\b")]
[InlineData("", "b", "b")]
[InlineData("a", "", "a")]
[InlineData("/", "b", "/b")]
[InlineData("a", "/b", "/b")]
[InlineData("a", "\\b", "\\b")]
[InlineData("a/b", "c/d", "a/b/c/d")]
[InlineData("a\\b", "c\\d", "a\\b/c\\d")]
[InlineData("a/b/", "c/d", "a/b/c/d")]
[InlineData("a\\b\\", "c\\d", "a\\b\\c\\d")]
#endif
[MemberData(nameof(TestData_CombineTwoPaths))]
public void CombinePath(string pathA, string pathB, string expected)
{
var result = _pgFileSystem.CombinePath(pathA, pathB);
Expand All @@ -47,31 +51,35 @@ public void CombinePath(string pathA, string pathB, string expected)
#endif
}

public static TheoryData<string?, string?, string> TestData_JoinTwoPaths = new()
{
{ "", "", "" },
{ Sep, "", Sep },
{ AltSep, "", AltSep },
{ "", Sep, Sep },
{ "", AltSep, AltSep },
{ Sep, Sep, $"{Sep}{Sep}" },
{ AltSep, AltSep, $"{AltSep}{AltSep}" },
{ "a", "", "a" },
{ "", "a", "a" },
{ "a", "a", $"a{OsSep}a" },
{ $"a{Sep}", "a", $"a{Sep}a" },
{ "a", $"{Sep}a", $"a{Sep}a" },
{ $"a{Sep}", $"{Sep}a", $"a{Sep}{Sep}a" },
{ "a", $"a{Sep}", $"a{OsSep}a{Sep}" },
{ $"a{AltSep}", "a", $"a{AltSep}a" },
{ "a", $"{AltSep}a", $"a{AltSep}a" },
{ $"a{Sep}", $"{AltSep}a", $"a{Sep}{AltSep}a" },
{ $"a{AltSep}", $"{AltSep}a", $"a{AltSep}{AltSep}a" },
{ "a", $"a{AltSep}", $"a{OsSep}a{AltSep}" },
{ null, null, ""},
{ null, "a", "a"},
{ "a", null, "a"}
};

[Theory]
#if Windows
[InlineData("a", "b", "a\\b")]
[InlineData("a/", "b", "a/b")]
[InlineData("a\\", "b", "a\\b")]
[InlineData("", "b", "b")]
[InlineData("a", "", "a")]
[InlineData("/", "b", "/b")]
[InlineData("a", "/b", "a/b")]
[InlineData("a", "\\b", "a\\b")]
[InlineData("a/b", "c/d", "a/b\\c/d")]
[InlineData("a\\b", "c\\d", "a\\b\\c\\d")]
#else
[InlineData("a", "b", "a/b")]
[InlineData("a/", "b", "a/b")]
[InlineData("a\\", "b", "a\\b")]
[InlineData("", "b", "b")]
[InlineData("a", "", "a")]
[InlineData("/", "b", "/b")]
[InlineData("a", "/b", "a/b")]
[InlineData("a", "\\b", "a\\b")]
[InlineData("a/b", "c/d", "a/b/c/d")]
[InlineData("a\\b", "c\\d", "a\\b/c\\d")]
#endif
public void JoinPath(string path1, string path2, string expected)
[MemberData(nameof(TestData_JoinTwoPaths))]
public void JoinPath(string? path1, string? path2, string expected)
{
var vsb = new ValueStringBuilder();
try
Expand All @@ -89,6 +97,54 @@ public void JoinPath(string path1, string path2, string expected)
}
}

public static TheoryData<string?, string?, string?, string> TestData_JoinThreePaths = new()
{
{ "", "", "", "" },
{ Sep, Sep, Sep, $"{Sep}{Sep}{Sep}" },
{ AltSep, AltSep, AltSep, $"{AltSep}{AltSep}{AltSep}" },
{ "a", "", "", "a" },
{ "", "a", "", "a" },
{ "", "", "a", "a" },
{ "a", "", "a", $"a{OsSep}a" },
{ "a", "a", "", $"a{OsSep}a" },
{ "", "a", "a", $"a{OsSep}a" },
{ "a", "a", "a", $"a{OsSep}a{OsSep}a" },
{ "a", Sep, "a", $"a{Sep}a" },
{ $"a{Sep}", "", "a", $"a{Sep}a" },
{ $"a{Sep}", "a", "", $"a{Sep}a" },
{ "", $"a{Sep}", "a", $"a{Sep}a" },
{ "a", "", $"{Sep}a", $"a{Sep}a" },
{ $"a{AltSep}", "", "a", $"a{AltSep}a" },
{ $"a{AltSep}", "a", "", $"a{AltSep}a" },
{ "", $"a{AltSep}", "a", $"a{AltSep}a" },
{ "a", "", $"{AltSep}a", $"a{AltSep}a" },
{ null, null, null, "" },
{ "a", null, null, "a" },
{ null, "a", null, "a" },
{ null, null, "a", "a" },
{ "a", null, "a", $"a{OsSep}a" }
};

[Theory]
[MemberData(nameof(TestData_JoinThreePaths))]
public void JoinPath_ThreePaths(string? path1, string? path2, string? path3, string expected)
{
var vsb = new ValueStringBuilder();
try
{
_pgFileSystem.JoinPath(path1.AsSpan(), path2.AsSpan(), path3.AsSpan(), ref vsb);
var result = vsb.ToString();
Assert.Equal(expected, result);
#if Windows
Assert.Equal(result, _fileSystem.Path.Join(path1, path2, path3));
#endif
}
finally
{
vsb.Dispose();
}
}

[Fact]
public void CombinePath_FirstArgNull_Throws()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="AnakinRaW.CommonUtilities.Testing" Version="13.0.23" />
<PackageReference Include="GitHubActionsTestLogger" Version="3.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.2" />
<PackageReference Include="Microsoft.Testing.Platform" Version="2.2.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public string CombinePath(string pathA, string pathB)
throw new ArgumentNullException(nameof(pathB));
return CombineInternal(pathA, pathB);
}

internal void JoinPath(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ref ValueStringBuilder stringBuilder)
{
if (path1.Length == 0 && path2.Length == 0)
Expand All @@ -59,7 +59,44 @@ internal void JoinPath(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ref V

stringBuilder.Append(path2);
}


internal void JoinPath(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, ref ValueStringBuilder stringBuilder)
{
if (path1.IsEmpty)
{
JoinPath(path2, path3, ref stringBuilder);
return;
}

if (path2.IsEmpty)
{
JoinPath(path1, path3, ref stringBuilder);
return;
}

if (path3.IsEmpty)
{
JoinPath(path1, path2, ref stringBuilder);
return;
}

stringBuilder.Append(path1);

var firstHasSeparator = IsDirectorySeparator(path1[path1.Length - 1]) || IsDirectorySeparator(path2[0]);
var secondHasSeparator = IsDirectorySeparator(path2[path2.Length - 1]) || IsDirectorySeparator(path3[0]);

if (!firstHasSeparator)
stringBuilder.Append(UnderlyingFileSystem.Path.DirectorySeparatorChar);

stringBuilder.Append(path2);

if (!secondHasSeparator)
stringBuilder.Append(UnderlyingFileSystem.Path.DirectorySeparatorChar);

stringBuilder.Append(path3);
}


private string CombineInternal(string first, string second)
{
if (string.IsNullOrEmpty(first))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace PG.StarWarsGame.Engine.IO;
/// </remarks>
public sealed partial class PetroglyphFileSystem
{
private const char DirectorySeparatorChar = '/';
private const char AltDirectorySeparatorChar = '\\';
internal const char DirectorySeparatorChar = '/';
internal const char AltDirectorySeparatorChar = '\\';

// ReSharper disable once InconsistentNaming
private static readonly PathNormalizeOptions PGFileSystemDirectorySeparatorNormalizeOptions = new()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using PG.StarWarsGame.Engine.IO;
using PG.StarWarsGame.Engine.Testing;

namespace PG.StarWarsGame.Engine.Test;

/// <summary>
/// A test fixture for verifying that repositories resolve requests in a case-insensitive manner.
/// </summary>
/// <param name="PopulateGame">Callback that writes fixtures into the virtual game's <c>ConfigureGame</c> origin.</param>
/// <param name="SelectRepository">Picks the repository facet under test from the constructed <see cref="IGameRepository"/>.</param>
/// <param name="FilesystemLookup">Lookup key the repository should resolve to the filesystem-backed fixture.</param>
/// <param name="FilesystemContent">Expected content at <paramref name="FilesystemLookup"/>.</param>
/// <param name="MegLookup">Lookup key the repository should resolve to the MEG-backed fixture.</param>
/// <param name="MegContent">Expected content at <paramref name="MegLookup"/>.</param>
public sealed record CaseInsensitivityFixture(
Action<IRepoOriginWriter> PopulateGame,
Func<IGameRepository, IRepository> SelectRepository,
string FilesystemLookup,
string FilesystemContent,
string MegLookup,
string MegContent);
Loading
Loading