Skip to content

Commit 23efa11

Browse files
authored
Merge pull request #37 from Atypical-Consulting/simplify-vfspath
Remove the regex from the VFSPath class
2 parents bbe9b1f + 92850c2 commit 23efa11

File tree

6 files changed

+20
-33
lines changed

6 files changed

+20
-33
lines changed

docs/api/VFSPath.VFSPathRegex.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/api/VFSPath.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ Implements [System.IEquatable<](https://docs.microsoft.com/en-us/dotnet/api/S
2222
| :--- | :--- |
2323
| [VFSPath(string)](VFSPath.VFSPath(string).md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.VFSPath(string)') | Creates a new instance of [VFSPath](VFSPath.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath'). |
2424

25-
| Fields | |
26-
| :--- | :--- |
27-
| [VFSPathRegex](VFSPath.VFSPathRegex.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.VFSPathRegex') | Regex for matching a valid file system path. |
28-
2925
| Properties | |
3026
| :--- | :--- |
3127
| [Depth](VFSPath.Depth.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.Depth') | Gets the depth of the file system entry.<br/>The root directory has a depth of 0.<br/>The depth of a file is the depth of its parent directory plus one.<br/>The depth of a directory is the depth of its parent directory plus one. |

docs/api/VirtualFileSystem.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
- **[Path](VFSNode.Path.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSNode.Path')** `Property` Gets the creation time of the node.
103103
- **[VFSPath](VFSPath.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath')** `Class` Represents a file system entry (file or directory) in the virtual file system.
104104
- **[VFSPath(string)](VFSPath.VFSPath(string).md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.VFSPath(string)')** `Constructor` Creates a new instance of [VFSPath](VFSPath.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath').
105-
- **[VFSPathRegex](VFSPath.VFSPathRegex.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.VFSPathRegex')** `Field` Regex for matching a valid file system path.
106105
- **[Depth](VFSPath.Depth.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.Depth')** `Property` Gets the depth of the file system entry.
107106
The root directory has a depth of 0.
108107
The depth of a file is the depth of its parent directory plus one.

docs/links

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ P:Atypical.VirtualFileSystem.Core.Abstractions.VFSNode.IsFile|VFSNode.IsFile.md|
139139
M:Atypical.VirtualFileSystem.Core.Abstractions.VFSNode.#ctor(Atypical.VirtualFileSystem.Core.Abstractions.VFSPath)|VFSNode.VFSNode(VFSPath).md|VFSNode(VFSPath)
140140
N:Atypical.VirtualFileSystem.Core.Abstractions|VirtualFileSystem.md#Atypical.VirtualFileSystem.Core.Abstractions|Atypical.VirtualFileSystem.Core.Abstractions
141141
T:Atypical.VirtualFileSystem.Core.Abstractions.VFSNode|VFSNode.md|VFSNode
142-
F:Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.VFSPathRegex|VFSPath.VFSPathRegex.md|VFSPathRegex
143142
P:Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.Value|VFSPath.Value.md|Value
144143
P:Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.Parent|VFSPath.Parent.md|Parent
145144
P:Atypical.VirtualFileSystem.Core.Abstractions.VFSPath.HasParent|VFSPath.HasParent.md|HasParent

src/Atypical.VirtualFileSystem.Core/Abstractions/VFSPath.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ namespace Atypical.VirtualFileSystem.Core.Abstractions;
1111
/// </summary>
1212
public abstract record VFSPath
1313
{
14-
/// <summary>
15-
/// Regex pattern for matching a valid file system path.
16-
/// </summary>
17-
private const string VFSPathRegexPattern =
18-
@$"^{ROOT_PATH}(?<path>([a-zA-Z0-9_\-\.]+{DIRECTORY_SEPARATOR})*[a-zA-Z0-9_\-\.]+)$";
19-
20-
/// <summary>
21-
/// Regex for matching a valid file system path.
22-
/// </summary>
23-
public static readonly Regex VFSPathRegex = new(VFSPathRegexPattern, RegexOptions.Compiled);
24-
2514
/// <summary>
2615
/// Creates a new instance of <see cref="VFSPath" />.
2716
/// </summary>
@@ -31,7 +20,7 @@ public abstract record VFSPath
3120
public VFSPath(string path)
3221
{
3322
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
34-
if (path is null)
23+
if (string.IsNullOrWhiteSpace(path))
3524
ThrowArgumentHasInvalidFormat(string.Empty);
3625

3726
var vfsPath = CleanVFSPathInput(path);
@@ -46,9 +35,9 @@ public VFSPath(string path)
4635
if (vfsPath.Contains($".{DIRECTORY_SEPARATOR}"))
4736
ThrowArgumentHasRelativePathSegment(vfsPath);
4837

49-
if (!VFSPathRegex.IsMatch(vfsPath))
38+
if (vfsPath.Split(DIRECTORY_SEPARATOR + DIRECTORY_SEPARATOR).Length > 2)
5039
ThrowArgumentHasInvalidFormat(vfsPath);
51-
40+
5241
Value = vfsPath;
5342

5443
// set parent path

tests/Atypical.VirtualFileSystem.UnitTests/ValueObjects/VFSFilePathTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,24 @@ public class Constructor
1616
// - The path must not contain any relative path segments (..).
1717
// - The path must not contain any consecutive slashes (//).
1818
// - The path must not end with a slash (/).
19+
20+
[Theory]
21+
[InlineData(@"AddChild.md", @"vfs://AddChild.md")]
22+
[InlineData(@"AddChild(IDirectoryNode).md", @"vfs://AddChild(IDirectoryNode).md")]
23+
[InlineData(@"DirectoryNode.AddChild(IDirectoryNode).md", @"vfs://DirectoryNode.AddChild(IDirectoryNode).md")]
24+
[InlineData(@"api/AddChild.md", @"vfs://api/AddChild.md")]
25+
[InlineData(@"api/AddChild(IDirectoryNode).md", @"vfs://api/AddChild(IDirectoryNode).md")]
26+
[InlineData(@"api/DirectoryNode.AddChild(IDirectoryNode).md", @"vfs://api/DirectoryNode.AddChild(IDirectoryNode).md")]
27+
public void Constructor_create_instance_when_path_is_valid(string path, string expectedPath)
28+
{
29+
// Act
30+
var vfsPath = new VFSFilePath(path);
1931

32+
// Assert
33+
vfsPath.Value.Should().NotBeNull();
34+
vfsPath.Value.Should().Be(expectedPath);
35+
}
36+
2037
[Fact]
2138
public void Constructor_create_instance_when_path_is_valid_and_starts_with_dot()
2239
{

0 commit comments

Comments
 (0)