public void GetMatchesOf_AnyOr56_ForDigitsStartingAt5() { int index = 5; AlternationExpression<char> expression = new AlternationExpression<char>( m_any, new ListExpression<char>(m_digits[5],m_digits[6])); var list = DigetsList; var matches = expression.GetMatches (list, index).ToList (); string[] expectedMatches = new [] {"5","56"}; Assert.AreEqual (expectedMatches.Length, matches.Count (), "Count"); int matchesIndex = 0; foreach (var match in matches) { string expected = expectedMatches [matchesIndex]; 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"); string matchedString = new string (match.Items.ToArray ()); Assert.AreEqual (expected, matchedString, "matched string does not match expected value."); matchesIndex++; } }
public void ParamsConstructorCopiesParamsArraySoParamsArrayModificationDoesNotAffectConstructedExpression() { IExpression<char> [] expressions = new [] {m_any, m_any, m_any}; var expression = new AlternationExpression<char> (expressions); int index = 0; var list = DigetsList; // alter array expressions [0] = m_digits[5]; expressions [1] = m_digits[8]; expressions [2] = m_a; var matches = expression.GetMatches (list, index); Assert.AreEqual (3, matches.Count (), "Count"); foreach (var match in matches) { Assert.AreEqual (index, match.Index, "match.Index"); Assert.AreEqual (1, match.Length, "match.Length"); Assert.IsTrue (match.Success, "match.Success"); Assert.AreEqual (1, match.Items.Count, "match.Items.Count"); Assert.AreEqual (list[index], match.Items [0], "match.Items [0]"); } }
public void GetMatchesOfEmptyFindsOneZeroLengthMatchForDigitsStartingAt8() { AlternationExpression<char> expression = new AlternationExpression<char> (); int index = 8; var list = DigetsList; int length = 0; var matches = expression.GetMatches (list, index); Assert.AreEqual (1, matches.Count (), "Count"); var match = matches.First (); 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"); }
public void GetMatchesOfNullThrowsArgumentNullException() { AlternationExpression<char> expression = new AlternationExpression<char> (m_digits[5],m_a); var matches = expression.GetMatches (null, 8); }
public void GetMatchesOfDigits_AnyOr5OrAny() { IExpression<char> [] expressions = new [] {m_any, m_digits[5], m_any}; var expression = new AlternationExpression<char> (expressions); string expected = "5"; int index = 5; var list = DigetsList; var matches = expression.GetMatches (list, index).ToList (); Assert.AreEqual (3, matches.Count (), "Count"); foreach (var match in matches) { 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"); string matchedString = new string (match.Items.ToArray ()); Assert.AreEqual (expected, matchedString, "matched string does not match expected value."); } }
public void GetMatchesOfAor8or5orAnyFindsTwoMatchesForDigitsStartingAt5() { AlternationExpression<char> expression = new AlternationExpression<char> (m_a,m_digits[8],m_digits[5],m_any); int index = 5; var list = DigetsList; var matches = expression.GetMatches (list, index); Assert.AreEqual (2, matches.Count (), "Count"); foreach (var match in matches) { Assert.AreEqual (index, match.Index, "match.Index"); Assert.AreEqual (1, match.Length, "match.Length"); Assert.IsTrue (match.Success, "match.Success"); Assert.AreEqual (1, match.Items.Count, "match.Items.Count"); Assert.AreEqual (list[index], match.Items [0], "match.Items [0]"); } }
public void GetMatchesOf5orAFindsNoMatchForDigitsStartingAt8() { AlternationExpression<char> expression = new AlternationExpression<char> (m_digits[5],m_a); var matches = expression.GetMatches (DigetsList, 8); Assert.AreEqual (0, matches.Count (), "Count"); }
public void GetMatchesFindsOneMatchForA() { AlternationExpression<char> expression = new AlternationExpression<char> (m_a); int index = 0; var list = AList; var matches = expression.GetMatches (list, index); Assert.AreEqual (1, matches.Count (), "Count"); var match = matches.First (); Assert.AreEqual (index, match.Index, "match.Index"); Assert.AreEqual (1, match.Length, "match.Length"); Assert.IsTrue (match.Success, "match.Success"); Assert.AreEqual (1, match.Items.Count, "match.Items.Count"); Assert.AreEqual (list[index], match.Items [0], "match.Items [0]"); }
public void GetMatchesFindsNoMatchesForEmpty() { AlternationExpression<char> expression = new AlternationExpression<char> (m_any); var matches = expression.GetMatches (EmptyList, 0); Assert.AreEqual (0, matches.Count (), "Count"); }