michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Date: 26 November 2000 michael@0: * michael@0: * michael@0: *SUMMARY: Passing a RegExp object to a RegExp() constructor. michael@0: *This test arose from Bugzilla bug 61266. The ECMA3 section is: michael@0: * michael@0: * 15.10.4.1 new RegExp(pattern, flags) michael@0: * michael@0: * If pattern is an object R whose [[Class]] property is "RegExp" and michael@0: * flags is undefined, then let P be the pattern used to construct R michael@0: * and let F be the flags used to construct R. If pattern is an object R michael@0: * whose [[Class]] property is "RegExp" and flags is not undefined, michael@0: * then throw a TypeError exception. Otherwise, let P be the empty string michael@0: * if pattern is undefined and ToString(pattern) otherwise, and let F be michael@0: * the empty string if flags is undefined and ToString(flags) otherwise. michael@0: * michael@0: * michael@0: *The current test will check the first scenario outlined above: michael@0: * michael@0: * "pattern" is itself a RegExp object R michael@0: * "flags" is undefined michael@0: * michael@0: * We check that a new RegExp object obj2 defined from these parameters michael@0: * is morally the same as the original RegExp object obj1. Of course, they michael@0: * can't be equal as objects - so we check their enumerable properties... michael@0: * michael@0: * In this test, the initial RegExp obj1 will include a flag. The flags michael@0: * parameter for obj2 will be undefined in the sense of not being provided. michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = '61266'; michael@0: var summary = 'Passing a RegExp object to a RegExp() constructor'; michael@0: var statprefix = 'Applying RegExp() twice to pattern '; michael@0: var statmiddle = ' and flag '; michael@0: var statsuffix = '; testing property '; michael@0: var singlequote = "'"; michael@0: var i = -1; var j = -1; var s = ''; michael@0: var obj1 = {}; var obj2 = {}; michael@0: var status = ''; var actual = ''; var expect = ''; var msg = ''; michael@0: var patterns = new Array(); michael@0: var flags = new Array(); michael@0: michael@0: michael@0: // various regular expressions to try - michael@0: patterns[0] = ''; michael@0: patterns[1] = 'abc'; michael@0: patterns[2] = '(.*)(3-1)\s\w'; michael@0: patterns[3] = '(.*)(...)\\s\\w'; michael@0: patterns[4] = '[^A-Za-z0-9_]'; michael@0: patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)'; michael@0: michael@0: // various flags to try - michael@0: flags[0] = 'i'; michael@0: flags[1] = 'g'; michael@0: flags[2] = 'm'; michael@0: flags[3] = undefined; michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------------------------- michael@0: test(); michael@0: //------------------------------------------------------------------------------------------------- michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: for (i in patterns) michael@0: { michael@0: s = patterns[i]; michael@0: michael@0: for (j in flags) michael@0: { michael@0: f = flags[j]; michael@0: status = getStatus(s, f); michael@0: obj1 = new RegExp(s, f); michael@0: obj2 = new RegExp(obj1); michael@0: michael@0: reportCompare (obj1 + '', obj2 + '', status); michael@0: } michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: } michael@0: michael@0: michael@0: function getStatus(regexp, flag) michael@0: { michael@0: return (statprefix + quote(regexp) + statmiddle + flag + statsuffix); michael@0: } michael@0: michael@0: michael@0: function quote(text) michael@0: { michael@0: return (singlequote + text + singlequote); michael@0: }