Beispiel #1
0
 public LocalRoot(Uri rootUri, FileSystemCasing casing)
 {
     if (rootUri == null)
     {
         throw new ArgumentNullException(nameof(rootUri));
     }
     if (!rootUri.IsAbsoluteUri)
     {
         throw new ArgumentException($"Not an absolute path: {rootUri.LocalPath}", nameof(rootUri));
     }
     if (!PathUtils.IsDirectoryUri(rootUri))
     {
         throw new ArgumentException($"Not a directory path: {rootUri.LocalPath}", nameof(rootUri));
     }
     if (!Enum.IsDefined(typeof(FileSystemCasing), casing))
     {
         throw new InvalidEnumArgumentException(nameof(casing), (int)casing, typeof(FileSystemCasing));
     }
     if (casing == FileSystemCasing.Unspecified)
     {
         throw new ArgumentException($"Must specify casing rule for path {rootUri}", nameof(casing));
     }
     RootUri = rootUri;
     Casing  = casing;
 }
Beispiel #2
0
        public Regex CompileRegex(string globPattern, FileSystemCasing casing)
        {
            var normalisedGlobPattern = SquashDirectorySeparators(globPattern);
            var regexPattern          = new Internal().Compile(normalisedGlobPattern);

            return(FileSystemRegexHelpers.CreateRegex(regexPattern, casing));
        }
        public void QualifiedPathsWithDifferentRoots_AreNotEqual([ValueSource(nameof(ValidFileSystemCasings))] FileSystemCasing casing)
        {
            var relativePath = RelativePath.CreateFromSegments("a", "b", "c");
            var a            = new QualifiedPath(new LocalRoot(new Uri(@"C:\"), casing), relativePath);
            var b            = new QualifiedPath(new LocalRoot(new Uri(@"E:\"), casing), relativePath);

            Assert.That(a, Is.Not.EqualTo(b).Using(default(QualifiedPath.DefaultEqualityComparer)));
        }
 public LocalRoot CreateNode(string absolutePath, FileSystemCasing casing)
 {
     if (!Path.IsPathRooted(absolutePath))
     {
         throw new ArgumentException($"Not an absolute path: {absolutePath}", nameof(absolutePath));
     }
     return(fileSystemApi.CreateStorageRoot(absolutePath.AsDirectoryPath(), casing));
 }
        public void PathIsContainedByParent([ValueSource(nameof(ValidFileSystemCasings))] FileSystemCasing casing)
        {
            var comparer   = new PathEqualityComparer(casing);
            var path       = RelativePath.CreateFromSegments("a", "b", "c");
            var parentPath = RelativePath.CreateFromSegments("a", "b").AsContainer();

            Assert.That(parentPath.Contains(path, comparer), Is.True);
        }
        public void PathIsEqualToIdenticalCasePath([ValueSource(nameof(ValidFileSystemCasings))] FileSystemCasing casing)
        {
            var comparer = new PathEqualityComparer(casing);
            var pathA    = RelativePath.CreateFromSegments("a", "b", "c");
            var pathB    = RelativePath.CreateFromSegments("a", "b", "c");

            Assert.That(pathA, Is.EqualTo(pathB).Using <RelativePath>(comparer));
        }
        public void PathDoesNotContainSibling([ValueSource(nameof(ValidFileSystemCasings))] FileSystemCasing casing)
        {
            var comparer    = new PathEqualityComparer(casing);
            var path        = RelativePath.CreateFromSegments("a", "b", "c");
            var siblingPath = RelativePath.CreateFromSegments("a", "b", "d");

            Assert.That(path.Contains(siblingPath, comparer), Is.False);
            Assert.That(path.AsContainer().Contains(siblingPath, comparer), Is.False);
        }
Beispiel #8
0
        public LocalRoot CreateStorageRoot(string absoluteFileSystemPath, FileSystemCasing casing)
        {
            if (!PathUtils.IsNormalisedAbsolutePath(absoluteFileSystemPath))
            {
                throw new ArgumentException($"Not a valid absolute path: {absoluteFileSystemPath}", nameof(absoluteFileSystemPath));
            }
            var canonicalUri = new Uri(absoluteFileSystemPath);

            return(new LocalRoot(canonicalUri, casing == FileSystemCasing.Unspecified ? GetCasingRules(absoluteFileSystemPath) : casing));
        }
        public static Regex CreateRegex(string regex, FileSystemCasing casing)
        {
            var options = RegexOptions.Compiled;

            if (casing == FileSystemCasing.CasePreservingInsensitive)
            {
                options |= RegexOptions.IgnoreCase;
            }
            return(new Regex(regex, options));
        }
Beispiel #10
0
        private static StringComparer SelectComparer(FileSystemCasing casing)
        {
            switch (casing)
            {
            case FileSystemCasing.Unspecified: throw new ArgumentException("Cannot compare paths when the casing rules are not known.");

            case FileSystemCasing.CaseSensitive: return(StringComparer.Ordinal);

            case FileSystemCasing.CasePreservingInsensitive: return(StringComparer.OrdinalIgnoreCase);

            default: throw new ArgumentOutOfRangeException(nameof(casing), casing, null);
            }
        }
        public Regex CompileRegex(string fileExtension, FileSystemCasing casing)
        {
            var trimmed = fileExtension.TrimStart('.');

            if (fileExtension.Length - trimmed.Length > 1)
            {
                throw new FileExtensionFormatException("Multiple leading dots are not permitted.", fileExtension);
            }

            var regexPattern = $@"^.*\.{Regex.Escape(trimmed)}$";

            return(FileSystemRegexHelpers.CreateRegex(regexPattern, casing));
        }
        public LocalRoot CreateStorageRoot(string absoluteFileSystemPath, FileSystemCasing casing)
        {
            if (!PathUtils.IsNormalisedAbsolutePath(absoluteFileSystemPath))
            {
                throw new ArgumentException($"Not a valid absolute path: {absoluteFileSystemPath}", nameof(absoluteFileSystemPath));
            }

            var canonicalUri = new WindowsPathCanonicaliser().CanonicaliseAbsolute(new Internal(), absoluteFileSystemPath);

            if (casing == FileSystemCasing.Unspecified)
            {
                return(new LocalRoot(canonicalUri, GetActualCasingRules(canonicalUri)));
            }
            return(new LocalRoot(canonicalUri, casing));
        }
Beispiel #13
0
 public PathEqualityComparer(FileSystemCasing casing)
 {
     comparer = SelectComparer(casing);
 }
Beispiel #14
0
 public StubFileSystemApi(FileSystemCasing defaultCasing = FileSystemCasing.Unspecified)
 {
     this.defaultCasing = defaultCasing;
 }
Beispiel #15
0
 public FilterConfigurationReader(IErrorReceiver errors, FileSystemCasing casing)
 {
     this.errors = errors;
     this.casing = casing;
 }