1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/RegExp/15.10.4.1-4.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 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 a RegExp object to a RegExp() constructor. 1.14 + *This test arose from Bugzilla bug 61266. The ECMA3 section is: 1.15 + * 1.16 + * 15.10.4.1 new RegExp(pattern, flags) 1.17 + * 1.18 + * If pattern is an object R whose [[Class]] property is "RegExp" and 1.19 + * flags is undefined, then let P be the pattern used to construct R 1.20 + * and let F be the flags used to construct R. If pattern is an object R 1.21 + * whose [[Class]] property is "RegExp" and flags is not undefined, 1.22 + * then throw a TypeError exception. Otherwise, let P be the empty string 1.23 + * if pattern is undefined and ToString(pattern) otherwise, and let F be 1.24 + * the empty string if flags is undefined and ToString(flags) otherwise. 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 + * We check that a new RegExp object obj2 defined from these parameters 1.33 + * is morally the same as the original RegExp object obj1. Of course, they 1.34 + * can't be equal as objects - so we check their enumerable properties... 1.35 + * 1.36 + * In this test, the initial RegExp object obj1 will include a 1.37 + * flag. This test is identical to test 15.10.4.1-3.js, except that 1.38 + * here we use this syntax: 1.39 + * 1.40 + * obj2 = new RegExp(obj1, undefined); 1.41 + * 1.42 + * instead of: 1.43 + * 1.44 + * obj2 = new RegExp(obj1); 1.45 + */ 1.46 +//----------------------------------------------------------------------------- 1.47 +var BUGNUMBER = '61266'; 1.48 +var summary = 'Passing a RegExp object to a RegExp() constructor'; 1.49 +var statprefix = 'Applying RegExp() twice to pattern '; 1.50 +var statmiddle = ' and flag '; 1.51 +var statsuffix = '; testing property '; 1.52 +var singlequote = "'"; 1.53 +var i = -1; var j = -1; var s = ''; 1.54 +var obj1 = {}; var obj2 = {}; 1.55 +var status = ''; var actual = ''; var expect = ''; var msg = ''; 1.56 +var patterns = new Array(); 1.57 +var flags = new Array(); 1.58 + 1.59 + 1.60 +// various regular expressions to try - 1.61 +patterns[0] = ''; 1.62 +patterns[1] = 'abc'; 1.63 +patterns[2] = '(.*)(3-1)\s\w'; 1.64 +patterns[3] = '(.*)(...)\\s\\w'; 1.65 +patterns[4] = '[^A-Za-z0-9_]'; 1.66 +patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)'; 1.67 + 1.68 +// various flags to try - 1.69 +flags[0] = 'i'; 1.70 +flags[1] = 'g'; 1.71 +flags[2] = 'm'; 1.72 +flags[3] = undefined; 1.73 + 1.74 + 1.75 + 1.76 +//------------------------------------------------------------------------------------------------- 1.77 +test(); 1.78 +//------------------------------------------------------------------------------------------------- 1.79 + 1.80 + 1.81 +function test() 1.82 +{ 1.83 + enterFunc ('test'); 1.84 + printBugNumber(BUGNUMBER); 1.85 + printStatus (summary); 1.86 + 1.87 + for (i in patterns) 1.88 + { 1.89 + s = patterns[i]; 1.90 + 1.91 + for (j in flags) 1.92 + { 1.93 + f = flags[j]; 1.94 + status = getStatus(s, f); 1.95 + obj1 = new RegExp(s, f); 1.96 + obj2 = new RegExp(obj1, undefined); // see introduction to bug 1.97 + 1.98 + reportCompare (obj1 + '', obj2 + '', status); 1.99 + } 1.100 + } 1.101 + 1.102 + exitFunc ('test'); 1.103 +} 1.104 + 1.105 + 1.106 +function getStatus(regexp, flag) 1.107 +{ 1.108 + return (statprefix + quote(regexp) + statmiddle + flag + statsuffix); 1.109 +} 1.110 + 1.111 + 1.112 +function quote(text) 1.113 +{ 1.114 + return (singlequote + text + singlequote); 1.115 +}