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 (RegExp object, flag) to RegExp() function. michael@0: * This test arose from Bugzilla bug 61266. The ECMA3 section is: michael@0: * michael@0: * 15.10.3 The RegExp Constructor Called as a Function michael@0: * michael@0: * 15.10.3.1 RegExp(pattern, flags) michael@0: * michael@0: * If pattern is an object R whose [[Class]] property is "RegExp" michael@0: * and flags is undefined, then return R unchanged. Otherwise michael@0: * call the RegExp constructor (section 15.10.4.1), passing it the michael@0: * pattern and flags arguments and return the object constructed michael@0: * by that constructor. 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: * The flags parameter will be undefined in the sense of not being michael@0: * provided. We check that RegExp(R) returns R - michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = '61266'; michael@0: var summary = 'Passing (RegExp object,flag) to RegExp() function'; michael@0: var statprefix = 'RegExp(new RegExp('; michael@0: var comma = ', '; var singlequote = "'"; var closeparens = '))'; michael@0: var cnSUCCESS = 'RegExp() returned the supplied RegExp object'; michael@0: var cnFAILURE = 'RegExp() did NOT return the supplied RegExp object'; michael@0: var i = -1; var j = -1; var s = ''; var f = ''; michael@0: var obj = {}; michael@0: var status = ''; var actual = ''; var expect = ''; 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: obj = new RegExp(s, f); michael@0: michael@0: actual = (obj == RegExp(obj))? cnSUCCESS : cnFAILURE; michael@0: expect = cnSUCCESS; michael@0: reportCompare (expect, actual, 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) + comma + flag + closeparens); michael@0: } michael@0: michael@0: michael@0: function quote(text) michael@0: { michael@0: return (singlequote + text + singlequote); michael@0: }