Skip to content

Commit dff32fe

Browse files
committed
Update tests to show API changes
1 parent 1e8e3fa commit dff32fe

File tree

2 files changed

+12
-130
lines changed

2 files changed

+12
-130
lines changed

tests/spec/s-xregexp-methods.js

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

tests/spec/s-xregexp.js

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -393,27 +393,24 @@ describe('XRegExp()', function() {
393393
// Named capture *functionality* is tested by the specs for named backreference syntax,
394394
// XRegExp.exec, XRegExp.replace, etc.
395395

396-
it('should allow the characters A-Z, a-z, 0-9, $, and _ to be used in capture names', function() {
396+
it('should allow the characters A-Z, a-z, 0-9, $, _, and RegExpIdentifierName characters to be used in capture names', function() {
397397
expect(XRegExp('(?<Az>x)').test('x')).toBe(true);
398398
expect(XRegExp('(?<_09>x)').test('x')).toBe(true);
399399
expect(XRegExp('(?<$>x)').test('x')).toBe(true);
400+
expect(function() {XRegExp('(?<naïve>)');}).not.toThrow();
401+
expect(function() {XRegExp('(?<Русский>)');}).not.toThrow();
402+
expect(function() {XRegExp('(?<日本語>)');}).not.toThrow();
400403
});
401404

402405
it('should throw an exception if characters other than A-Z, a-z, 0-9, $, and _ are used in capture names', function() {
403406
expect(function() {XRegExp('(?<?>)');}).toThrowError(SyntaxError);
404407
expect(function() {XRegExp('(?<.>)');}).toThrowError(SyntaxError);
405408
expect(function() {XRegExp('(?<<>)');}).toThrowError(SyntaxError);
406409
expect(function() {XRegExp('(?<->)');}).toThrowError(SyntaxError);
407-
// Native named capture uses different allowed chars that XRegExp should be updated to handle
408-
//expect(function() {XRegExp('(?<naïve>)');}).toThrowError(SyntaxError);
409-
//expect(function() {XRegExp('(?<Русский>)');}).toThrowError(SyntaxError);
410-
//expect(function() {XRegExp('(?<日本語>)');}).toThrowError(SyntaxError);
411410
});
412411

413-
it('should allow capture names to start with digits', function() {
414-
expect(XRegExp('(?<0a>x)').test('x')).toBe(true);
415-
expect(XRegExp('(?<1_1>x)').test('x')).toBe(true);
416-
expect(XRegExp('(?<234$>x)').test('x')).toBe(true);
412+
it('should not allow capture names to start with digits', function() {
413+
expect(function() {XRegExp('(?<0a>x)');}).toThrowError(SyntaxError);
417414
});
418415

419416
it('should throw an exception if bare integers are used as capture names', function() {
@@ -488,6 +485,10 @@ describe('XRegExp()', function() {
488485
expect(function() {XRegExp('\\k<`>');}).toThrowError(SyntaxError);
489486
});
490487

488+
it('should not allow leading digits', function() {
489+
expect(function() {XRegExp('(.)\\k<01>');}).toThrowError(SyntaxError);
490+
});
491+
491492
it('should separate backreferences from following literal digits', function() {
492493
expect(XRegExp('(?<$1>A1)(2)(3)(4)(5)(6)(7)(8)(9)(B10)\\k<$1>0').test('A123456789B10A10')).toBe(true);
493494
expect(XRegExp('(?<$1>A)\\k<$1>2').test('AA2')).toBe(true);
@@ -506,49 +507,6 @@ describe('XRegExp()', function() {
506507

507508
});
508509

509-
describe('explicit numbered backreferences', function() {
510-
511-
it('should match the numbered backreference', function() {
512-
expect(XRegExp('(.)\\k<1>').test('aa')).toBe(true);
513-
expect(XRegExp('(.)\\k<1>').test('ab')).toBe(false);
514-
expect(XRegExp('(.)\\k<1>\\k<1>').test('aaa')).toBe(true);
515-
});
516-
517-
it('should allow leading zeros', function() {
518-
expect(XRegExp('(.)\\k<01>').test('aa')).toBe(true);
519-
expect(XRegExp('(.)\\k<001>').test('aa')).toBe(true);
520-
});
521-
522-
it('should match named backreferences by number', function() {
523-
expect(XRegExp('(?<A>.)\\k<1>').test('aa')).toBe(true);
524-
expect(XRegExp('(?<A>.)\\k<1>').test('ab')).toBe(false);
525-
expect(XRegExp('(?<A>.)\\k<1>\\k<1>').test('aaa')).toBe(true);
526-
});
527-
528-
it('should separate numbered backreferences from following literal digits', function() {
529-
expect(XRegExp('(A1)(2)(3)(4)(5)(6)(7)(8)(9)(B10)\\k<1>0').test('A123456789B10A10')).toBe(true);
530-
expect(XRegExp('(A)\\k<1>2').test('AA2')).toBe(true);
531-
});
532-
533-
it('should throw an exception for backreferences to unknown groups', function() {
534-
expect(function() {XRegExp('\\k<1>');}).toThrowError(SyntaxError);
535-
expect(function() {XRegExp('()\\k<2>');}).toThrowError(SyntaxError);
536-
});
537-
538-
it('should throw an exception for backreferences to capturing groups not opened to the left', function() {
539-
expect(function() {XRegExp('\\k<1>()');}).toThrowError(SyntaxError);
540-
expect(function() {XRegExp('()\\k<2>()');}).toThrowError(SyntaxError);
541-
expect(function() {XRegExp('(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)\\k<11>(11)');}).toThrowError(SyntaxError);
542-
expect(function() {XRegExp('(\\k<1>)');}).not.toThrow();
543-
});
544-
545-
it('should not allow \\k<0> to refer to the entire match', function() {
546-
expect(function() {XRegExp('\\k<0>');}).toThrowError(SyntaxError);
547-
expect(function() {XRegExp('\\k<00>');}).toThrowError(SyntaxError);
548-
});
549-
550-
});
551-
552510
describe('strict error handling', function() {
553511

554512
it('should throw an exception for octals except \\0 not followed by 0-9', function() {

0 commit comments

Comments
 (0)