Exemplo n.º 1
0
        public void TestNegateGlobShouldAllowMultipleNegateChars(string pattern, bool expectedNegate, string expected)
        {
            var negate = GlobMatcher.ParseNegate(ref pattern);

            Assert.Equal(expectedNegate, negate);
            Assert.Equal(expected, pattern);
        }
Exemplo n.º 2
0
        internal static IEnumerable <string> /*!*/ GetMatches(Context ctx, string /*!*/ pattern, GlobOptions flags)
        {
            if (pattern.Length == 0)
            {
                yield break;
            }

            bool noEscape = ((flags & GlobOptions.NoEscape) != 0);
            bool brace    = ((flags & GlobOptions.Brace) != 0);

            string[] groups = UngroupGlobs(pattern, noEscape, brace);
            if (groups.Length == 0)
            {
                yield break;
            }

            foreach (string group in groups)
            {
                GlobMatcher matcher = new GlobMatcher(ctx, group, flags);
                foreach (string filename in matcher.DoGlob())
                {
                    yield return(filename.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar));
                }
            }
        }
        public void MatchesTest(string pattern, string fileName, bool expectsMatch)
        {
            var wildcard = GlobMatcher.Create(pattern, new GlobMatcherOptions {
                IgnoreCase = true, AllowWindowsPaths = true
            });
            var match = wildcard.IsMatch(fileName);

            Assert.AreEqual(expectsMatch, match, $"Failure with pattern {pattern}, fileName {fileName}, should match {expectsMatch}");
        }
        public void MatcherTest()
        {
            const string Glob  = "C:/Projects/editorconfig-core-net/tests/filetree/top/of/path";
            const string File  = "C:/Projects/editorconfig-core-net/tests/filetree/top/of/path";
            var          m     = GlobMatcher.Create(Glob, _globOptions);
            var          match = m.IsMatch(File);

            match.Should().BeTrue();
        }
Exemplo n.º 5
0
        public void TestGlobPartialMatchShouldMatchFolder(string pattern, string[] folders, bool expected)
        {
            var glob = new GlobMatcher(pattern, GlobMatcher.DefaultOptions | GlobMatcherOptions.AllowDotMatch);

            foreach (var file in folders)
            {
                var match = glob.Match(file, true);
                Assert.Equal(expected, match);
            }
        }
Exemplo n.º 6
0
        public void TestGlobMatchWithDotMatchShouldMatchDotFiles(string pattern, string[] files, bool expected)
        {
            var glob = new GlobMatcher(pattern, GlobMatcher.DefaultOptions | GlobMatcherOptions.AllowDotMatch);

            foreach (var file in files)
            {
                var match = glob.Match(file);
                Assert.Equal(expected, match);
            }
        }
Exemplo n.º 7
0
        public void TestGlobMatchWithoutDotMatchShouldMatchNonDotFiles(string pattern, string[] files, bool expected)
        {
            var glob = new GlobMatcher(pattern);

            foreach (var file in files)
            {
                var match = glob.Match(file);
                Assert.Equal(expected, match);
            }
        }
        public IEnumerable <InsqlDescriptor> GetDescriptors()
        {
            var optionsValue = this.options.Value;

            if (!optionsValue.Enabled)
            {
                return(new List <InsqlDescriptor>());
            }

            if (string.IsNullOrWhiteSpace(optionsValue.Matches))
            {
                throw new ArgumentNullException(nameof(optionsValue.Matches), $"{nameof(ExternalDescriptorOptions)} `Matches` is null!");
            }

            GlobMatcher globMatcher = new GlobMatcher(optionsValue.Matches, new GlobMatcherOptions
            {
                AllowWindowsPaths = true
            });

            var directory = optionsValue.Directory;

            if (string.IsNullOrWhiteSpace(directory))
            {
                directory = AppDomain.CurrentDomain.BaseDirectory;
            }

            if (!Path.IsPathRooted(directory))
            {
                directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, directory);
            }

            var fileNames = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories).Where(path => globMatcher.IsMatch(path)).ToList();

            return(fileNames.Select(path =>
            {
                if (!File.Exists(path))
                {
                    return null;
                }

                using (var stream = File.OpenRead(path))
                {
                    return InsqlDescriptorXmlParser.Instance.ParseDescriptor(stream, optionsValue.Namespace);
                }
            }).Where(item => item != null).ToList());
        }
Exemplo n.º 9
0
        private SitemapElementOptions GetMatchingOptions(SitemapOptions options, string sourcePath)
        {
            if (options.FileOptions != null)
            {
                // As the latter one overrides the former one, match the pattern from latter to former
                for (var i = options.FileOptions.Count - 1; i >= 0; i--)
                {
                    var item = options.FileOptions[i];
                    var glob = new GlobMatcher(item.Key);
                    if (glob.Match(sourcePath))
                    {
                        return(item.Value);
                    }
                }
            }

            return(options);
        }
Exemplo n.º 10
0
        /*!*/
        public static IEnumerable<string> GlobResults(IFileAdaptionLayer pal, string/*!*/ pattern, int flags)
        {
            if (pattern.Length == 0) {
                yield break;
            }
            bool noEscape = ((flags & Constants.FNM_NOESCAPE) != 0);
            string[] groups = UngroupGlobs(pattern, noEscape);
            if (groups.Length == 0) {
                yield break;
            }

            foreach (string group in groups) {
                GlobMatcher matcher = new GlobMatcher(pal, group, flags);
                foreach (string filename in matcher.DoGlob()) {
                    yield return filename;
                }
            }
        }
        private static void TestCase(string pattern, IList <string> expected, GlobMatcherOptions?options = null, IEnumerable <string>?input = null)
        {
            input ??= Files;

            var filtered = input;
            var mm       = GlobMatcher.Create(pattern, options);

            filtered = filtered.Where(mm.IsMatch);
            if (options?.NoNull == true)
            {
                filtered = filtered.DefaultIfEmpty(pattern);
            }

            filtered = filtered.OrderBy(s => s);

            Assert.AreEqual(
                String.Join(Environment.NewLine, expected.OrderBy(s => s)),
                String.Join(Environment.NewLine, filtered),
                "Failure from `" + pattern + "`"
                );
        }
Exemplo n.º 12
0
        internal static IEnumerable <string> /*!*/ GetMatches(Context ctx, string /*!*/ pattern, GlobOptions flags)
        {
            if (string.IsNullOrEmpty(pattern))
            {
                yield break;
            }

            var noEscape = (flags & GlobOptions.NoEscape) != 0;
            var brace    = (flags & GlobOptions.Brace) != 0;

            var groups = UngroupGlobs(pattern, noEscape, brace);

            foreach (string group in groups)
            {
                var matcher = new GlobMatcher(ctx, group, flags);

                foreach (string filename in matcher.DoGlob())
                {
                    yield return(CurrentPlatform.NormalizeSlashes(filename));
                }
            }
        }
Exemplo n.º 13
0
        public static IEnumerable <string> /*!*/ GetMatches(string /*!*/ pattern, int flags)
        {
            if (pattern.Length == 0)
            {
                yield break;
            }
            bool noEscape = ((flags & Constants.FNM_NOESCAPE) != 0);

            string[] groups = UngroupGlobs(pattern, noEscape);
            if (groups.Length == 0)
            {
                yield break;
            }
            foreach (string group in groups)
            {
                GlobMatcher matcher = new GlobMatcher(group, flags);
                foreach (string filename in matcher.DoGlob())
                {
                    yield return(filename);
                }
            }
        }
Exemplo n.º 14
0
        private static IEnumerable <string> GetMatches(PlatformAdaptationLayer pal, string pattern, Constants flags)
        {
            if (pattern.Length == 0)
            {
                yield break;
            }
            var noEscape = ((flags & Constants.NoEscape) != 0);
            var groups   = UngroupGlobs(pattern, noEscape);

            if (groups.Length == 0)
            {
                yield break;
            }

            foreach (var group in groups)
            {
                var matcher = new GlobMatcher(pal, group, flags);
                foreach (var filename in matcher.DoGlob())
                {
                    yield return(filename.Replace("//", "/"));
                }
            }
        }
Exemplo n.º 15
0
        public IEnumerable <InsqlDescriptor> GetDescriptors()
        {
            var optionsValue = this.options.Value;

            if (!optionsValue.Enabled)
            {
                return(new List <InsqlDescriptor>());
            }

            if (string.IsNullOrWhiteSpace(optionsValue.Matches))
            {
                throw new ArgumentNullException(nameof(optionsValue.Matches), $"{nameof(EmbeddedDescriptorOptions)} `Matches` is null!");
            }

            GlobMatcher globMatcher = new GlobMatcher(optionsValue.Matches);

            IEnumerable <Assembly> assemblies = optionsValue.Assemblies;

            if (assemblies == null)
            {
                assemblies = AppDomain.CurrentDomain.GetAssemblies();
            }

            assemblies = assemblies.Where(assembly => !assembly.IsDynamic && !assembly.ReflectionOnly);

            return(assemblies.SelectMany(assembly =>
            {
                var resourceNames = assembly.GetManifestResourceNames();

                resourceNames = globMatcher.Filter(resourceNames).ToArray();

                return resourceNames
                .Select(name => InsqlDescriptorXmlParser.Instance.ParseDescriptor(assembly.GetManifestResourceStream(name), optionsValue.Namespace))
                .Where(o => o != null);
            }).ToList());
        }
Exemplo n.º 16
0
 public FileMetadataItem(GlobMatcher glob, string key, object value)
 {
     Glob  = glob;
     Key   = key;
     Value = value;
 }
Exemplo n.º 17
0
 private static IList<string>/*!*/ DoGlob(PlatformAdaptationLayer/*!*/ pal, string/*!*/ pattern, int flags) {
     GlobMatcher matcher = new GlobMatcher(pal, pattern, flags);
     return matcher.DoGlob();
 }
Exemplo n.º 18
0
 public FileMetadataPairsItem(string pattern, object value)
 {
     Glob  = new GlobMatcher(pattern);
     Value = ConvertToObjectHelper.ConvertJObjectToObject(value);
 }
Exemplo n.º 19
0
 private bool ShouldCheckout(SvnChangeset set, StringCollection includeGlobs, StringCollection excludeGlobs)
 {
     return(GlobMatcher.IsIncluded(set.ChangedPaths, includeGlobs) && !GlobMatcher.IsExcluded(set.ChangedPaths, excludeGlobs));
 }
Exemplo n.º 20
0
        internal static IEnumerable<string>/*!*/ GetMatches(string/*!*/ pattern, GlobOptions flags) 
        {
            if (pattern.Length == 0) {
                yield break;
            }

            bool noEscape = ((flags & GlobOptions.NoEscape) != 0);
            bool brace = ((flags & GlobOptions.Brace) != 0);

            string[] groups = UngroupGlobs(pattern, noEscape, brace);
            if (groups.Length == 0) {
                yield break;
            }

            foreach (string group in groups) {
                GlobMatcher matcher = new GlobMatcher(group, flags);
                foreach (string filename in matcher.DoGlob()) {                 
                    yield return filename;
                }
            }            
        }
Exemplo n.º 21
0
        private static IEnumerable<string> GetMatches(PlatformAdaptationLayer pal, string pattern, Constants flags)
        {
            if (pattern.Length == 0)
            {
                yield break;
            }
            var noEscape = ((flags & Constants.NoEscape) != 0);
            var groups = UngroupGlobs(pattern, noEscape);
            if (groups.Length == 0)
            {
                yield break;
            }

            foreach (var group in groups)
            {
                var matcher = new GlobMatcher(pal, group, flags);
                foreach (var filename in matcher.DoGlob())
                {
                    yield return filename.Replace("//", "/");
                }
            }
        }
Exemplo n.º 22
0
        private static IList <string> /*!*/ DoGlob(PlatformAdaptationLayer /*!*/ pal, string /*!*/ pattern, int flags)
        {
            GlobMatcher matcher = new GlobMatcher(pal, pattern, flags);

            return(matcher.DoGlob());
        }
Exemplo n.º 23
0
 public void TestGlobPartialMatchShouldMatchFolder(string pattern, string[] folders, bool expected)
 {
     var glob = new GlobMatcher(pattern, GlobMatcher.DefaultOptions | GlobMatcherOptions.AllowDotMatch);
     foreach (var file in folders)
     {
         var match = glob.Match(file, true);
         Assert.Equal(expected, match);
     }
 }
Exemplo n.º 24
0
 public FileMetadataPairsItem(string pattern, object value)
 {
     Glob  = new GlobMatcher(pattern);
     Value = value;
 }
Exemplo n.º 25
0
 public void TestGlobMatchWithDotMatchShouldMatchDotFiles(string pattern, string[] files, bool expected)
 {
     var glob = new GlobMatcher(pattern, GlobMatcher.DefaultOptions | GlobMatcherOptions.AllowDotMatch);
     foreach (var file in files)
     {
         var match = glob.Match(file);
         Assert.Equal(expected, match);
     }
 }
Exemplo n.º 26
0
 public void TestGlobMatchWithoutDotMatchShouldMatchNonDotFiles(string pattern, string[] files, bool expected)
 {
     var glob = new GlobMatcher(pattern);
     foreach(var file in files)
     {
         var match = glob.Match(file);
         Assert.Equal(expected, match);
     }
 }
Exemplo n.º 27
0
        public void TestGroupedGlobShouldExpand(string source, string[] expected)
        {
            var result = GlobMatcher.ExpandGroup(source);

            Assert.Equal(expected, result);
        }
Exemplo n.º 28
0
 public static IEnumerable<string>/*!*/ GetMatches(string baseDirectory, string/*!*/ pattern, int flags, Func<string, IEnumerable<string>> filesProvider)
 {
     if (pattern.Length == 0)
     {
         yield break;
     }
     bool noEscape = ((flags & Constants.FNM_NOESCAPE) != 0);
     string[] groups = UngroupGlobs(pattern, noEscape);
     if (groups.Length == 0)
     {
         yield break;
     }
     foreach (string group in groups)
     {
         GlobMatcher matcher = new GlobMatcher(baseDirectory, group, flags, filesProvider);
         foreach (string filename in matcher.DoGlob())
         {
             yield return filename;
         }
     }
 }
Exemplo n.º 29
0
        public void Rejects(string glob, string path)
        {
            var matcher = new GlobMatcher(new GlobParser().Parse(glob), true);

            Assert.That(matcher.IsMatch(path.Split('/')), Is.False);
        }