Beispiel #1
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 #2
0
        public void ORegex_Search_Offset()
        {
            using (var r = new ORegex("A"))
            {
                Assert.IsTrue(r.Valid);
                r.Search("-A-", 1);

                Assert.AreEqual(1, r.MatchPosition(0));
                Assert.AreEqual(1, r.MatchLength(0));
                Assert.AreEqual("A", r.Capture(0));

                Assert.AreEqual(-1, r.MatchPosition(1));
                Assert.AreEqual(-1, r.MatchLength(1));
                Assert.AreEqual(null, r.Capture(1));
            }
        }
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
        public void ORegex_Search_MultipleCaptures()
        {
            using (var r = new ORegex("(A)(.*)"))
            {
                Assert.IsTrue(r.Valid);
                r.Search("---A---");
                Assert.AreEqual(3, r.MatchPosition(0));
                Assert.AreEqual(4, r.MatchLength(0));
                Assert.AreEqual("A---", r.Capture(0));

                Assert.AreEqual(3, r.MatchPosition(1));
                Assert.AreEqual(1, r.MatchLength(1));
                Assert.AreEqual("A", r.Capture(1));

                Assert.AreEqual(4, r.MatchPosition(2));
                Assert.AreEqual(3, r.MatchLength(2));
                Assert.AreEqual("---", r.Capture(2));

                Assert.AreEqual(-1, r.MatchPosition(3));
                Assert.AreEqual(-1, r.MatchLength(3));
                Assert.AreEqual(null, r.Capture(3));
            }
        }