Exemplo n.º 1
0
        public static void CaptureCollection_GetEnumeratorTest()
        {
            Regex             rgx1     = new Regex(@"(?<A1>a*)(?<A2>b*)(?<A3>c*)");
            String            strInput = "aaabbccccccccccaaaabc";
            Match             mtch1    = rgx1.Match(strInput);
            CaptureCollection captrc1  = mtch1.Captures;

            IEnumerator enmtr1 = captrc1.GetEnumerator();

            for (int i = 0; i < captrc1.Count; i++)
            {
                enmtr1.MoveNext();

                Assert.Equal(enmtr1.Current, captrc1[i]);
            }

            Assert.False(enmtr1.MoveNext(), "Err_5! enmtr1.MoveNext returned true");

            enmtr1.Reset();

            for (int i = 0; i < captrc1.Count; i++)
            {
                enmtr1.MoveNext();

                Assert.Equal(enmtr1.Current, captrc1[i]);
            }
        }
Exemplo n.º 2
0
        public static void CaptureCollection_GetEnumeratorTest_Negative()
        {
            Regex             rgx1     = new Regex(@"(?<A1>a*)(?<A2>b*)(?<A3>c*)");
            String            strInput = "aaabbccccccccccaaaabc";
            Match             mtch1    = rgx1.Match(strInput);
            CaptureCollection captrc1  = mtch1.Captures;

            IEnumerator enmtr1 = captrc1.GetEnumerator();

            Capture currentCapture;

            Assert.Throws <InvalidOperationException>(() => currentCapture = (Capture)enmtr1.Current);


            for (int i = 0; i < captrc1.Count; i++)
            {
                enmtr1.MoveNext();
            }

            enmtr1.MoveNext();

            Assert.Throws <InvalidOperationException>(() => currentCapture = (Capture)enmtr1.Current);
            enmtr1.Reset();

            Assert.Throws <InvalidOperationException>(() => currentCapture = (Capture)enmtr1.Current);
        }
Exemplo n.º 3
0
        public void Deny_Unrestricted()
        {
            Assert.AreEqual(0, coll.Count, "Count");
            Assert.IsTrue(coll.IsReadOnly, "IsReadOnly");
            Assert.IsFalse(coll.IsSynchronized, "IsSynchronized");
            Assert.IsNotNull(coll.SyncRoot, "SyncRoot");

            Assert.IsNotNull(coll.GetEnumerator(), "GetEnumerator");
            Capture[] captures = new Capture[0];
            coll.CopyTo(captures, 0);
        }
Exemplo n.º 4
0
        public static void GetEnumerator()
        {
            Regex regex = new Regex(@"(?<A1>a*)(?<A2>b*)(?<A3>c*)");
            Match match = regex.Match("aaabbccccccccccaaaabc");

            CaptureCollection captures   = match.Captures;
            IEnumerator       enumerator = captures.GetEnumerator();

            for (int i = 0; i < 2; i++)
            {
                int counter = 0;
                while (enumerator.MoveNext())
                {
                    Assert.Equal(captures[counter], enumerator.Current);
                    counter++;
                }
                Assert.Equal(captures.Count, counter);
                enumerator.Reset();
            }
        }