1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/RegExp/15.10.3.1-2.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * Date: 26 November 2000 1.11 + * 1.12 + * 1.13 + * SUMMARY: Passing (RegExp object, flag) to RegExp() function. 1.14 + * This test arose from Bugzilla bug 61266. The ECMA3 section is: 1.15 + * 1.16 + * 15.10.3 The RegExp Constructor Called as a Function 1.17 + * 1.18 + * 15.10.3.1 RegExp(pattern, flags) 1.19 + * 1.20 + * If pattern is an object R whose [[Class]] property is "RegExp" 1.21 + * and flags is undefined, then return R unchanged. Otherwise 1.22 + * call the RegExp constructor (section 15.10.4.1), passing it the 1.23 + * pattern and flags arguments and return the object constructed 1.24 + * by that constructor. 1.25 + * 1.26 + * 1.27 + * The current test will check the first scenario outlined above: 1.28 + * 1.29 + * "pattern" is itself a RegExp object R 1.30 + * "flags" is undefined 1.31 + * 1.32 + * This test is identical to test 15.10.3.1-1.js, except here we do: 1.33 + * 1.34 + * RegExp(R, undefined); 1.35 + * 1.36 + * instead of: 1.37 + * 1.38 + * RegExp(R); 1.39 + * 1.40 + * 1.41 + * We check that RegExp(R, undefined) returns R - 1.42 + */ 1.43 +//----------------------------------------------------------------------------- 1.44 +var BUGNUMBER = '61266'; 1.45 +var summary = 'Passing (RegExp object,flag) to RegExp() function'; 1.46 +var statprefix = 'RegExp(new RegExp('; 1.47 +var comma = ', '; var singlequote = "'"; var closeparens = '))'; 1.48 +var cnSUCCESS = 'RegExp() returned the supplied RegExp object'; 1.49 +var cnFAILURE = 'RegExp() did NOT return the supplied RegExp object'; 1.50 +var i = -1; var j = -1; var s = ''; var f = ''; 1.51 +var obj = {}; 1.52 +var status = ''; var actual = ''; var expect = ''; 1.53 +var patterns = new Array(); 1.54 +var flags = new Array(); 1.55 + 1.56 + 1.57 +// various regular expressions to try - 1.58 +patterns[0] = ''; 1.59 +patterns[1] = 'abc'; 1.60 +patterns[2] = '(.*)(3-1)\s\w'; 1.61 +patterns[3] = '(.*)(...)\\s\\w'; 1.62 +patterns[4] = '[^A-Za-z0-9_]'; 1.63 +patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)'; 1.64 + 1.65 +// various flags to try - 1.66 +flags[0] = 'i'; 1.67 +flags[1] = 'g'; 1.68 +flags[2] = 'm'; 1.69 +flags[3] = undefined; 1.70 + 1.71 + 1.72 + 1.73 +//------------------------------------------------------------------------------------------------- 1.74 +test(); 1.75 +//------------------------------------------------------------------------------------------------- 1.76 + 1.77 + 1.78 +function test() 1.79 +{ 1.80 + enterFunc ('test'); 1.81 + printBugNumber(BUGNUMBER); 1.82 + printStatus (summary); 1.83 + 1.84 + for (i in patterns) 1.85 + { 1.86 + s = patterns[i]; 1.87 + 1.88 + for (j in flags) 1.89 + { 1.90 + f = flags[j]; 1.91 + status = getStatus(s, f); 1.92 + obj = new RegExp(s, f); 1.93 + 1.94 + actual = (obj == RegExp(obj, undefined))? cnSUCCESS : cnFAILURE ; 1.95 + expect = cnSUCCESS; 1.96 + reportCompare (expect, actual, status); 1.97 + } 1.98 + } 1.99 + 1.100 + exitFunc ('test'); 1.101 +} 1.102 + 1.103 + 1.104 +function getStatus(regexp, flag) 1.105 +{ 1.106 + return (statprefix + quote(regexp) + comma + flag + closeparens); 1.107 +} 1.108 + 1.109 + 1.110 +function quote(text) 1.111 +{ 1.112 + return (singlequote + text + singlequote); 1.113 +}