Exemple #1
0
        public void CaseInsensitive()
        {
            // standard cases
            Assert.AreEqual(@"[Aa]bc", Tools.CaseInsensitive("Abc"));
            Assert.AreEqual(@"[Aa]bc", Tools.CaseInsensitive("abc"));
            Assert.AreEqual(@"[Aa]BC", Tools.CaseInsensitive("aBC"));
            Assert.AreEqual(@"[Aa]bc[de]", Tools.CaseInsensitive("abc[de]"));

            // trimming
            Assert.AreEqual(@"[Aa]bc", Tools.CaseInsensitive("abc "));

            // no changes
            Assert.AreEqual(@" abc", Tools.CaseInsensitive(" abc"));
            Assert.AreEqual("", Tools.CaseInsensitive(""));
            Assert.AreEqual("123", Tools.CaseInsensitive("123"));
            Assert.AreEqual("-", Tools.CaseInsensitive("-"));
            Assert.AreEqual(@"[Aa]bc", Tools.CaseInsensitive(@"[Aa]bc"));

            Regex r = new Regex(Tools.CaseInsensitive("test"));

            Assert.IsTrue(r.IsMatch("test 123"));
            Assert.AreEqual("Test", r.Match("Test").Value);
            Assert.IsFalse(r.IsMatch("tEst"));

            r = new Regex(Tools.CaseInsensitive("Test"));
            Assert.IsTrue(r.IsMatch("test 123"));
            Assert.AreEqual("Test", r.Match("Test").Value);
            Assert.IsFalse(r.IsMatch("TEst"));

            r = new Regex(Tools.CaseInsensitive("#test#"));
            Assert.IsTrue(r.IsMatch("#test#"));
            Assert.IsFalse(r.IsMatch("#Test#"));
            Assert.IsFalse(r.IsMatch("test"));
        }
        public void TestCaseInsensitive()
        {
            Assert.AreEqual("", Tools.CaseInsensitive(""));
            Assert.AreEqual("123", Tools.CaseInsensitive("123"));
            Assert.AreEqual("-", Tools.CaseInsensitive("-"));

            Regex r = new Regex(Tools.CaseInsensitive("test"));

            Assert.IsTrue(r.IsMatch("test 123"));
            Assert.AreEqual("Test", r.Match("Test").Value);
            Assert.IsFalse(r.IsMatch("tEst"));

            r = new Regex(Tools.CaseInsensitive("Test"));
            Assert.IsTrue(r.IsMatch("test 123"));
            Assert.AreEqual("Test", r.Match("Test").Value);
            Assert.IsFalse(r.IsMatch("TEst"));

            r = new Regex(Tools.CaseInsensitive("[test}"));
            Assert.IsTrue(r.IsMatch("[test}"));
            Assert.IsFalse(r.IsMatch("[Test}"));
            Assert.IsFalse(r.IsMatch("test"));
        }