Skip to content

Commit

Permalink
Add deconstruction to FileTreeNode for cleaner tests
Browse files Browse the repository at this point in the history
Updated FileTreeNode class to include Deconstruct method, enabling more readable testing of path and value. Changes have been applied to both Absolute and Relative FileTreeTests. Deconstruction simplifies asserting equalities and improves overall code readability in tests.
  • Loading branch information
halgari committed Aug 29, 2023
1 parent b3eda87 commit 5edda07
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 5edda07

Please sign in to comment.