Skip to content

Commit

Permalink
Merge pull request #13 from Nexus-Mods/deconstruct-tree-nodes
Browse files Browse the repository at this point in the history
Add deconstruction to FileTreeNode for cleaner tests
  • Loading branch information
halgari authored Aug 29, 2023
2 parents b3eda87 + 5edda07 commit 723c454
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/NexusMods.Paths/FileTree/FileTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ public static FileTreeNode<TPath, TValue> CreateTree(IEnumerable<KeyValuePair<TP
return rootNode;
}


/// <summary>
/// Deconstructs the node into its path and value.
/// </summary>
/// <param name="path"></param>
/// <param name="value"></param>
public void Deconstruct(out TPath path, out TValue? value)
{
path = Path;
value = Value;
}

/// <summary>
/// Populates the tree with the given collection of file entries.
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions tests/NexusMods.Paths.Tests/FileTree/AbsoluteFileTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public void Test_FindNode(string path, bool isUnix, bool found, int value)
if (found)
{
node.Should().NotBeNull();
node!.Path.Should().Be(CreateAbsPath(path, isUnix));
node!.Value.Should().Be(value);
var (testPath, testValue) = node!;
testPath.Should().Be(CreateAbsPath(path, isUnix));
testValue.Should().Be(value);
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions tests/NexusMods.Paths.Tests/FileTree/RelativeFileTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public void Test_FindNode(string path, bool found, int value)
if (found)
{
node.Should().NotBeNull();
node!.Path.Should().Be((RelativePath)path);
node!.Value.Should().Be(value);
var (testPath, testValue) = node!;
testPath.Should().Be((RelativePath)path);
testValue.Should().Be(value);
}
else
{
Expand Down

0 comments on commit 723c454

Please sign in to comment.