diff --git a/TruePath.Tests/AbsolutePathTests.cs b/TruePath.Tests/AbsolutePathTests.cs
index c7f784e..e0efe21 100644
--- a/TruePath.Tests/AbsolutePathTests.cs
+++ b/TruePath.Tests/AbsolutePathTests.cs
@@ -16,6 +16,23 @@ public void ConstructionTest()
Assert.Equal($"{root}...", path.Value);
}
+ [Fact]
+ public void PathRootReturnsRoot()
+ {
+ var root = new AbsolutePath(OperatingSystem.IsWindows() ? @"A:\" : "/");
+ var path = root / "foo" / "bar";
+
+ Assert.Equal(root, path.PathRoot());
+ }
+
+ [Fact]
+ public void PathRootOfRootReturnsItself()
+ {
+ var root = new AbsolutePath(OperatingSystem.IsWindows() ? @"A:\" : "/");
+
+ Assert.Equal(root, root.PathRoot());
+ }
+
[Fact]
public void ReadKind_NonExistent()
{
diff --git a/TruePath/AbsolutePath.cs b/TruePath/AbsolutePath.cs
index 23ed853..79f306d 100644
--- a/TruePath/AbsolutePath.cs
+++ b/TruePath/AbsolutePath.cs
@@ -74,6 +74,10 @@ public AbsolutePath(LocalPath localPath) : this(localPath.Value, checkAbsolutene
///
public AbsolutePath? Parent => Underlying.Parent is { } path ? new(path.Value, checkAbsoluteness: false) : null;
+ /// Gets the root of this path.
+ public AbsolutePath PathRoot() =>
+ new(Path.GetPathRoot(Value)!, checkAbsoluteness: false);
+
///
IPath? IPath.Parent => Parent;