Initial add; see Bugzilla bug 61266 -

This commit is contained in:
pschwartau%netscape.com 2000-12-01 20:20:43 +00:00
parent 482fa18cd7
commit aa456cab4f
7 changed files with 833 additions and 0 deletions

View File

@ -0,0 +1,115 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 26 November 2000
*
*
* SUMMARY: Passing (RegExp object, flag) to RegExp() function.
* This test arose from Bugzilla bug 61266. The ECMA3 section is:
*
* 15.10.3 The RegExp Constructor Called as a Function
*
* 15.10.3.1 RegExp(pattern, flags)
*
* If pattern is an object R whose [[Class]] property is "RegExp"
* and flags is undefined, then return R unchanged. Otherwise
* call the RegExp constructor (section 15.10.4.1), passing it the
* pattern and flags arguments and return the object constructed
* by that constructor.
*
*
* The current test will check the first scenario outlined above:
*
* "pattern" is itself a RegExp object R
* "flags" is undefined
*
* The flags parameter will be undefined in the sense of not being
* provided. We check that RegExp(R) returns R -
*/
//-------------------------------------------------------------------------------------------------
var bug = '61266';
var summary = 'Passing (RegExp object,flag) to RegExp() function';
var statprefix = 'RegExp(new RegExp(';
var comma = ', '; var singlequote = "'"; var closeparens = '))';
var cnSUCCESS = 'RegExp() returned the supplied RegExp object';
var cnFAILURE = 'RegExp() did NOT return the supplied RegExp object';
var i = -1; var j = -1; var s = ''; var f = '';
var obj = {};
var status = ''; var actual = ''; var expect = '';
var match = new Array();
var flag = new Array();
// various regular expressions to try -
match[0] = '';
match[1] = 'abc';
match[2] = '(.*)(3-1)\s\w';
match[3] = '(.*)(...)\\s\\w';
match[4] = '[^A-Za-z0-9_]';
match[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
// various flags to try -
flag[0] = 'i';
flag[1] = 'g';
flag[2] = 'm';
flag[3] = undefined;
//-------------------------------------------------------------------------------------------------
test();
//-------------------------------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (i in match)
{
s = match[i];
for (j in flag)
{
f = flag[j];
status = getStatus(s, f);
obj = new RegExp(s, f);
actual = (obj == RegExp(obj))? cnSUCCESS : cnFAILURE;
expect = cnSUCCESS;
reportCompare (expect, actual, status);
}
}
exitFunc ('test');
}
function getStatus(regexp, flag)
{
return (statprefix + quote(regexp) + comma + flag + closeparens);
}
function quote(text)
{
return (singlequote + text + singlequote);
}

View File

@ -0,0 +1,123 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 26 November 2000
*
*
* SUMMARY: Passing (RegExp object, flag) to RegExp() function.
* This test arose from Bugzilla bug 61266. The ECMA3 section is:
*
* 15.10.3 The RegExp Constructor Called as a Function
*
* 15.10.3.1 RegExp(pattern, flags)
*
* If pattern is an object R whose [[Class]] property is "RegExp"
* and flags is undefined, then return R unchanged. Otherwise
* call the RegExp constructor (section 15.10.4.1), passing it the
* pattern and flags arguments and return the object constructed
* by that constructor.
*
*
* The current test will check the first scenario outlined above:
*
* "pattern" is itself a RegExp object R
* "flags" is undefined
*
* This test is identical to test 15.10.3.1-1.js, except here we do:
*
* RegExp(R, undefined);
*
* instead of:
*
* RegExp(R);
*
*
* We check that RegExp(R, undefined) returns R -
*/
//-------------------------------------------------------------------------------------------------
var bug = '61266';
var summary = 'Passing (RegExp object,flag) to RegExp() function';
var statprefix = 'RegExp(new RegExp(';
var comma = ', '; var singlequote = "'"; var closeparens = '))';
var cnSUCCESS = 'RegExp() returned the supplied RegExp object';
var cnFAILURE = 'RegExp() did NOT return the supplied RegExp object';
var i = -1; var j = -1; var s = ''; var f = '';
var obj = {};
var status = ''; var actual = ''; var expect = '';
var match = new Array();
var flag = new Array();
// various regular expressions to try -
match[0] = '';
match[1] = 'abc';
match[2] = '(.*)(3-1)\s\w';
match[3] = '(.*)(...)\\s\\w';
match[4] = '[^A-Za-z0-9_]';
match[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
// various flags to try -
flag[0] = 'i';
flag[1] = 'g';
flag[2] = 'm';
flag[3] = undefined;
//-------------------------------------------------------------------------------------------------
test();
//-------------------------------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (i in match)
{
s = match[i];
for (j in flag)
{
f = flag[j];
status = getStatus(s, f);
obj = new RegExp(s, f);
actual = (obj == RegExp(obj, undefined))? cnSUCCESS : cnFAILURE ;
expect = cnSUCCESS;
reportCompare (expect, actual, status);
}
}
exitFunc ('test');
}
function getStatus(regexp, flag)
{
return (statprefix + quote(regexp) + comma + flag + closeparens);
}
function quote(text)
{
return (singlequote + text + singlequote);
}

View File

@ -0,0 +1,111 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 26 November 2000
*
*
*SUMMARY: Passing a RegExp object to a RegExp() constructor.
*This test arose from Bugzilla bug 61266. The ECMA3 section is:
*
* 15.10.4.1 new RegExp(pattern, flags)
*
* If pattern is an object R whose [[Class]] property is "RegExp" and
* flags is undefined, then let P be the pattern used to construct R
* and let F be the flags used to construct R. If pattern is an object R
* whose [[Class]] property is "RegExp" and flags is not undefined,
* then throw a TypeError exception. Otherwise, let P be the empty string
* if pattern is undefined and ToString(pattern) otherwise, and let F be
* the empty string if flags is undefined and ToString(flags) otherwise.
*
*
*The current test will check the first scenario outlined above:
*
* "pattern" is itself a RegExp object R
* "flags" is undefined
*
* We check that a new RegExp object obj2 defined from these parameters
* is morally the same as the original RegExp object obj1. Of course, they
* can't be equal as objects - so we check their enumerable properties...
*
* In this test, the initial RegExp object obj1 will not include a flag. The flags
* parameter for obj2 will be undefined in the sense of not being provided.
*/
//-------------------------------------------------------------------------------------------------
var bug = '61266';
var summary = 'Passing a RegExp object to a RegExp() constructor';
var statprefix = 'Applying RegExp() twice to pattern ';
var statsuffix = '; testing property ';
var singlequote = "'";
var i = -1; var s = '';
var obj1 = {}; var obj2 = {};
var status = ''; var actual = ''; var expect = ''; var msg = '';
var match = new Array();
// various regular expressions to try -
match[0] = '';
match[1] = 'abc';
match[2] = '(.*)(3-1)\s\w';
match[3] = '(.*)(...)\\s\\w';
match[4] = '[^A-Za-z0-9_]';
match[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
//-------------------------------------------------------------------------------------------------
test();
//-------------------------------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (i in match)
{
s = match[i];
status =getStatus(s);
obj1 = new RegExp(s);
obj2 = new RegExp(obj1);
for (prop in obj2)
{
msg = status + quote(prop);
actual = obj2[prop];
expect = obj1[prop];
reportCompare (expect, actual, msg);
}
}
exitFunc ('test');
}
function getStatus(regexp)
{
return (statprefix + quote(regexp) + statsuffix);
}
function quote(text)
{
return (singlequote + text + singlequote);
}

View File

@ -0,0 +1,117 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 26 November 2000
*
*
*SUMMARY: Passing a RegExp object to a RegExp() constructor.
*This test arose from Bugzilla bug 61266. The ECMA3 section is:
*
* 15.10.4.1 new RegExp(pattern, flags)
*
* If pattern is an object R whose [[Class]] property is "RegExp" and
* flags is undefined, then let P be the pattern used to construct R
* and let F be the flags used to construct R. If pattern is an object R
* whose [[Class]] property is "RegExp" and flags is not undefined,
* then throw a TypeError exception. Otherwise, let P be the empty string
* if pattern is undefined and ToString(pattern) otherwise, and let F be
* the empty string if flags is undefined and ToString(flags) otherwise.
*
*
*The current test will check the first scenario outlined above:
*
* "pattern" is itself a RegExp object R
* "flags" is undefined
*
* We check that a new RegExp object obj2 defined from these parameters
* is morally the same as the original RegExp object obj1. Of course, they
* can't be equal as objects - so we check their enumerable properties...
*
* In this test, the initial RegExp object obj1 will not include a flag. This test is
* identical to test 15.10.4.1-1.js, except that here we use this syntax:
*
* obj2 = new RegExp(obj1, undefined);
*
* instead of:
*
* obj2 = new RegExp(obj1);
*/
//-------------------------------------------------------------------------------------------------
var bug = '61266';
var summary = 'Passing a RegExp object to a RegExp() constructor';
var statprefix = 'Applying RegExp() twice to pattern ';
var statsuffix = '; testing property ';
var singlequote = "'";
var i = -1; var s = '';
var obj1 = {}; var obj2 = {};
var status = ''; var actual = ''; var expect = ''; var msg = '';
var match = new Array();
// various regular expressions to try -
match[0] = '';
match[1] = 'abc';
match[2] = '(.*)(3-1)\s\w';
match[3] = '(.*)(...)\\s\\w';
match[4] = '[^A-Za-z0-9_]';
match[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
//-------------------------------------------------------------------------------------------------
test();
//-------------------------------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (i in match)
{
s = match[i];
status =getStatus(s);
obj1 = new RegExp(s);
obj2 = new RegExp(obj1, undefined); // see introduction to bug
for (prop in obj2)
{
msg = status + quote(prop);
actual = obj2[prop];
expect = obj1[prop];
reportCompare (expect, actual, msg);
}
}
exitFunc ('test');
}
function getStatus(regexp)
{
return (statprefix + quote(regexp) + statsuffix);
}
function quote(text)
{
return (singlequote + text + singlequote);
}

View File

@ -0,0 +1,124 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 26 November 2000
*
*
*SUMMARY: Passing a RegExp object to a RegExp() constructor.
*This test arose from Bugzilla bug 61266. The ECMA3 section is:
*
* 15.10.4.1 new RegExp(pattern, flags)
*
* If pattern is an object R whose [[Class]] property is "RegExp" and
* flags is undefined, then let P be the pattern used to construct R
* and let F be the flags used to construct R. If pattern is an object R
* whose [[Class]] property is "RegExp" and flags is not undefined,
* then throw a TypeError exception. Otherwise, let P be the empty string
* if pattern is undefined and ToString(pattern) otherwise, and let F be
* the empty string if flags is undefined and ToString(flags) otherwise.
*
*
*The current test will check the first scenario outlined above:
*
* "pattern" is itself a RegExp object R
* "flags" is undefined
*
* We check that a new RegExp object obj2 defined from these parameters
* is morally the same as the original RegExp object obj1. Of course, they
* can't be equal as objects - so we check their enumerable properties...
*
* In this test, the initial RegExp obj1 will include a flag. The flags
* parameter for obj2 will be undefined in the sense of not being provided.
*/
//-------------------------------------------------------------------------------------------------
var bug = '61266';
var summary = 'Passing a RegExp object to a RegExp() constructor';
var statprefix = 'Applying RegExp() twice to pattern ';
var statmiddle = ' and flag ';
var statsuffix = '; testing property ';
var singlequote = "'";
var i = -1; var j = -1; var s = '';
var obj1 = {}; var obj2 = {};
var status = ''; var actual = ''; var expect = ''; var msg = '';
var match = new Array();
var flag = new Array();
// various regular expressions to try -
match[0] = '';
match[1] = 'abc';
match[2] = '(.*)(3-1)\s\w';
match[3] = '(.*)(...)\\s\\w';
match[4] = '[^A-Za-z0-9_]';
match[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
// various flags to try -
flag[0] = 'i';
flag[1] = 'g';
flag[2] = 'm';
flag[3] = undefined;
//-------------------------------------------------------------------------------------------------
test();
//-------------------------------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (i in match)
{
s = match[i];
for (j in flag)
{
f = flag[j];
status = getStatus(s, f);
obj1 = new RegExp(s, f);
obj2 = new RegExp(obj1);
for (prop in obj2)
{
msg = status + quote(prop);
actual = obj2[prop];
expect = obj1[prop];
reportCompare (expect, actual, msg);
}
}
}
exitFunc ('test');
}
function getStatus(regexp, flag)
{
return (statprefix + quote(regexp) + statmiddle + flag + statsuffix);
}
function quote(text)
{
return (singlequote + text + singlequote);
}

View File

@ -0,0 +1,130 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 26 November 2000
*
*
*SUMMARY: Passing a RegExp object to a RegExp() constructor.
*This test arose from Bugzilla bug 61266. The ECMA3 section is:
*
* 15.10.4.1 new RegExp(pattern, flags)
*
* If pattern is an object R whose [[Class]] property is "RegExp" and
* flags is undefined, then let P be the pattern used to construct R
* and let F be the flags used to construct R. If pattern is an object R
* whose [[Class]] property is "RegExp" and flags is not undefined,
* then throw a TypeError exception. Otherwise, let P be the empty string
* if pattern is undefined and ToString(pattern) otherwise, and let F be
* the empty string if flags is undefined and ToString(flags) otherwise.
*
*
*The current test will check the first scenario outlined above:
*
* "pattern" is itself a RegExp object R
* "flags" is undefined
*
* We check that a new RegExp object obj2 defined from these parameters
* is morally the same as the original RegExp object obj1. Of course, they
* can't be equal as objects - so we check their enumerable properties...
*
* In this test, the initial RegExp object obj1 will include a flag. This test is
* identical to test 15.10.4.1-3.js, except that here we use this syntax:
*
* obj2 = new RegExp(obj1, undefined);
*
* instead of:
*
* obj2 = new RegExp(obj1);
*/
//-------------------------------------------------------------------------------------------------
var bug = '61266';
var summary = 'Passing a RegExp object to a RegExp() constructor';
var statprefix = 'Applying RegExp() twice to pattern ';
var statmiddle = ' and flag ';
var statsuffix = '; testing property ';
var singlequote = "'";
var i = -1; var j = -1; var s = '';
var obj1 = {}; var obj2 = {};
var status = ''; var actual = ''; var expect = ''; var msg = '';
var match = new Array();
var flag = new Array();
// various regular expressions to try -
match[0] = '';
match[1] = 'abc';
match[2] = '(.*)(3-1)\s\w';
match[3] = '(.*)(...)\\s\\w';
match[4] = '[^A-Za-z0-9_]';
match[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
// various flags to try -
flag[0] = 'i';
flag[1] = 'g';
flag[2] = 'm';
flag[3] = undefined;
//-------------------------------------------------------------------------------------------------
test();
//-------------------------------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (i in match)
{
s = match[i];
for (j in flag)
{
f = flag[j];
status = getStatus(s, f);
obj1 = new RegExp(s, f);
obj2 = new RegExp(obj1, undefined); // see introduction to bug
for (prop in obj2)
{
msg = status + quote(prop);
actual = obj2[prop];
expect = obj1[prop];
reportCompare (expect, actual, msg);
}
}
}
exitFunc ('test');
}
function getStatus(regexp, flag)
{
return (statprefix + quote(regexp) + statmiddle + flag + statsuffix);
}
function quote(text)
{
return (singlequote + text + singlequote);
}

View File

@ -0,0 +1,113 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 26 November 2000
*
*
*SUMMARY: Passing a RegExp object to a RegExp() constructor.
*This test arose from Bugzilla bug 61266. The ECMA3 section is:
*
* 15.10.4.1 new RegExp(pattern, flags)
*
* If pattern is an object R whose [[Class]] property is "RegExp" and
* flags is undefined, then let P be the pattern used to construct R
* and let F be the flags used to construct R. If pattern is an object R
* whose [[Class]] property is "RegExp" and flags is not undefined,
* then throw a TypeError exception. Otherwise, let P be the empty string
* if pattern is undefined and ToString(pattern) otherwise, and let F be
* the empty string if flags is undefined and ToString(flags) otherwise.
*
*
*The current test will check the second scenario outlined above:
*
* "pattern" is itself a RegExp object R
* "flags" is NOT undefined
*
* This should throw an exception ... we test for this.
*
*/
//-------------------------------------------------------------------------------------------------
var bug = '61266';
var summary = 'Negative test: Passing (RegExp object, flag) to RegExp() constructor';
var statprefix = 'Passing RegExp object on pattern ';
var statsuffix = '; passing flag ';
var cnFAILURE = 'Expected an exception to be thrown, but none was -';
var singlequote = "'";
var i = -1; var j = -1; var s = ''; var f = '';
var obj1 = {}; var obj2 = {};
var match = new Array();
var flag = new Array();
// various regular expressions to try -
match[0] = '';
match[1] = 'abc';
match[2] = '(.*)(3-1)\s\w';
match[3] = '(.*)(...)\\s\\w';
match[4] = '[^A-Za-z0-9_]';
match[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
// various flags to try -
flag[0] = 'i';
flag[1] = 'g';
flag[2] = 'm';
//-------------------------------------------------------------------------------------------------
test();
//-------------------------------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (i in match)
{
s = match[i];
for (j in flag)
{
f = flag[j];
printStatus(getStatus(s, f));
obj1 = new RegExp(s, f);
obj2 = new RegExp(obj1, f); // this should cause an exception
// WE SHOULD NEVER REACH THIS POINT -
reportFailure(cnFAILURE);
}
}
exitFunc ('test');
}
function getStatus(regexp, flag)
{
return (statprefix + quote(regexp) + statsuffix + flag);
}
function quote(text)
{
return (singlequote + text + singlequote);
}