public void TestNegateGlobShouldAllowMultipleNegateChars(string pattern, bool expectedNegate, string expected) { var negate = GlobMatcher.ParseNegate(ref pattern); Assert.Equal(expectedNegate, negate); Assert.Equal(expected, pattern); }
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(); }
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); } }
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); } }
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()); }
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); }
/*!*/ 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 + "`" ); }
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)); } } }
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); } } }
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("//", "/")); } } }
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()); }
public FileMetadataItem(GlobMatcher glob, string key, object value) { Glob = glob; Key = key; Value = value; }
private static IList<string>/*!*/ DoGlob(PlatformAdaptationLayer/*!*/ pal, string/*!*/ pattern, int flags) { GlobMatcher matcher = new GlobMatcher(pal, pattern, flags); return matcher.DoGlob(); }
public FileMetadataPairsItem(string pattern, object value) { Glob = new GlobMatcher(pattern); Value = ConvertToObjectHelper.ConvertJObjectToObject(value); }
private bool ShouldCheckout(SvnChangeset set, StringCollection includeGlobs, StringCollection excludeGlobs) { return(GlobMatcher.IsIncluded(set.ChangedPaths, includeGlobs) && !GlobMatcher.IsExcluded(set.ChangedPaths, excludeGlobs)); }
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; } } }
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("//", "/"); } } }
private static IList <string> /*!*/ DoGlob(PlatformAdaptationLayer /*!*/ pal, string /*!*/ pattern, int flags) { GlobMatcher matcher = new GlobMatcher(pal, pattern, flags); return(matcher.DoGlob()); }
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); } }
public FileMetadataPairsItem(string pattern, object value) { Glob = new GlobMatcher(pattern); Value = value; }
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); } }
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 void TestGroupedGlobShouldExpand(string source, string[] expected) { var result = GlobMatcher.ExpandGroup(source); Assert.Equal(expected, result); }
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; } } }
public void Rejects(string glob, string path) { var matcher = new GlobMatcher(new GlobParser().Parse(glob), true); Assert.That(matcher.IsMatch(path.Split('/')), Is.False); }