From 5edda078cfcbf4bd373429ad518a989277a64227 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 29 Aug 2023 07:17:31 -0600 Subject: [PATCH] Add deconstruction to FileTreeNode for cleaner tests 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. --- src/NexusMods.Paths/FileTree/FileTreeNode.cs | 12 ++++++++++++ .../FileTree/AbsoluteFileTreeTests.cs | 5 +++-- .../FileTree/RelativeFileTreeTests.cs | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/NexusMods.Paths/FileTree/FileTreeNode.cs b/src/NexusMods.Paths/FileTree/FileTreeNode.cs index 9acf4ec..7c7d834 100644 --- a/src/NexusMods.Paths/FileTree/FileTreeNode.cs +++ b/src/NexusMods.Paths/FileTree/FileTreeNode.cs @@ -189,6 +189,18 @@ public static FileTreeNode CreateTree(IEnumerable + /// Deconstructs the node into its path and value. + /// + /// + /// + public void Deconstruct(out TPath path, out TValue? value) + { + path = Path; + value = Value; + } + /// /// Populates the tree with the given collection of file entries. /// diff --git a/tests/NexusMods.Paths.Tests/FileTree/AbsoluteFileTreeTests.cs b/tests/NexusMods.Paths.Tests/FileTree/AbsoluteFileTreeTests.cs index d357147..eee4d62 100644 --- a/tests/NexusMods.Paths.Tests/FileTree/AbsoluteFileTreeTests.cs +++ b/tests/NexusMods.Paths.Tests/FileTree/AbsoluteFileTreeTests.cs @@ -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 { diff --git a/tests/NexusMods.Paths.Tests/FileTree/RelativeFileTreeTests.cs b/tests/NexusMods.Paths.Tests/FileTree/RelativeFileTreeTests.cs index 66f3464..683ac42 100644 --- a/tests/NexusMods.Paths.Tests/FileTree/RelativeFileTreeTests.cs +++ b/tests/NexusMods.Paths.Tests/FileTree/RelativeFileTreeTests.cs @@ -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 {