Skip to content

Commit 361b535

Browse files
committed
Issue 93 tests
1 parent b1bc286 commit 361b535

2 files changed

Lines changed: 86 additions & 28 deletions

File tree

tests/test_02_gitignore_basic.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -905,27 +905,56 @@ def test_15_issue_93_b_2_double(self):
905905
self.assertFalse(pattern.match_file(' foo'))
906906
self.assertTrue(pattern.match_file(' foo'))
907907

908-
def test_15_issue_93_c_1(self):
908+
def test_15_issue_93_c_1_valid(self):
909909
"""
910-
Test patterns with invalid range notation.
910+
Test patterns with valid range notations.
911911
"""
912-
# TODO BUG: This test is a placeholder for the current behavior. Git behaves
913-
# differently for this scenario.
912+
for raw_pattern, regex in [
913+
('[a-z]', f'^(?:.+/)?[a-z]{_DIR_OPT}'),
914+
('a[a-z]', f'^(?:.+/)?a[a-z]{_DIR_OPT}'),
915+
]:
916+
with self.subTest(f"p={raw_pattern!r}"):
917+
pattern = GitIgnoreBasicPattern(raw_pattern)
918+
self.assertIs(pattern.include, True)
919+
self.assertEqual(pattern.regex.pattern, regex)
920+
921+
def test_15_issue_93_c_2_invalid(self):
922+
"""
923+
Test patterns with invalid range notations.
924+
"""
925+
# TODO BUG: These tests need to pass.
914926
# - See <https://github.com/cpburnz/python-pathspec/issues/93>.
915-
pattern = GitIgnoreBasicPattern('[')
916-
self.assertIs(pattern.include, True)
917-
self.assertEqual(pattern.regex.pattern, f'^(?:.+/)?\\[{_DIR_OPT}')
927+
for raw_pattern in [
928+
'[!]',
929+
'[z-a]',
930+
'a[z-a]',
931+
]:
932+
with self.subTest(f"p={raw_pattern!r}"):
933+
pattern = GitIgnoreBasicPattern(raw_pattern)
934+
self.assertIs(pattern.include, None)
935+
self.assertIs(pattern.regex.pattern, None)
918936

919-
def test_15_issue_93_c_2(self):
937+
def test_15_issue_93_c_3_unclosed(self):
920938
"""
921-
Test patterns with invalid range notation.
939+
Test patterns with unclosed range notations.
922940
"""
923-
# TODO BUG: This test is a placeholder for the current behavior. Git behaves
924-
# differently for this scenario.
941+
# TODO BUG: These tests need to pass.
925942
# - See <https://github.com/cpburnz/python-pathspec/issues/93>.
926-
pattern = GitIgnoreBasicPattern('[!]')
927-
self.assertIs(pattern.include, True)
928-
self.assertEqual(pattern.regex.pattern, f'^(?:.+/)?\\[!\\]{_DIR_OPT}')
943+
for raw_pattern in [
944+
'[!',
945+
'[-',
946+
'[a',
947+
'[a-',
948+
'[a-z',
949+
'a[',
950+
'a[-',
951+
'a[a-',
952+
'a[a-z',
953+
]:
954+
with self.subTest(f"p={raw_pattern!r}"):
955+
pattern = GitIgnoreBasicPattern(raw_pattern)
956+
self.assertIs(pattern.include, None)
957+
self.assertIs(pattern.regex.pattern, None)
929958

930959
def test_16_repr_str(self):
931960
"""

tests/test_03_gitignore_spec.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -907,24 +907,53 @@ def test_15_issue_93_b_2_double(self):
907907
self.assertFalse(pattern.match_file(' foo'))
908908
self.assertTrue(pattern.match_file(' foo'))
909909

910-
def test_15_issue_93_c_1(self):
910+
def test_15_issue_93_c_1_valid(self):
911911
"""
912-
Test patterns with invalid range notation.
912+
Test patterns with valid range notations.
913913
"""
914-
# TODO BUG: This test is a placeholder for the current behavior. Git behaves
915-
# differently for this scenario.
914+
for raw_pattern, regex in [
915+
('[a-z]', f'^(?:.+/)?[a-z]{_DIR_MARK_OPT}'),
916+
('a[a-z]', f'^(?:.+/)?a[a-z]{_DIR_MARK_OPT}'),
917+
]:
918+
with self.subTest(f"p={raw_pattern!r}"):
919+
pattern = GitIgnoreSpecPattern(raw_pattern)
920+
self.assertIs(pattern.include, True)
921+
self.assertEqual(pattern.regex.pattern, regex)
922+
923+
def test_15_issue_93_c_2_invalid(self):
924+
"""
925+
Test patterns with invalid range notations.
926+
"""
927+
# TODO BUG: These tests need to pass.
916928
# - See <https://github.com/cpburnz/python-pathspec/issues/93>.
917-
pattern = GitIgnoreSpecPattern('[')
918-
self.assertIs(pattern.include, True)
919-
self.assertEqual(pattern.regex.pattern, f'^(?:.+/)?\\[{_DIR_MARK_OPT}')
929+
for raw_pattern in [
930+
'[!]',
931+
'[z-a]',
932+
'a[z-a]',
933+
]:
934+
with self.subTest(f"p={raw_pattern!r}"):
935+
pattern = GitIgnoreSpecPattern(raw_pattern)
936+
self.assertIs(pattern.include, None)
937+
self.assertIs(pattern.regex.pattern, None)
920938

921-
def test_15_issue_93_c_2(self):
939+
def test_15_issue_93_c_3_unclosed(self):
922940
"""
923-
Test patterns with invalid range notation.
941+
Test patterns with unclosed range notations.
924942
"""
925-
# TODO BUG: This test is a placeholder for the current behavior. Git behaves
926-
# differently for this scenario.
943+
# TODO BUG: These tests need to pass.
927944
# - See <https://github.com/cpburnz/python-pathspec/issues/93>.
928-
pattern = GitIgnoreSpecPattern('[!]')
929-
self.assertIs(pattern.include, True)
930-
self.assertEqual(pattern.regex.pattern, f'^(?:.+/)?\\[!\\]{_DIR_MARK_OPT}')
945+
for raw_pattern in [
946+
'[!',
947+
'[-',
948+
'[a',
949+
'[a-',
950+
'[a-z',
951+
'a[',
952+
'a[-',
953+
'a[a-',
954+
'a[a-z',
955+
]:
956+
with self.subTest(f"p={raw_pattern!r}"):
957+
pattern = GitIgnoreSpecPattern(raw_pattern)
958+
self.assertIs(pattern.include, None)
959+
self.assertIs(pattern.regex.pattern, None)

0 commit comments

Comments
 (0)