@@ -907,10 +907,14 @@ def test_15_issue_93_b_2_double(self):
907907
908908 def test_15_issue_93_c_1_valid (self ):
909909 """
910- Test patterns with valid range notations .
910+ Test patterns with valid range notation .
911911 """
912912 for raw_pattern , regex in [
913+ ('[!a-z]' , f'^(?:.+/)?[^a-z]{ _DIR_OPT } ' ),
914+ ('[^a-z]' , f'^(?:.+/)?[^a-z]{ _DIR_OPT } ' ),
913915 ('[a-z]' , f'^(?:.+/)?[a-z]{ _DIR_OPT } ' ),
916+ ('a[!a-z]' , f'^(?:.+/)?a[^a-z]{ _DIR_OPT } ' ),
917+ ('a[^a-z]' , f'^(?:.+/)?a[^a-z]{ _DIR_OPT } ' ),
914918 ('a[a-z]' , f'^(?:.+/)?a[a-z]{ _DIR_OPT } ' ),
915919 ]:
916920 with self .subTest (f"p={ raw_pattern !r} " ):
@@ -920,22 +924,21 @@ def test_15_issue_93_c_1_valid(self):
920924
921925 def test_15_issue_93_c_2_invalid (self ):
922926 """
923- Test patterns with invalid range notations .
927+ Test patterns with invalid range notation .
924928 """
925- # TODO BUG: These tests need to pass.
926- # - See <https://github.com/cpburnz/python-pathspec/issues/93>.
927- for raw_pattern in [
928- '[!]' ,
929- 'a[!]' ,
929+ # The basic pattern treats invalid range notation as a literal.
930+ for raw_pattern , regex in [
931+ ('[!]' , f'^(?:.+/)?\\ [!\\ ]{ _DIR_OPT } ' ),
932+ ('[^]' , f'^(?:.+/)?\\ [\\ ^\\ ]{ _DIR_OPT } ' ),
933+ ('a[!]' , f'^(?:.+/)?a\\ [!\\ ]{ _DIR_OPT } ' ),
934+ ('a[^]' , f'^(?:.+/)?a\\ [\\ ^\\ ]{ _DIR_OPT } ' ),
930935 ]:
931936 with self .subTest (f"p={ raw_pattern !r} " ):
932937 pattern = GitIgnoreBasicPattern (raw_pattern )
933- self .assertIs (pattern .include , None )
934- self .assertIs (pattern .regex , None )
938+ self .assertIs (pattern .include , True )
939+ self .assertEqual (pattern .regex . pattern , regex )
935940
936941 # The `re` module fails to compile these.
937- # - NOTE: Technically, these should result in null patterns rather than
938- # exceptions to fully replicate Git's behavior.
939942 for raw_pattern in [
940943 '[z-a]' ,
941944 'a[z-a]' ,
@@ -946,25 +949,29 @@ def test_15_issue_93_c_2_invalid(self):
946949
947950 def test_15_issue_93_c_3_unclosed (self ):
948951 """
949- Test patterns with unclosed range notations .
952+ Test patterns with unclosed range notation .
950953 """
951954 # TODO BUG: These tests need to pass.
952955 # - See <https://github.com/cpburnz/python-pathspec/issues/93>.
953- for raw_pattern in [
954- '[!' ,
955- '[-' ,
956- '[a' ,
957- '[a-' ,
958- '[a-z' ,
959- 'a[' ,
960- 'a[-' ,
961- 'a[a-' ,
962- 'a[a-z' ,
956+ for raw_pattern , regex in [
957+ ('[!' , f'^(?:.+/)?\\ [!{ _DIR_OPT } ' ),
958+ ('[' , f'^(?:.+/)?\\ [{ _DIR_OPT } ' ),
959+ ('[-' , f'^(?:.+/)?\\ [\\ -{ _DIR_OPT } ' ),
960+ ('[^' , f'^(?:.+/)?\\ [\\ ^{ _DIR_OPT } ' ),
961+ ('[a' , f'^(?:.+/)?\\ [a{ _DIR_OPT } ' ),
962+ ('[a-' , f'^(?:.+/)?\\ [a\\ -{ _DIR_OPT } ' ),
963+ ('[a-z' , f'^(?:.+/)?\\ [a\\ -z{ _DIR_OPT } ' ),
964+ ('a[!' , f'^(?:.+/)?a\\ [!{ _DIR_OPT } ' ),
965+ ('a[' , f'^(?:.+/)?a\\ [{ _DIR_OPT } ' ),
966+ ('a[-' , f'^(?:.+/)?a\\ [\\ -{ _DIR_OPT } ' ),
967+ ('a[^' , f'^(?:.+/)?a\\ [\\ ^{ _DIR_OPT } ' ),
968+ ('a[a-' , f'^(?:.+/)?a\\ [a\\ -{ _DIR_OPT } ' ),
969+ ('a[a-z' , f'^(?:.+/)?a\\ [a\\ -z{ _DIR_OPT } ' ),
963970 ]:
964971 with self .subTest (f"p={ raw_pattern !r} " ):
965972 pattern = GitIgnoreBasicPattern (raw_pattern )
966- self .assertIs (pattern .include , None )
967- self .assertIs (pattern .regex , None )
973+ self .assertIs (pattern .include , True )
974+ self .assertEqual (pattern .regex . pattern , regex )
968975
969976 def test_16_repr_str (self ):
970977 """
0 commit comments