@@ -1113,6 +1113,37 @@ extension RegexTests {
1113
1113
( input: " 23x23 " , match: " 23x23 " ) ,
1114
1114
( input: " 123x23 " , match: " 23x23 " ) ,
1115
1115
xfail: true )
1116
+
1117
+ // Backreferences in lookaheads
1118
+ firstMatchTests (
1119
+ #"^(?=.*(.)(.)\2\1).+$"# ,
1120
+ ( input: " abbba " , match: nil ) ,
1121
+ ( input: " ABBA " , match: " ABBA " ) ,
1122
+ ( input: " defABBAdef " , match: " defABBAdef " ) )
1123
+ firstMatchTests (
1124
+ #"^(?=.*(.)(.)\2\1).+\2$"# ,
1125
+ ( input: " abbba " , match: nil ) ,
1126
+ ( input: " ABBA " , match: nil ) ,
1127
+ ( input: " defABBAdef " , match: nil ) )
1128
+ // FIXME: Backreferences don't escape positive lookaheads
1129
+ firstMatchTests (
1130
+ #"^(?=.*(.)(.)\2\1).+\2$"# ,
1131
+ ( input: " ABBAB " , match: " ABBAB " ) ,
1132
+ ( input: " defABBAdefB " , match: " defABBAdefB " ) ,
1133
+ xfail: true )
1134
+
1135
+ firstMatchTests (
1136
+ #"^(?!.*(.)(.)\2\1).+$"# ,
1137
+ ( input: " abbba " , match: " abbba " ) ,
1138
+ ( input: " ABBA " , match: nil ) ,
1139
+ ( input: " defABBAdef " , match: nil ) )
1140
+ // Backreferences don't escape negative lookaheads;
1141
+ // matching only proceeds when the lookahead fails
1142
+ firstMatchTests (
1143
+ #"^(?!.*(.)(.)\2\1).+\2$"# ,
1144
+ ( input: " abbba " , match: nil ) ,
1145
+ ( input: " abbbab " , match: nil ) ,
1146
+ ( input: " ABBAB " , match: nil ) )
1116
1147
1117
1148
// TODO: Test example where non-atomic is significant
1118
1149
firstMatchTest (
0 commit comments