Skip to content

Commit

Permalink
Expand some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cpburnz committed Jun 12, 2021
1 parent a6ebcba commit 789fa6f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pathspec/tests/test_gitwildmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def test_03_inner_double_asterisk(self):
This should match:
left/right
left/bar/right
left/foo/bar/right
left/bar/right/foo
Expand All @@ -198,12 +199,14 @@ def test_03_inner_double_asterisk(self):

pattern = GitWildMatchPattern(re.compile(regex), include)
results = set(pattern.match([
'left/right',
'left/bar/right',
'left/foo/bar/right',
'left/bar/right/foo',
'foo/left/bar/right',
]))
self.assertEqual(results, {
'left/right',
'left/bar/right',
'left/foo/bar/right',
'left/bar/right/foo',
Expand All @@ -223,6 +226,7 @@ def test_03_parent_double_asterisk(self):
This should match:
spam
foo/spam
foo/spam/bar
"""
Expand All @@ -232,10 +236,12 @@ def test_03_parent_double_asterisk(self):

pattern = GitWildMatchPattern(re.compile(regex), include)
results = set(pattern.match([
'spam',
'foo/spam',
'foo/spam/bar',
]))
self.assertEqual(results, {
'spam',
'foo/spam',
'foo/spam/bar',
})
Expand Down Expand Up @@ -264,6 +270,17 @@ def test_03_duplicate_leading_double_asterisk_edge_case(self):
self.assertTrue(include)
self.assertEqual(equivalent_regex, regex)

regex, include = GitWildMatchPattern.pattern_to_regex('**/api/')
self.assertTrue(include)
self.assertEqual(regex, '^(?:.+/)?api/.*$')

equivalent_regex, include = GitWildMatchPattern.pattern_to_regex('**/api/**')
self.assertTrue(include)
self.assertEqual(equivalent_regex, regex)

equivalent_regex, include = GitWildMatchPattern.pattern_to_regex('**/**/api/**/**')
self.assertTrue(include)
self.assertEqual(equivalent_regex, regex)

def test_03_double_asterisk_trailing_slash_edge_case(self):
"""
Expand All @@ -273,9 +290,7 @@ def test_03_double_asterisk_trailing_slash_edge_case(self):
"""
regex, include = GitWildMatchPattern.pattern_to_regex('**/')
self.assertTrue(include)
# FIXME: currently failing
# REVIEW: I believe this is the correct regex for this case
# self.assertEqual(regex, '^(?:.+/).*$')
self.assertEqual(regex, '^.+/.*$')

equivalent_regex, include = GitWildMatchPattern.pattern_to_regex('**/**/')
self.assertTrue(include)
Expand Down

0 comments on commit 789fa6f

Please sign in to comment.