public void ConstructorSucceeds()
 {
     int min = 0;
      int max = int.MaxValue;
      var expression = new GreedyRepeatExpression<char> (m_A);
      Assert.AreEqual (min, expression.Minimum, "Minimum");
      Assert.AreEqual (max, expression.Maximum, "Maximum");
 }
 public void SupportsLookBack_For_LookBackSupported()
 {
     var expression = new GreedyRepeatExpression<char> (LookBackSupported, 2,4);
      Assert.IsTrue (expression.SupportsLookBack);
 }
 public void RangeConstructorArgumentOutOfRangeExceptionForNegativeMinimum()
 {
     var expression = new GreedyRepeatExpression<char> (m_any, -1, 23);
 }
 public void RangeConstructorArgumentExceptionForMaximumLessThanMinimum()
 {
     var expression = new GreedyRepeatExpression<char> (m_any, 4, 3);
 }
 public void NotSupportsLookBack_For_LookBackSupported_LookBackNotSupported()
 {
     var expression = new GreedyRepeatExpression<char> (new AlternationExpression<char> (LookBackSupported, LookBackNotSupported), 2);
      Assert.IsFalse (expression.SupportsLookBack);
 }
 public void NotAnyLength_For_NotAnyLength()
 {
     var expression = new GreedyRepeatExpression<char> (NotAnyLength, 2);
      Assert.IsFalse (expression.AnyLength);
 }
        public void GetMatchesFindsOneMatchForA()
        {
            GreedyRepeatExpression<char> expression = new GreedyRepeatExpression<char> (m_A);

             string [] expectedValues = new [] {"A", ""};
             int index = 0;
             var list = AList;
             var matches = expression.GetMatches (list, index).ToList ();

             Assert.AreEqual (expectedValues.Length, matches.Count (), "Count");

             for (int i = 0; i < expectedValues.Length; i++)
             {
            var match = matches [i];
            var expected = expectedValues [i];
            Assert.AreEqual (index, match.Index, "match.Index");
            Assert.AreEqual (expected.Length, match.Length, "match.Length");
            Assert.IsTrue (match.Success, "match.Success");
            Assert.AreEqual (expected.Length, match.Items.Count, "match.Items.Count");
            Assert.AreEqual (expected, new string (match.Items.ToArray ()), "match.Items");
             }
        }
 public void ConstructorThrowArgumentNullExceptionForNullArray()
 {
     var expression = new GreedyRepeatExpression<char> ((IExpression<char>) null);
 }
 public void GetPossibleMatchLengths_ForEmpty()
 {
     var expected = new int [] {0};
      var expression = new GreedyRepeatExpression<char> (new AlternationExpression<char>());
      expression.AssertPossibleMatchLengths (expected);
 }
 public void GetPossibleMatchLengths_For1_4to6()
 {
     var expected = new int [] {4,5,6};
      var expression = new GreedyRepeatExpression<char> (MatchLength1, 4, 6);
      expression.AssertPossibleMatchLengths (expected);
 }
        public void GetMatchesOf_A_ForAAABBB_LikeRegex()
        {
            var expression = new GreedyRepeatExpression<char> (m_A);

             expression.AssertMatches ("AAABBB", "A*");
        }
        public void GetMatchesOf_A_3_ForAAABBBReturnsAAA()
        {
            int index = 0;
             int length = 3;
             GreedyRepeatExpression<char> expression = new GreedyRepeatExpression<char> (m_A, length);

             var list = AAABBB;
             var matches = expression.GetMatches (list, index).ToList ();

             Assert.AreEqual (1, matches.Count (), "Count");
             foreach (var match in matches)
             {
            Assert.AreEqual (index, match.Index, "match.Index");
            Assert.AreEqual (length, match.Length, "match.Length");
            Assert.IsTrue (match.Success, "match.Success");
            Assert.AreEqual (length, match.Items.Count, "match.Items.Count");
            for (int i = 0; i < length; i++)
            {
               Assert.AreEqual (list[index + i], match.Items [i], "match.Items [" + i + "]");
            }
             }
        }
        public void GetMatchesOf_Any_2_ForDigetsStartingAt5Returns56()
        {
            int index = 5;
             GreedyRepeatExpression<char> expression = new GreedyRepeatExpression<char> (m_any, 2);
             int length = 2;

             var list = DigetsList;
             var matches = expression.GetMatches (list, index).ToList ();

             Assert.AreEqual (1, matches.Count (), "Count");
             foreach (var match in matches)
             {
            Assert.AreEqual (index, match.Index, "match.Index");
            Assert.AreEqual (length, match.Length, "match.Length");
            Assert.IsTrue (match.Success, "match.Success");
            Assert.AreEqual (length, match.Items.Count, "match.Items.Count");
            for (int i = 0; i < length; i++)
            {
               Assert.AreEqual (list[index + i], match.Items [i], "match.Items [" + i + "]");
            }
             }
        }
        public void GetMatchesOf_AAorABorBB_1_2_ForAAABBB()
        {
            int index = 0;
             GreedyRepeatExpression<char> expression =
            new GreedyRepeatExpression<char> (
               new AlternationExpression<char> (
                  new ListExpression<char>(m_A, m_A),
                  new ListExpression<char>(m_A, m_B),
                  new ListExpression<char>(m_B, m_B)),
               1, 2);

             string [] expectedValues =
            new [] {"AA", "AAAB"}
               .Reverse ()
               .ToArray ();
             var list = AAABBB;

             var matches = expression.GetMatches (list, index).ToList ();

             Assert.AreEqual (expectedValues.Length, matches.Count (), "Count");
             for (int i = 0; i < expectedValues.Length; i++)
             {
            var match = matches [i];
            var expected = expectedValues [i];
            Assert.AreEqual (index, match.Index, "match.Index at " + i);
            Assert.AreEqual (expected.Length, match.Length, "match.Length at " + i);
            Assert.IsTrue (match.Success, "match.Success at " + i);
            Assert.AreEqual (expected.Length, match.Items.Count, "match.Items.Count at " + i);

            Assert.AreEqual (expected, new string (match.Items.ToArray ()), "Value at " + i);
             }
        }
        public void GetMatchesOfDigits_Any_4_8()
        {
            var expression = new GreedyRepeatExpression<char> (m_any, 4, 8);

             string [] expectedValues =
            new [] {"0123", "01234", "012345", "0123456", "01234567"}
               .Reverse ()
               .ToArray ();

             int index = 0;
             var list = DigetsList;

             var matches = expression.GetMatches (list, index).ToList ();

             Assert.AreEqual (expectedValues.Length, matches.Count (), "Count");
             for (int i = 0; i < expectedValues.Length; i++)
             {
            var match = matches [i];
            var expected = expectedValues [i];
            Assert.AreEqual (index, match.Index, "match.Index at " + i);
            Assert.AreEqual (expected.Length, match.Length, "match.Length at " + i);
            Assert.IsTrue (match.Success, "match.Success at " + i);
            Assert.AreEqual (expected.Length, match.Items.Count, "match.Items.Count at " + i);
            Assert.AreEqual (expected, new string (match.Items.ToArray ()), "Value at " + i);
             }
        }
 public void AnyLength_For_AnyLength_NotAnyLength()
 {
     var expression = new GreedyRepeatExpression<char> (
     new ListExpression<char> (AnyLength, NotAnyLength));
      Assert.IsTrue (expression.AnyLength);
 }
 public void GetPossibleMatchLengths_For_2_3to4()
 {
     var expected = new int [] {6,8};
      var expression = new GreedyRepeatExpression<char> (MatchLength2, 3,4);
      expression.AssertPossibleMatchLengths (expected);
 }
 public void GetPossibleMatchLengths_For_3to5_2to3()
 {
     var expected = new int [] {3+3,3+3+3,3+3+4,3+3+5,3+4,3+4+5,3+5,3+5+5,4+5+5,5+5+5};
      var expression = new GreedyRepeatExpression<char> (MatchLengths3to5, 2,3);
      expression.AssertPossibleMatchLengths (expected);
 }
 public void ExactConstructorSucceeds()
 {
     int min = 2;
      int max = min;
      var expression = new GreedyRepeatExpression<char> (m_A, min);
      Assert.AreEqual (min, expression.Minimum, "Minimum");
      Assert.AreEqual (max, expression.Maximum, "Maximum");
 }
 public void ExactConstructorThrowArgumentOutOfRangeException()
 {
     var expression = new GreedyRepeatExpression<char> (m_any, -1);
 }