js/src/tests/ecma_3/RegExp/15.10.4.1-5-n.js

changeset 0
6474c204b198
     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-5-n.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     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 + *
    1.11 + * Date: 26 November 2000
    1.12 + *
    1.13 + *
    1.14 + *SUMMARY: Passing a RegExp object to a RegExp() constructor.
    1.15 + *This test arose from Bugzilla bug 61266. The ECMA3 section is:      
    1.16 + *
    1.17 + *  15.10.4.1 new RegExp(pattern, flags)
    1.18 + *
    1.19 + *  If pattern is an object R whose [[Class]] property is "RegExp" and
    1.20 + *  flags is undefined, then let P be the pattern used to construct R
    1.21 + *  and let F be the flags used to construct R. If pattern is an object R
    1.22 + *  whose [[Class]] property is "RegExp" and flags is not undefined,
    1.23 + *  then throw a TypeError exception. Otherwise, let P be the empty string 
    1.24 + *  if pattern is undefined and ToString(pattern) otherwise, and let F be
    1.25 + *  the empty string if flags is undefined and ToString(flags) otherwise.
    1.26 + *
    1.27 + *
    1.28 + *The current test will check the second scenario outlined above:
    1.29 + *
    1.30 + *   "pattern" is itself a RegExp object R
    1.31 + *   "flags" is NOT undefined
    1.32 + *
    1.33 + * This should throw an exception ... we test for this.
    1.34 + *
    1.35 + */
    1.36 +
    1.37 +//-------------------------------------------------------------------------------------------------
    1.38 +var BUGNUMBER = '61266';
    1.39 +var summary = 'Negative test: Passing (RegExp object, flag) to RegExp() constructor';
    1.40 +var statprefix = 'Passing RegExp object on pattern ';
    1.41 +var statsuffix =  '; passing flag ';
    1.42 +var cnFAILURE = 'Expected an exception to be thrown, but none was -';
    1.43 +var singlequote = "'";
    1.44 +var i = -1; var j = -1; var s = ''; var f = '';
    1.45 +var obj1 = {}; var obj2 = {};
    1.46 +var patterns = new Array();
    1.47 +var flags = new Array(); 
    1.48 +
    1.49 +
    1.50 +// various regular expressions to try -
    1.51 +patterns[0] = '';
    1.52 +patterns[1] = 'abc';
    1.53 +patterns[2] = '(.*)(3-1)\s\w';
    1.54 +patterns[3] = '(.*)(...)\\s\\w';
    1.55 +patterns[4] = '[^A-Za-z0-9_]';
    1.56 +patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
    1.57 +
    1.58 +// various flags to try -
    1.59 +flags[0] = 'i';
    1.60 +flags[1] = 'g';
    1.61 +flags[2] = 'm';
    1.62 +
    1.63 +
    1.64 +DESCRIPTION = "Negative test: Passing (RegExp object, flag) to RegExp() constructor"
    1.65 +  EXPECTED = "error";
    1.66 +
    1.67 +
    1.68 +//-------------------------------------------------------------------------------------------------
    1.69 +test();
    1.70 +//-------------------------------------------------------------------------------------------------
    1.71 +
    1.72 +
    1.73 +function test()
    1.74 +{
    1.75 +  enterFunc ('test');
    1.76 +  printBugNumber(BUGNUMBER);
    1.77 +  printStatus (summary);
    1.78 +
    1.79 +  for (i in patterns)
    1.80 +  {
    1.81 +    s = patterns[i];
    1.82 +
    1.83 +    for (j in flags)
    1.84 +    {
    1.85 +      f = flags[j];
    1.86 +      printStatus(getStatus(s, f));
    1.87 +      obj1 = new RegExp(s, f);  
    1.88 +      obj2 = new RegExp(obj1, f);   // this should cause an exception
    1.89 +
    1.90 +      // WE SHOULD NEVER REACH THIS POINT -
    1.91 +      reportCompare('PASS', 'FAIL', cnFAILURE);
    1.92 +    }
    1.93 +  }
    1.94 +
    1.95 +  exitFunc ('test');
    1.96 +}
    1.97 +
    1.98 +
    1.99 +function getStatus(regexp, flag)
   1.100 +{
   1.101 +  return (statprefix  +  quote(regexp) +  statsuffix  +   flag);
   1.102 +}
   1.103 +
   1.104 +
   1.105 +function quote(text)
   1.106 +{
   1.107 +  return (singlequote  +  text  + singlequote);
   1.108 +}

mercurial