From 204191b83e9beeab83f5eb4dd5dd8a793c5edea6 Mon Sep 17 00:00:00 2001 From: Mark Bell Date: Thu, 23 Jun 2016 12:18:02 +0100 Subject: [PATCH] Allow specification of MatchFlags at the list level, closes #7 --- MAB.DotIgnore.Test/IgnoreListTests.cs | 24 +++++++++++++++++++++ MAB.DotIgnore/IgnoreList.cs | 27 ++++++++++++++---------- MAB.DotIgnore/IgnoreRule.cs | 1 + MAB.DotIgnore/Properties/AssemblyInfo.cs | 6 +++--- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/MAB.DotIgnore.Test/IgnoreListTests.cs b/MAB.DotIgnore.Test/IgnoreListTests.cs index 849dab5..2e7ecab 100644 --- a/MAB.DotIgnore.Test/IgnoreListTests.cs +++ b/MAB.DotIgnore.Test/IgnoreListTests.cs @@ -140,6 +140,30 @@ public void DirectoryInfo_Match_Log() Assert.IsTrue(log[0] == "Ignored by test > test"); } + [Test] + public void Constructor_Flags_Respected() + { + var directory = new DirectoryInfo(_basePath + @"\TEST"); + // Case sensitive list, should not match + var list1 = new IgnoreList(new string[] { "test" }); + // Case insensitive, should match + var list2 = new IgnoreList(new string[] { "test" }, MatchFlags.CASEFOLD); + Assert.IsFalse(list1.IsIgnored(directory)); + Assert.IsTrue(list2.IsIgnored(directory)); + } + + [Test] + public void Add_Rule_Flags_Respected() + { + var directory = new DirectoryInfo(_basePath + @"\TEST"); + var list1 = new IgnoreList(new string[] { "x" }); + var list2 = new IgnoreList(new string[] { "x" }); + list1.AddRule("test"); + list2.AddRule("test", MatchFlags.CASEFOLD); + Assert.IsFalse(list1.IsIgnored(directory)); + Assert.IsTrue(list2.IsIgnored(directory)); + } + [TearDown] public void TearDown() { diff --git a/MAB.DotIgnore/IgnoreList.cs b/MAB.DotIgnore/IgnoreList.cs index 1770bc4..ff45c8a 100644 --- a/MAB.DotIgnore/IgnoreList.cs +++ b/MAB.DotIgnore/IgnoreList.cs @@ -22,45 +22,50 @@ public class IgnoreList /// Create a list of ignore rules to check paths against /// /// A list of glob ignore patterns as strings - public IgnoreList(IEnumerable rules) + /// Optional flags determining pattern matching behaviour + public IgnoreList(IEnumerable rules, MatchFlags flags = MatchFlags.PATHNAME) { - AddRules(rules); + AddRules(rules, flags); } /// /// Create a list of ignore rules to check paths against /// /// Path to a text file containing a list of glob ignore patterns as strings - public IgnoreList(string ignoreFilePath) + /// Optional flags determining pattern matching behaviour + public IgnoreList(string ignoreFilePath, MatchFlags flags = MatchFlags.PATHNAME) { - AddRules(File.ReadAllLines(ignoreFilePath)); + AddRules(File.ReadAllLines(ignoreFilePath), flags); } /// /// Add a rule to the ignore list /// /// Glob ignore pattern as string - public void AddRule(string rule) + /// Optional flags determining pattern matching behaviour + public void AddRule(string rule, MatchFlags flags = MatchFlags.PATHNAME) { - AddRules(new string[] { rule }); + AddRules(new string[] { rule }, flags); } /// /// Add multiple rules to the ignore list /// /// Path to a text file containing a list of glob ignore patterns as strings - public void AddRules(string ignoreFilePath) + /// Optional flags determining pattern matching behaviour + public void AddRules(string ignoreFilePath, MatchFlags flags = MatchFlags.PATHNAME) { - _rules.AddRange(CleanRules(File.ReadAllLines(ignoreFilePath)).Select(line => new IgnoreRule(line))); + _rules.AddRange(CleanRules(File.ReadAllLines(ignoreFilePath)).Select(line => new IgnoreRule(line, flags))); } /// /// Add multiple rules to the ignore list /// /// A list of glob ignore patterns as strings - public void AddRules(IEnumerable rules) + /// Optional flags determining pattern matching behaviour + public void AddRules(IEnumerable rules, MatchFlags flags = MatchFlags.PATHNAME) { - _rules.AddRange(CleanRules(rules).Select(line => new IgnoreRule(line))); + _rules.AddRange(CleanRules(rules).Select(line => new IgnoreRule(line, flags))); } /// @@ -75,7 +80,7 @@ public void RemoveRule(string rule) /// /// Check if a file path matches any of the rules in the ignore list /// - /// FileInfo representing the file to chec + /// FileInfo representing the file to check public bool IsIgnored(FileInfo file) { return IsIgnored(file.FullName, false); diff --git a/MAB.DotIgnore/IgnoreRule.cs b/MAB.DotIgnore/IgnoreRule.cs index 3e71d09..b0cefb0 100644 --- a/MAB.DotIgnore/IgnoreRule.cs +++ b/MAB.DotIgnore/IgnoreRule.cs @@ -35,6 +35,7 @@ public class IgnoreRule /// Create an individual ignore rule for the specified pattern /// /// A glob pattern specifying file(s) this rule should ignore + /// Optional flags determining pattern matching behaviour public IgnoreRule(string pattern, MatchFlags flags = MatchFlags.PATHNAME) { if(Utils.IsNullOrWhiteSpace(pattern)) diff --git a/MAB.DotIgnore/Properties/AssemblyInfo.cs b/MAB.DotIgnore/Properties/AssemblyInfo.cs index 403af4a..262f727 100644 --- a/MAB.DotIgnore/Properties/AssemblyInfo.cs +++ b/MAB.DotIgnore/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.0.0")] -[assembly: AssemblyFileVersion("1.1.0.0")] -[assembly: AssemblyInformationalVersion("1.1.0")] +[assembly: AssemblyVersion("1.2.0.0")] +[assembly: AssemblyFileVersion("1.2.0.0")] +[assembly: AssemblyInformationalVersion("1.2.0")]