regress-219.js revision a7e24c173cf37484693b9abb38e494fa7bd7baeb
1// Copyright 2008 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28// Tests handling of flags for regexps. 29 30// We should now allow duplicates of flags. 31// (See http://code.google.com/p/v8/issues/detail?id=219) 32 33// Base tests: we recognize the basic flags 34 35function assertFlags(re, global, multiline, ignoreCase) { 36 var name = re + " flag: "; 37 (global ? assertTrue : assertFalse)(re.global, name + "g"); 38 (multiline ? assertTrue : assertFalse)(re.multiline, name + "m"); 39 (ignoreCase ? assertTrue : assertFalse)(re.ignoreCase, name + "i"); 40} 41 42var re = /a/; 43assertFlags(re, false, false, false) 44 45re = /a/gim; 46assertFlags(re, true, true, true) 47 48re = RegExp("a",""); 49assertFlags(re, false, false, false) 50 51re = RegExp("a", "gim"); 52assertFlags(re, true, true, true) 53 54// Double i's 55 56re = /a/ii; 57assertFlags(re, false, false, true) 58 59re = /a/gii; 60assertFlags(re, true, false, true) 61 62re = /a/igi; 63assertFlags(re, true, false, true) 64 65re = /a/iig; 66assertFlags(re, true, false, true) 67 68re = /a/gimi; 69assertFlags(re, true, true, true) 70 71re = /a/giim; 72assertFlags(re, true, true, true) 73 74re = /a/igim; 75assertFlags(re, true, true, true) 76 77 78re = RegExp("a", "ii"); 79assertFlags(re, false, false, true) 80 81re = RegExp("a", "gii"); 82assertFlags(re, true, false, true) 83 84re = RegExp("a", "igi"); 85assertFlags(re, true, false, true) 86 87re = RegExp("a", "iig"); 88assertFlags(re, true, false, true) 89 90re = RegExp("a", "gimi"); 91assertFlags(re, true, true, true) 92 93re = RegExp("a", "giim"); 94assertFlags(re, true, true, true) 95 96re = RegExp("a", "igim"); 97assertFlags(re, true, true, true) 98 99// Tripple i's 100 101re = /a/iii; 102assertFlags(re, false, false, true) 103 104re = /a/giii; 105assertFlags(re, true, false, true) 106 107re = /a/igii; 108assertFlags(re, true, false, true) 109 110re = /a/iigi; 111assertFlags(re, true, false, true) 112 113re = /a/iiig; 114assertFlags(re, true, false, true) 115 116re = /a/miiig; 117assertFlags(re, true, true, true) 118 119 120re = RegExp("a", "iii"); 121assertFlags(re, false, false, true) 122 123re = RegExp("a", "giii"); 124assertFlags(re, true, false, true) 125 126re = RegExp("a", "igii"); 127assertFlags(re, true, false, true) 128 129re = RegExp("a", "iigi"); 130assertFlags(re, true, false, true) 131 132re = RegExp("a", "iiig"); 133assertFlags(re, true, false, true) 134 135re = RegExp("a", "miiig"); 136assertFlags(re, true, true, true) 137 138// Illegal flags - flags late in string. 139 140re = /a/arglebargleglopglyf; 141assertFlags(re, true, false, false) 142 143re = /a/arglebargleglopglif; 144assertFlags(re, true, false, true) 145 146re = /a/arglebargleglopglym; 147assertFlags(re, true, true, false) 148 149re = /a/arglebargleglopglim; 150assertFlags(re, true, true, true) 151 152// Case of flags still matters. 153 154re = /a/gmi; 155assertFlags(re, true, true, true) 156 157re = /a/Gmi; 158assertFlags(re, false, true, true) 159 160re = /a/gMi; 161assertFlags(re, true, false, true) 162 163re = /a/gmI; 164assertFlags(re, true, true, false) 165 166re = /a/GMi; 167assertFlags(re, false, false, true) 168 169re = /a/GmI; 170assertFlags(re, false, true, false) 171 172re = /a/gMI; 173assertFlags(re, true, false, false) 174 175re = /a/GMI; 176assertFlags(re, false, false, false) 177