Exemplo n.º 1
0
		/// <summary>Check for a match.</summary>
		/// <remarks>
		/// Check for a match. If target ends with "/", match will assume that the
		/// target is meant to be a directory.
		/// </remarks>
		/// <param name="pattern">Pattern as it would appear in a .gitignore file</param>
		/// <param name="target">Target file path relative to repository's GIT_DIR</param>
		/// <returns>
		/// Result of
		/// <see cref="IgnoreRule.IsMatch(string, bool)">IgnoreRule.IsMatch(string, bool)</see>
		/// </returns>
		private bool Match(string pattern, string target)
		{
			IgnoreRule r = new IgnoreRule(pattern);
			//If speed of this test is ever an issue, we can use a presetRule field
			//to avoid recompiling a pattern each time.
			return r.IsMatch(target, target.EndsWith("/"));
		}
Exemplo n.º 2
0
		public virtual void TestGetters()
		{
			IgnoreRule r = new IgnoreRule("/pattern/");
			NUnit.Framework.Assert.IsFalse(r.GetNameOnly());
			NUnit.Framework.Assert.IsTrue(r.DirOnly());
			NUnit.Framework.Assert.IsFalse(r.GetNegation());
			NUnit.Framework.Assert.AreEqual(r.GetPattern(), "/pattern");
			r = new IgnoreRule("/patter?/");
			NUnit.Framework.Assert.IsFalse(r.GetNameOnly());
			NUnit.Framework.Assert.IsTrue(r.DirOnly());
			NUnit.Framework.Assert.IsFalse(r.GetNegation());
			NUnit.Framework.Assert.AreEqual(r.GetPattern(), "/patter?");
			r = new IgnoreRule("patt*");
			NUnit.Framework.Assert.IsTrue(r.GetNameOnly());
			NUnit.Framework.Assert.IsFalse(r.DirOnly());
			NUnit.Framework.Assert.IsFalse(r.GetNegation());
			NUnit.Framework.Assert.AreEqual(r.GetPattern(), "patt*");
			r = new IgnoreRule("pattern");
			NUnit.Framework.Assert.IsTrue(r.GetNameOnly());
			NUnit.Framework.Assert.IsFalse(r.DirOnly());
			NUnit.Framework.Assert.IsFalse(r.GetNegation());
			NUnit.Framework.Assert.AreEqual(r.GetPattern(), "pattern");
			r = new IgnoreRule("!pattern");
			NUnit.Framework.Assert.IsTrue(r.GetNameOnly());
			NUnit.Framework.Assert.IsFalse(r.DirOnly());
			NUnit.Framework.Assert.IsTrue(r.GetNegation());
			NUnit.Framework.Assert.AreEqual(r.GetPattern(), "pattern");
			r = new IgnoreRule("!/pattern");
			NUnit.Framework.Assert.IsFalse(r.GetNameOnly());
			NUnit.Framework.Assert.IsFalse(r.DirOnly());
			NUnit.Framework.Assert.IsTrue(r.GetNegation());
			NUnit.Framework.Assert.AreEqual(r.GetPattern(), "/pattern");
			r = new IgnoreRule("!/patter?");
			NUnit.Framework.Assert.IsFalse(r.GetNameOnly());
			NUnit.Framework.Assert.IsFalse(r.DirOnly());
			NUnit.Framework.Assert.IsTrue(r.GetNegation());
			NUnit.Framework.Assert.AreEqual(r.GetPattern(), "/patter?");
		}