public virtual void TestCopyConstructor() { string pattern = "helloworld"; FileNameMatcher matcher = new FileNameMatcher(pattern, null); matcher.Append("hello"); FileNameMatcher copy = new FileNameMatcher(matcher); NUnit.Framework.Assert.AreEqual(false, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(true, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(false, copy.IsMatch()); NUnit.Framework.Assert.AreEqual(true, copy.CanAppendMatch()); matcher.Append("world"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(false, copy.IsMatch()); NUnit.Framework.Assert.AreEqual(true, copy.CanAppendMatch()); copy.Append("world"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(true, copy.IsMatch()); NUnit.Framework.Assert.AreEqual(false, copy.CanAppendMatch()); copy.Reset(); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(false, copy.IsMatch()); NUnit.Framework.Assert.AreEqual(true, copy.CanAppendMatch()); copy.Append("helloworld"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(true, copy.IsMatch()); NUnit.Framework.Assert.AreEqual(false, copy.CanAppendMatch()); }
public virtual void TestCreateMatcherForSuffix() { string pattern = "helloworld"; FileNameMatcher matcher = new FileNameMatcher(pattern, null); matcher.Append("hello"); FileNameMatcher childMatcher = matcher.CreateMatcherForSuffix(); NUnit.Framework.Assert.AreEqual(false, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(true, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(false, childMatcher.IsMatch()); NUnit.Framework.Assert.AreEqual(true, childMatcher.CanAppendMatch()); matcher.Append("world"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(false, childMatcher.IsMatch()); NUnit.Framework.Assert.AreEqual(true, childMatcher.CanAppendMatch()); childMatcher.Append("world"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(true, childMatcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, childMatcher.CanAppendMatch()); childMatcher.Reset(); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(false, childMatcher.IsMatch()); NUnit.Framework.Assert.AreEqual(true, childMatcher.CanAppendMatch()); childMatcher.Append("world"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); NUnit.Framework.Assert.AreEqual(true, childMatcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, childMatcher.CanAppendMatch()); }
/// <exception cref="NGit.Errors.InvalidPatternException"></exception> private void AssertFileNameMatch(string pattern, string input, char excludedCharacter , bool matchExpected, bool appendCanMatchExpected) { FileNameMatcher matcher = new FileNameMatcher(pattern, excludedCharacter); matcher.Append(input); NUnit.Framework.Assert.AreEqual(matchExpected, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(appendCanMatchExpected, matcher.CanAppendMatch()); }
/// <exception cref="NGit.Errors.InvalidPatternException"></exception> private void AssertMatch(string pattern, string input, bool matchExpected, bool appendCanMatchExpected ) { FileNameMatcher matcher = new FileNameMatcher(pattern, null); matcher.Append(input); Assert.AreEqual(matchExpected, matcher.IsMatch()); Assert.AreEqual(appendCanMatchExpected, matcher.CanAppendMatch()); }
/// <summary>Create a new ignore rule with the given pattern.</summary> /// <remarks> /// Create a new ignore rule with the given pattern. Assumes that /// the pattern is already trimmed. /// </remarks> /// <param name="pattern"> /// Base pattern for the ignore rule. This pattern will /// be parsed to generate rule parameters. /// </param> public IgnoreRule(string pattern) { this.pattern = pattern; negation = false; nameOnly = false; dirOnly = false; matcher = null; Setup(); }
public virtual void TestReset() { string pattern = "helloworld"; FileNameMatcher matcher = new FileNameMatcher(pattern, null); matcher.Append("helloworld"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); matcher.Reset(); matcher.Append("hello"); NUnit.Framework.Assert.AreEqual(false, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(true, matcher.CanAppendMatch()); matcher.Append("world"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); matcher.Append("to much"); NUnit.Framework.Assert.AreEqual(false, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); matcher.Reset(); matcher.Append("helloworld"); NUnit.Framework.Assert.AreEqual(true, matcher.IsMatch()); NUnit.Framework.Assert.AreEqual(false, matcher.CanAppendMatch()); }
/// <summary>Remove leading/trailing characters as needed.</summary> /// <remarks> /// Remove leading/trailing characters as needed. Set up /// rule variables for later matching. /// </remarks> private void Setup() { int startIndex = 0; int endIndex = pattern.Length; if (pattern.StartsWith("!")) { startIndex++; negation = true; } if (pattern.EndsWith("/")) { endIndex--; dirOnly = true; } pattern = Sharpen.Runtime.Substring(pattern, startIndex, endIndex); bool hasSlash = pattern.Contains("/"); if (!hasSlash) { nameOnly = true; } else { if (!pattern.StartsWith("/")) { //Contains "/" but does not start with one //Adding / to the start should not interfere with matching pattern = "/" + pattern; } } if (pattern.Contains("*") || pattern.Contains("?") || pattern.Contains("[")) { try { matcher = new FileNameMatcher(pattern, '/'); } catch (InvalidPatternException e) { Sharpen.Runtime.PrintStackTrace(e); } } }
/// <summary> /// A Copy Constructor which creates a new /// <see cref="FileNameMatcher">FileNameMatcher</see> /// with the /// same state and reset point like <code>other</code>. /// </summary> /// <param name="other"> /// another /// <see cref="FileNameMatcher">FileNameMatcher</see> /// instance. /// </param> public FileNameMatcher(NGit.Fnmatch.FileNameMatcher other) : this(other.headsStartValue , other.heads) { }