示例#1
0
        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());
        }
示例#2
0
        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());
        }
示例#3
0
		/// <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());
		}
示例#4
0
		/// <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());
		}
示例#5
0
        /// <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());
        }
示例#6
0
        /// <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());
        }
示例#7
0
		/// <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();
		}
示例#8
0
        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());
        }
示例#9
0
		/// <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);
				}
			}
		}
示例#10
0
 /// <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)
 {
 }
示例#11
0
		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());
		}
示例#12
0
		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());
		}
示例#13
0
		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());
		}