@@ -1251,84 +1251,8 @@ describe('XRegExp.replace()', function() {
12511251 expect ( function ( ) { XRegExp . replace ( 'test' , XRegExp ( '(?<test>t)' , 'g' ) , ':$<x>:' ) ; } ) . toThrowError ( SyntaxError ) ;
12521252 } ) ;
12531253
1254- } ) ;
1255-
1256- describe ( 'explicit numbered backreferences' , function ( ) {
1257-
1258- it ( 'should return the numbered backreference' , function ( ) {
1259- expect ( XRegExp . replace ( 'test' , / ( .) ./ g, '${1}' ) ) . toBe ( 'ts' ) ;
1260- expect ( XRegExp . replace ( 'test' , / ( .) ./ g, '$<1>' ) ) . toBe ( 'ts' ) ;
1261-
1262- // Backreference to a nonparticipating capturing group
1263- expect ( XRegExp . replace ( 'test' , / t | ( e ) / g, '${1}' ) ) . toBe ( 'es' ) ;
1264- expect ( XRegExp . replace ( 'test' , / t | ( e ) / g, '$<1>' ) ) . toBe ( 'es' ) ;
1265- } ) ;
1266-
1267- it ( 'should allow leading zeros' , function ( ) {
1268- expect ( XRegExp . replace ( 'test' , / ( .) ./ g, '${01}' ) ) . toBe ( 'ts' ) ;
1269- expect ( XRegExp . replace ( 'test' , / ( .) ./ g, '$<01>' ) ) . toBe ( 'ts' ) ;
1270-
1271- expect ( XRegExp . replace ( 'test' , / ( .) ./ g, '${001}' ) ) . toBe ( 'ts' ) ;
1272- expect ( XRegExp . replace ( 'test' , / ( .) ./ g, '$<001>' ) ) . toBe ( 'ts' ) ;
1273- } ) ;
1274-
1275- it ( 'should return named backreferences by number' , function ( ) {
1276- expect ( XRegExp . replace ( 'test' , XRegExp ( '(?<name>.).' , 'g' ) , '${1}' ) ) . toBe ( 'ts' ) ;
1277- expect ( XRegExp . replace ( 'test' , XRegExp ( '(?<name>.).' , 'g' ) , '$<1>' ) ) . toBe ( 'ts' ) ;
1278- } ) ;
1279-
1280- it ( 'should separate numbered backreferences from following literal digits' , function ( ) {
1281- expect ( XRegExp . replace ( 'test' , new RegExp ( '(.).' , 'g' ) , '${1}0' ) ) . toBe ( 't0s0' ) ;
1282- expect ( XRegExp . replace ( 'test' , new RegExp ( '(.).' , 'g' ) , '$<1>0' ) ) . toBe ( 't0s0' ) ;
1283-
1284- expect ( XRegExp . replace ( 'test' , new RegExp ( '(.).' + '()' . repeat ( 9 ) , 'g' ) , '${1}0' ) ) . toBe ( 't0s0' ) ;
1285- expect ( XRegExp . replace ( 'test' , new RegExp ( '(.).' + '()' . repeat ( 9 ) , 'g' ) , '$<1>0' ) ) . toBe ( 't0s0' ) ;
1286- } ) ;
1287-
1288- it ( 'should throw an exception for backreferences to unknown group numbers' , function ( ) {
1289- expect ( function ( ) { XRegExp . replace ( 'test' , / t / , '${1}' ) ; } ) . toThrowError ( SyntaxError ) ;
1290- expect ( function ( ) { XRegExp . replace ( 'test' , / t / , '$<1>' ) ; } ) . toThrowError ( SyntaxError ) ;
1291-
1292- expect ( function ( ) { XRegExp . replace ( 'test' , / ( t ) / , '${2}' ) ; } ) . toThrowError ( SyntaxError ) ;
1293- expect ( function ( ) { XRegExp . replace ( 'test' , / ( t ) / , '$<2>' ) ; } ) . toThrowError ( SyntaxError ) ;
1294- } ) ;
1295-
1296- it ( 'should allow ${0} to refer to the entire match' , function ( ) {
1297- expect ( XRegExp . replace ( 'test' , / ../ g, '${0}:' ) ) . toBe ( 'te:st:' ) ;
1298- expect ( XRegExp . replace ( 'test' , / ../ g, '$<0>:' ) ) . toBe ( 'te:st:' ) ;
1299-
1300- expect ( XRegExp . replace ( 'test' , / ../ g, '${00}:' ) ) . toBe ( 'te:st:' ) ;
1301- expect ( XRegExp . replace ( 'test' , / ../ g, '$<00>:' ) ) . toBe ( 'te:st:' ) ;
1302-
1303- expect ( XRegExp . replace ( 'test' , / ../ g, '${000}:' ) ) . toBe ( 'te:st:' ) ;
1304- expect ( XRegExp . replace ( 'test' , / ../ g, '$<000>:' ) ) . toBe ( 'te:st:' ) ;
1305- } ) ;
1306-
1307- it ( 'should support backreferences 100 and greater, if the browser does natively' , function ( ) {
1308- // IE < 9 doesn't allow backreferences greater than \99 *within* a regex, but
1309- // XRegExp still allows backreferences to groups 100+ within replacement text
1310- try {
1311- // Regex with 1,000 capturing groups. This fails in Firefox 4-6 (but not v3.6
1312- // or v7+) with `InternalError: regular expression too complex`
1313- var lottaGroups = new RegExp ( [
1314- '^(a)\\1' , '()' . repeat ( 8 ) ,
1315- '(b)\\10' , '()' . repeat ( 89 ) ,
1316- '(c)' , '()' . repeat ( 899 ) ,
1317- '(d)$'
1318- ] . join ( '' ) ) ;
1319-
1320- expect ( XRegExp . replace ( 'aabbcd' , lottaGroups , '${0} ${01} ${001} ${0001} ${1} ${10} ${100} ${1000}' ) ) . toBe ( 'aabbcd a a a a b c d' ) ;
1321- expect ( XRegExp . replace ( 'aabbcd' , lottaGroups , '$<0> $<01> $<001> $<0001> $<1> $<10> $<100> $<1000>' ) ) . toBe ( 'aabbcd a a a a b c d' ) ;
1322- expect ( XRegExp . replace ( 'aabbcd' , lottaGroups , '$<0> ${01} $<001> ${0001} $<1> ${10} $<100> ${1000}' ) ) . toBe ( 'aabbcd a a a a b c d' ) ;
1323- // For comparison...
1324- expect ( XRegExp . replace ( 'aabbcd' , lottaGroups , '$0 $01 $001 $0001 $1 $10 $100 $1000' ) ) . toBe ( 'aabbcd a aabbcd1 aabbcd01 a b b0 b00' ) ;
1325- } catch ( err ) {
1326- // Keep the assertion count consistent cross-browser
1327- expect ( true ) . toBe ( true ) ;
1328- expect ( true ) . toBe ( true ) ;
1329- expect ( true ) . toBe ( true ) ;
1330- expect ( true ) . toBe ( true ) ;
1331- }
1254+ it ( 'should not allow leading digits' , function ( ) {
1255+ expect ( function ( ) { XRegExp . replace ( 'test' , / ( .) ./ g, '${01}' ) ; } ) . toThrowError ( SyntaxError ) ;
13321256 } ) ;
13331257
13341258 } ) ;
0 commit comments