Beispiel #1
0
 public void ORegex_IndexIn_WithOffset()
 {
     using (var r = new ORegex("A"))
     {
         Assert.IsTrue(r.Valid);
         Assert.AreEqual(-1, r.IndexIn("A--", 1));
         Assert.AreEqual(1, r.IndexIn("AA-", 1));
         Assert.AreEqual(2, r.IndexIn("A-A", 2));
         Assert.AreEqual(2, r.IndexIn("--A", 2));
     }
 }
Beispiel #2
0
        public void ORegex_InvalidRegularExpression()
        {
            var invalidRegex = "(.*";
            var r            = new ORegex(invalidRegex);

            Assert.IsFalse(r.Valid);

            try
            {
                r.SafeSearch("test");
                Assert.Fail("An invalid regular expression did not throw an ArgumentException");
            }
            catch (ArgumentException) { }

            try
            {
                r.IndexIn("test");
                Assert.Fail("An invalid regular expression did not throw an ArgumentException");
            }
            catch (ArgumentException) { }

            try
            {
                r.Search("test");
                Assert.Fail("An invalid regular expression did not throw an ArgumentException");
            }
            catch (ArgumentException) { }
        }
Beispiel #3
0
        public void ORegex_ObjectDisposedExceptions()
        {
            var r = new ORegex("A");

            r.Dispose();

            try
            {
                r.SafeSearch("test");
                Assert.Fail();
            }
            catch (ObjectDisposedException) { }

            try
            {
                r.Search("test");
                Assert.Fail();
            }
            catch (ObjectDisposedException) { }

            try
            {
                r.IndexIn("test");
                Assert.Fail();
            }
            catch (ObjectDisposedException) { }

            try
            {
                r.MatchPosition(0);
                Assert.Fail();
            }
            catch (ObjectDisposedException) { }

            try
            {
                r.MatchLength(0);
                Assert.Fail();
            }
            catch (ObjectDisposedException) { }

            try
            {
                r.Capture(0);
                Assert.Fail();
            }
            catch (ObjectDisposedException) { }

            // IDisposable.Dispose() should be idempotent
            try
            {
                r.Dispose();
            }
            catch (ObjectDisposedException)
            {
                Assert.Fail();
            }
        }
Beispiel #4
0
        /// <summary>
        /// This is not intended as a full test suite. It's just here to easily
        /// test that the dll/so/dylib works on a given environment.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var text    = "abcABC123";
            var pattern = "[A-C]+";

            Console.WriteLine("Building ORegex({0})", text);

            using (var re = new ORegex(pattern, false))
            {
                Console.WriteLine("Looking for {0} in {1}", pattern, text);
                Console.WriteLine("Found a match at {0}", re.IndexIn(text));
            }
        }
Beispiel #5
0
        public void ORegex_NoCaptureExceptions()
        {
            using (var r = new ORegex("A"))
            {
                // No region is defined since we haven't searched
                try
                {
                    r.MatchPosition(0);
                    Assert.Fail();
                }
                catch (InvalidOperationException) { }

                try
                {
                    r.MatchLength(0);
                    Assert.Fail();
                }
                catch (InvalidOperationException) { }

                try
                {
                    r.Capture(0);
                    Assert.Fail();
                }
                catch (InvalidOperationException) { }

                // IndexIn should not create a region. Only Search does that.
                r.IndexIn("A");
                try
                {
                    r.MatchPosition(0);
                    Assert.Fail();
                }
                catch (InvalidOperationException) { }

                try
                {
                    r.MatchLength(0);
                    Assert.Fail();
                }
                catch (InvalidOperationException) { }

                try
                {
                    r.Capture(0);
                    Assert.Fail();
                }
                catch (InvalidOperationException) { }
            }
        }
Beispiel #6
0
        public void ORegex_MultilineSearch()
        {
            using (var r = new ORegex("A.B", multiline: false))
            {
                Assert.IsTrue(r.Valid);
                Assert.AreEqual(-1, r.IndexIn("A\nB"));
            }

            using (var r = new ORegex("A.B", multiline: true))
            {
                Assert.IsTrue(r.Valid);
                Assert.AreEqual(0, r.IndexIn("A\nB"));
            }
        }