Skip to content

Commit

Permalink
StringProcessing: Add assert for unescaped_split
Browse files Browse the repository at this point in the history
  • Loading branch information
Makman2 committed Mar 24, 2015
1 parent 3861a54 commit 192d724
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions coalib/tests/parsing/StringProcessingTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,33 @@ def assertSplitEquals(self,
self.assertIteratorElementsEqual(iter(expected_results[i]),
return_value)

def assertUnescapedSplitEquals(self,
test_strings,
expected_results,
pattern,
max_split=0,
remove_empty_matches=False):
"""
Checks whether all supplied test strings are returned as expected from
unescaped_split().
:param test_strings: The list of test strings.
:param expected_results: The list of the expected results.
:param pattern: The pattern to invoke unescaped_split()
with.
:param max_split: The maximum number of splits to perform
when invoking unescaped_split().
:param remove_empty_matches: Whether to remove empty entries or not.
"""
self.assertEqual(len(expected_results), len(test_strings))
for i in range(0, len(expected_results)):
return_value = unescaped_split(pattern,
test_strings[i],
max_split,
remove_empty_matches)
self.assertIteratorElementsEqual(iter(expected_results[i]),
return_value)

def assertIteratorElementsEqual(self, iterator1, iterator2):
"""
Checks whether each element in the iterators and their length do equal.
Expand Down Expand Up @@ -482,15 +509,10 @@ def test_split_auto_trim(self):

# Test the basic unescaped_split() functionality.
def test_unescaped_split(self):
separator_pattern = self.test_unescaped_split_pattern
expected_results = self.test_unescaped_split_expected_results

self.assertEqual(len(expected_results), len(self.test_strings))
for i in range(0, len(expected_results)):
return_value = unescaped_split(separator_pattern,
self.test_strings[i])
self.assertIteratorElementsEqual(iter(expected_results[i]),
return_value)
self.assertUnescapedSplitEquals(
self.test_strings,
self.test_unescaped_split_expected_results,
self.test_unescaped_split_pattern)

# Test the unescaped_split() function while varying the max_split
# parameter.
Expand All @@ -512,13 +534,10 @@ def test_unescaped_split_max_split(self):
str.join(separator_pattern,
expected_master_results[j][max_split : ]))

self.assertEqual(len(expected_results), len(self.test_strings))
for x in range(0, len(expected_results)):
return_value = unescaped_split(separator_pattern,
self.test_strings[x],
max_split)
self.assertIteratorElementsEqual(iter(expected_results[x]),
return_value)
self.assertUnescapedSplitEquals(self.test_strings,
expected_results,
separator_pattern,
max_split)

# Test the unescaped_split() function with different regex patterns.
def test_unescaped_split_regex_pattern(self):
Expand All @@ -534,18 +553,12 @@ def test_unescaped_split_regex_pattern(self):

# Test the unescaped_split() function for its remove_empty_matches feature.
def test_unescaped_split_auto_trim(self):
separator = self.test_unescaped_split_auto_trim_pattern
expected_results = self.test_unescaped_split_auto_trim_expected_results

self.assertEqual(len(expected_results),
len(self.auto_trim_test_strings))
for i in range(0, len(expected_results)):
return_value = unescaped_split(separator,
self.auto_trim_test_strings[i],
0,
True)
self.assertIteratorElementsEqual(iter(expected_results[i]),
return_value)
self.assertUnescapedSplitEquals(
self.auto_trim_test_strings,
self.test_unescaped_split_auto_trim_expected_results,
self.test_unescaped_split_auto_trim_pattern,
0,
True)

# Test the basic search_in_between() functionality.
def test_search_in_between(self):
Expand Down

1 comment on commit 192d724

@sils
Copy link
Member

@sils sils commented on 192d724 Mar 26, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Please sign in to comment.