Fix bug affecting nested bundle paths

* Resolves #1419
This commit is contained in:
ds5678 2024-08-09 21:54:55 -07:00
parent a5cd6d3ad6
commit 4c41bc27ca
5 changed files with 72 additions and 2 deletions

View File

@ -159,6 +159,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssetRipper.GUI.Web", "Sour
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssetRipper.Export.Modules.Models", "Source\AssetRipper.Export.Modules.Models\AssetRipper.Export.Modules.Models.csproj", "{B827502A-EA76-4C16-B246-0E625A7ED80E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssetRipper.Export.Modules.Models", "Source\AssetRipper.Export.Modules.Models\AssetRipper.Export.Modules.Models.csproj", "{B827502A-EA76-4C16-B246-0E625A7ED80E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssetRipper.GUI.Web.Tests", "Source\AssetRipper.GUI.Web.Tests\AssetRipper.GUI.Web.Tests.csproj", "{9EDD3621-6E2B-41AD-8F6A-F8C4CD113566}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -337,6 +339,10 @@ Global
{B827502A-EA76-4C16-B246-0E625A7ED80E}.Debug|Any CPU.Build.0 = Debug|Any CPU {B827502A-EA76-4C16-B246-0E625A7ED80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B827502A-EA76-4C16-B246-0E625A7ED80E}.Release|Any CPU.ActiveCfg = Release|Any CPU {B827502A-EA76-4C16-B246-0E625A7ED80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B827502A-EA76-4C16-B246-0E625A7ED80E}.Release|Any CPU.Build.0 = Release|Any CPU {B827502A-EA76-4C16-B246-0E625A7ED80E}.Release|Any CPU.Build.0 = Release|Any CPU
{9EDD3621-6E2B-41AD-8F6A-F8C4CD113566}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9EDD3621-6E2B-41AD-8F6A-F8C4CD113566}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EDD3621-6E2B-41AD-8F6A-F8C4CD113566}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EDD3621-6E2B-41AD-8F6A-F8C4CD113566}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<OutputPath>..\0Bins\Other\AssetRipper.GUI.Web.Tests\$(Configuration)\</OutputPath>
<IntermediateOutputPath>..\0Bins\obj\AssetRipper.GUI.Web.Tests\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AssetRipper.GUI.Web\AssetRipper.GUI.Web.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,35 @@
using AssetRipper.GUI.Web.Paths;
namespace AssetRipper.GUI.Web.Tests;
public class BundlePathTests
{
[Test]
public void DefaultBundlePathIsRoot()
{
BundlePath path = default;
Assert.That(path.IsRoot);
}
[Test]
public void BundlePathParentWithDepthOneIsRoot()
{
BundlePath path = new([0]);
Assert.That(path.Parent.IsRoot);
}
[Test]
public void BundlePathParentWithDepthTwoIsNotRoot()
{
BundlePath path = new([0,0]);
Assert.That(path.Parent.IsRoot, Is.False);
}
[Test]
public void ParentHasCorrectPath()
{
BundlePath path = new([1, 2, 3]);
BundlePath parent = path.Parent;
Assert.That(parent.Path.ToArray(), Is.EquivalentTo((int[])[1, 2]));
}
}

View File

@ -0,0 +1,2 @@
global using NUnit.Framework;
global using System;

View File

@ -39,14 +39,14 @@ public readonly record struct BundlePath : IPath<BundlePath>
/// If <see cref="IsRoot"/>, then this will return <see langword="default"/>. /// If <see cref="IsRoot"/>, then this will return <see langword="default"/>.
/// </remarks> /// </remarks>
[JsonIgnore] [JsonIgnore]
public BundlePath Parent => Depth > 1 ? new BundlePath(Path.Span[..^-1]) : default; public BundlePath Parent => Depth > 1 ? new BundlePath(Path.Span[..^1]) : default;
public BundlePath GetChild(int index) public BundlePath GetChild(int index)
{ {
int[] path; int[] path;
if (_path is null) if (_path is null)
{ {
path = new int[1] { index }; path = [index];
} }
else else
{ {