зеркало из https://github.com/mozilla/gecko-dev.git
Exported functionality common to RegExp testing to new file js/tests/ecma_3/RegExp/shell.js
This commit is contained in:
Родитель
766e838c4f
Коммит
5cc9cfb919
|
@ -19,76 +19,74 @@
|
||||||
* Contributor(s): pschwartau@netscape.com
|
* Contributor(s): pschwartau@netscape.com
|
||||||
* Date: 28 December 2000
|
* Date: 28 December 2000
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* SUMMARY: Testing regular expressions containing the ? character.
|
* SUMMARY: Testing regular expressions containing the ? character.
|
||||||
* Arose from Bugzilla bug 57572: "RegExp with ? matches incorrectly"
|
* Arose from Bugzilla bug 57572: "RegExp with ? matches incorrectly"
|
||||||
*
|
*
|
||||||
|
* See http://bugzilla.mozilla.org/show_bug.cgi?id=57572
|
||||||
*/
|
*/
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
var bug = 57572;
|
var bug = 57572;
|
||||||
var summary = 'Testing regular expressions containing "?"';
|
var summary = 'Testing regular expressions containing "?"\n';
|
||||||
var statprefix = 'regexp = '; var statmiddle = ', string = '; var statsuffix = ', $=';
|
var cnEmptyString = ''; var cnSingleSpace = ' ';
|
||||||
var cnSingleQuote = "'"; var cnEmptyString = ''; var cnSingleSpace = ' ';
|
|
||||||
var i = -1; var j = -1;
|
|
||||||
var pattern = ''; var patterns = new Array();
|
var pattern = ''; var patterns = new Array();
|
||||||
var string = ''; var strings = new Array();
|
var string = ''; var strings = new Array();
|
||||||
var actual = ''; var actuals = new Array();
|
var actualmatch = ''; var actualmatches = new Array();
|
||||||
var expect = ''; expects = new Array();
|
var expectedmatch = ''; var expectedmatches = new Array();
|
||||||
|
|
||||||
|
|
||||||
pattern = /(\S+)?(.*)/;
|
pattern = /(\S+)?(.*)/;
|
||||||
string = 'Test this';
|
string = 'Test this';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, 'Test', ' this'); //single space in front of 'this'
|
expectedmatch = Array(string, 'Test', ' this'); //single space in front of 'this'
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
pattern = /(\S+)? ?(.*)/; //single space between the ? characters
|
pattern = /(\S+)? ?(.*)/; //single space between the ? characters
|
||||||
string= 'Test this';
|
string= 'Test this';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, 'Test', 'this'); //NO space in front of 'this'
|
expectedmatch = Array(string, 'Test', 'this'); //NO space in front of 'this'
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
pattern = /(\S+)????(.*)/;
|
pattern = /(\S+)????(.*)/;
|
||||||
string= 'Test this';
|
string= 'Test this';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, cnEmptyString, string);
|
expectedmatch = Array(string, cnEmptyString, string);
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
pattern = /(\S+)?(.*)/;
|
pattern = /(\S+)?(.*)/;
|
||||||
string = 'Stupid phrase, with six - (short) words';
|
string = 'Stupid phrase, with six - (short) words';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, 'Stupid', ' phrase, with six - (short) words'); //single space in front of 'phrase'
|
expectedmatch = Array(string, 'Stupid', ' phrase, with six - (short) words'); //single space in front of 'phrase'
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
pattern = /(\S+)? ?(.*)/; //single space between the ? characters
|
pattern = /(\S+)? ?(.*)/; //single space between the ? characters
|
||||||
string = 'Stupid phrase, with six - (short) words';
|
string = 'Stupid phrase, with six - (short) words';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, 'Stupid', 'phrase, with six - (short) words'); //NO space in front of 'phrase'
|
expectedmatch = Array(string, 'Stupid', 'phrase, with six - (short) words'); //NO space in front of 'phrase'
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
// let's add an extra back-reference this time - three instead of two -
|
// let's add an extra back-reference this time - three instead of two -
|
||||||
pattern = /(\S+)?( ?)(.*)/; //single space before second ? character
|
pattern = /(\S+)?( ?)(.*)/; //single space before second ? character
|
||||||
string = 'Stupid phrase, with six - (short) words';
|
string = 'Stupid phrase, with six - (short) words';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, 'Stupid', cnSingleSpace, 'phrase, with six - (short) words');
|
expectedmatch = Array(string, 'Stupid', cnSingleSpace, 'phrase, with six - (short) words');
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
pattern = /^(\S+)?( ?)(B+)$/; //single space before second ? character
|
pattern = /^(\S+)?( ?)(B+)$/; //single space before second ? character
|
||||||
string = 'AAABBB';
|
string = 'AAABBB';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, 'AAABB', cnEmptyString, 'B');
|
expectedmatch = Array(string, 'AAABB', cnEmptyString, 'B');
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
pattern = /(\S+)?(!?)(.*)/;
|
pattern = /(\S+)?(!?)(.*)/;
|
||||||
string = 'WOW !!! !!!';
|
string = 'WOW !!! !!!';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, 'WOW', cnEmptyString, ' !!! !!!');
|
expectedmatch = Array(string, 'WOW', cnEmptyString, ' !!! !!!');
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
pattern = /(.+)?(!?)(!+)/;
|
pattern = /(.+)?(!?)(!+)/;
|
||||||
string = 'WOW !!! !!!';
|
string = 'WOW !!! !!!';
|
||||||
actual = string.match(pattern);
|
actualmatch = string.match(pattern);
|
||||||
expect = Array(string, 'WOW !!! !!', cnEmptyString, '!');
|
expectedmatch = Array(string, 'WOW !!! !!', cnEmptyString, '!');
|
||||||
addThis();
|
addThis();
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,8 +102,8 @@ function addThis()
|
||||||
i++;
|
i++;
|
||||||
patterns[i] = pattern;
|
patterns[i] = pattern;
|
||||||
strings[i] = string;
|
strings[i] = string;
|
||||||
actuals[i] = actual;
|
actualmatches[i] = actualmatch;
|
||||||
expects[i] = expect;
|
expectedmatches[i] = expectedmatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,27 +112,6 @@ function test()
|
||||||
enterFunc ('test');
|
enterFunc ('test');
|
||||||
printBugNumber (bug);
|
printBugNumber (bug);
|
||||||
printStatus (summary);
|
printStatus (summary);
|
||||||
|
testRegExp(patterns, strings, actualmatches, expectedmatches);
|
||||||
for (i=0; i != patterns.length; i++)
|
|
||||||
{
|
|
||||||
// expects[i] and actuals[i] are array objects. Compare them element-by-element -
|
|
||||||
for (j=0; j !=actuals[i].length; j++)
|
|
||||||
{
|
|
||||||
reportCompare (expects[i][j], actuals[i][j], getStatus(i, j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exitFunc ('test');
|
exitFunc ('test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getStatus(i, j)
|
|
||||||
{
|
|
||||||
return (statprefix + quote(patterns[i]) + statmiddle + quote(strings[i]) + statsuffix + j );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function quote(text)
|
|
||||||
{
|
|
||||||
return (cnSingleQuote + text + cnSingleQuote);
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче