public static Result VerifyHostPath(U8Span path) { if (path.IsEmpty()) { return(Result.Success); } if (path[0] != StringTraits.DirectorySeparator) { return(ResultFs.InvalidPathFormat.Log()); } U8Span path2 = path.Slice(1); if (path2.IsEmpty()) { return(Result.Success); } int skipLength = WindowsPath.GetWindowsPathSkipLength(path2); int remainingLength = PathTools.MaxPathLength - skipLength; Result rc = PathUtility.VerifyPath(null, path2.Slice(skipLength), remainingLength, remainingLength); if (rc.IsFailure()) { return(rc); } using var normalizer = new PathNormalizer(path, PathNormalizer.Option.PreserveUnc); return(normalizer.Result); }
public static void Normalize_MountNameOptionOn_ParsesMountName() { using var normalizer = new PathNormalizer("mount:/a/./b".ToU8Span(), PathNormalizer.Option.HasMountName); Assert.Equal(Result.Success, normalizer.Result); Assert.Equal("mount:/a/b", normalizer.Path.ToString()); }
public static void Normalize_PreserveUncOptionOff_DoesNotPreserveUncPath() { using var normalizer = new PathNormalizer("//aa/bb/..".ToU8Span(), PathNormalizer.Option.None); Assert.Equal(Result.Success, normalizer.Result); Assert.Equal(@"/aa", normalizer.Path.ToString()); }
public static void Normalize_PreserveUncOptionOn_PreservesUncPath() { using var normalizer = new PathNormalizer("//aa/bb/..".ToU8Span(), PathNormalizer.Option.PreserveUnc); Assert.Equal(Result.Success, normalizer.Result); Assert.Equal(@"\\aa/bb", normalizer.Path.ToString()); }
public static void Normalize_PreserveTailSeparatorOption_IgnoresMissingTailSeparator() { using var normalizer = new PathNormalizer("/a/./b".ToU8Span(), PathNormalizer.Option.PreserveTrailingSeparator); Assert.Equal(Result.Success, normalizer.Result); Assert.Equal("/a/b", normalizer.Path.ToString()); }
public static void Ctor_EmptyPathWithAcceptEmptyOption_ReturnsEmptyPathWithSuccess() { using var normalizer = new PathNormalizer("".ToU8Span(), PathNormalizer.Option.AcceptEmpty); Assert.Equal(Result.Success, normalizer.Result); Assert.True(normalizer.Path.IsEmpty()); }
public static void Normalize_PathAlreadyNormalized_ReturnsSameBuffer() { var originalPath = "/a/b".ToU8Span(); using var normalizer = new PathNormalizer(originalPath, PathNormalizer.Option.PreserveTrailingSeparator); Assert.Equal(Result.Success, normalizer.Result); // Compares addresses and lengths of the buffers Assert.True(originalPath.Value == normalizer.Path.Value); }
public static void Normalize_MountNameOptionOff_DoesNotParseMountName() { using var normalizer = new PathNormalizer("mount:/a/./b".ToU8Span(), PathNormalizer.Option.None); Assert.Equal(ResultFs.InvalidPathFormat.Value, normalizer.Result); }