Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions TruePath.Tests/AbsolutePathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions TruePath/AbsolutePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public AbsolutePath(LocalPath localPath) : this(localPath.Value, checkAbsolutene
/// <inheritdoc cref="IPath.Parent"/>
public AbsolutePath? Parent => Underlying.Parent is { } path ? new(path.Value, checkAbsoluteness: false) : null;

/// <summary>Gets the root of this path.</summary>
public AbsolutePath PathRoot() =>
new(Path.GetPathRoot(Value)!, checkAbsoluteness: false);

/// <inheritdoc cref="IPath.Parent"/>
IPath? IPath.Parent => Parent;

Expand Down
Loading