@@ -50,14 +50,12 @@ fn lookbehind_grouping_single_expression() {
5050
5151#[ test]
5252fn lookbehind_variable_sized_alt ( ) {
53+ // These get compiled into multiple alternative lookbehinds
5354 assert_eq ! ( find( r"(?<=a|bc)" , "xxa" ) , Some ( ( 3 , 3 ) ) ) ;
5455 assert_eq ! ( find( r"(?<=a|bc)" , "xxbc" ) , Some ( ( 4 , 4 ) ) ) ;
5556 assert_eq ! ( find( r"(?<=a|bc)" , "xx" ) , None ) ;
5657 assert_eq ! ( find( r"(?<=a|bc)" , "xxb" ) , None ) ;
5758 assert_eq ! ( find( r"(?<=a|bc)" , "xxc" ) , None ) ;
58-
59- assert ! ( Regex :: new( r"(?<=a(?:b|cd))" ) . is_err( ) ) ;
60- assert ! ( Regex :: new( r"(?<=a+b+))" ) . is_err( ) ) ;
6159}
6260
6361#[ test]
@@ -69,9 +67,49 @@ fn negative_lookbehind_variable_sized_alt() {
6967 assert_eq ! ( find( r"(?<!a|bc)x" , "cx" ) , Some ( ( 1 , 2 ) ) ) ;
7068 assert_eq ! ( find( r"(?<!a|bc)x" , "ax" ) , None ) ;
7169 assert_eq ! ( find( r"(?<!a|bc)x" , "bcx" ) , None ) ;
70+ }
71+
72+ #[ test]
73+ #[ cfg( feature = "variable-lookbehinds" ) ]
74+ fn lookbehind_positive_variable_sized_functionality ( ) {
75+ assert_eq ! ( find( r"(?<=a(?:b|cd))x" , "abx" ) , Some ( ( 2 , 3 ) ) ) ;
76+ assert_eq ! ( find( r"(?<=a(?:b|cd))x" , "acdx" ) , Some ( ( 3 , 4 ) ) ) ;
77+ assert_eq ! ( find( r"(?<=a(?:b|cd))x" , "ax" ) , None ) ;
78+ assert_eq ! ( find( r"(?<=a(?:b|cd))x" , "bcx" ) , None ) ;
79+
80+ assert_eq ! ( find( r"(?<=a+b+)x" , "abx" ) , Some ( ( 2 , 3 ) ) ) ;
81+ assert_eq ! ( find( r"(?<=a+b+)x" , "aabbx" ) , Some ( ( 4 , 5 ) ) ) ;
82+ assert_eq ! ( find( r"(?<=a+b+)x" , "aaabbbx" ) , Some ( ( 6 , 7 ) ) ) ;
83+ assert_eq ! ( find( r"(?<=a+b+)x" , "ax" ) , None ) ;
84+ assert_eq ! ( find( r"(?<=a+b+)x" , "bx" ) , None ) ;
85+ assert_eq ! ( find( r"(?<=a+b+)x" , "abcx" ) , None ) ;
86+ assert_eq ! ( find( r"(?<=a+b+)c" , "bc aabbc" ) , Some ( ( 7 , 8 ) ) ) ;
87+
88+ assert_eq ! ( find( r"\b(?<=\|\s{0,9})(?:[gG]pu)\b" , "|gpu" ) , Some ( ( 1 , 4 ) ) ) ;
89+ assert_eq ! (
90+ find( r"\b(?<=\|\s{0,9})(?:[gG]pu)\b" , "| gpu" ) ,
91+ Some ( ( 3 , 6 ) )
92+ ) ;
93+ }
94+
95+ #[ test]
96+ #[ cfg( feature = "variable-lookbehinds" ) ]
97+ fn lookbehind_negative_variable_sized_functionality ( ) {
98+ assert_eq ! ( find( r"(?<!a(?:b|cd))x" , "abx" ) , None ) ;
99+ assert_eq ! ( find( r"(?<!a(?:b|cd))x" , "acdx" ) , None ) ;
100+ assert_eq ! ( find( r"(?<!a(?:b|cd))x" , "ax" ) , Some ( ( 1 , 2 ) ) ) ;
101+ assert_eq ! ( find( r"(?<!a(?:b|cd))x" , "bcx" ) , Some ( ( 2 , 3 ) ) ) ;
102+
103+ assert_eq ! ( find( r"(?<!a+b+)x" , "abx" ) , None ) ;
104+ assert_eq ! ( find( r"(?<!a+b+)x" , "aabbx" ) , None ) ;
105+ assert_eq ! ( find( r"(?<!a+b+)x" , "aaabbbx" ) , None ) ;
106+ assert_eq ! ( find( r"(?<!a+b+)x" , "ax" ) , Some ( ( 1 , 2 ) ) ) ;
107+ assert_eq ! ( find( r"(?<!a+b+)x" , "bx" ) , Some ( ( 1 , 2 ) ) ) ;
108+ assert_eq ! ( find( r"(?<!a+b+)x" , "abcx" ) , Some ( ( 3 , 4 ) ) ) ;
109+ assert_eq ! ( find( r"(?<!a+b+)c" , "aabbc bc" ) , Some ( ( 7 , 8 ) ) ) ;
72110
73- assert ! ( Regex :: new ( r"(?<!a (?:b|cd))" ) . is_err ( ) ) ;
74- assert ! ( Regex :: new ( r"(?<!a+b+)" ) . is_err ( ) ) ;
111+ assert_eq ! ( find ( r"\b (?<!\|\s{0,9}) (?:[gG]pu)\b" , "|gpu" ) , None ) ;
112+ assert_eq ! ( find ( r"\b (?<!\|\s{0,9})(?:[gG]pu)\b" , "| gpu" ) , None ) ;
75113}
76114
77115#[ test]
0 commit comments