iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 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 | |
| 35 | function 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 | |
| 42 | var re = /a/; |
| 43 | assertFlags(re, false, false, false) |
| 44 | |
| 45 | re = /a/gim; |
| 46 | assertFlags(re, true, true, true) |
| 47 | |
| 48 | re = RegExp("a",""); |
| 49 | assertFlags(re, false, false, false) |
| 50 | |
| 51 | re = RegExp("a", "gim"); |
| 52 | assertFlags(re, true, true, true) |
| 53 | |
| 54 | // Double i's |
| 55 | |
| 56 | re = /a/ii; |
| 57 | assertFlags(re, false, false, true) |
| 58 | |
| 59 | re = /a/gii; |
| 60 | assertFlags(re, true, false, true) |
| 61 | |
| 62 | re = /a/igi; |
| 63 | assertFlags(re, true, false, true) |
| 64 | |
| 65 | re = /a/iig; |
| 66 | assertFlags(re, true, false, true) |
| 67 | |
| 68 | re = /a/gimi; |
| 69 | assertFlags(re, true, true, true) |
| 70 | |
| 71 | re = /a/giim; |
| 72 | assertFlags(re, true, true, true) |
| 73 | |
| 74 | re = /a/igim; |
| 75 | assertFlags(re, true, true, true) |
| 76 | |
| 77 | |
| 78 | re = RegExp("a", "ii"); |
| 79 | assertFlags(re, false, false, true) |
| 80 | |
| 81 | re = RegExp("a", "gii"); |
| 82 | assertFlags(re, true, false, true) |
| 83 | |
| 84 | re = RegExp("a", "igi"); |
| 85 | assertFlags(re, true, false, true) |
| 86 | |
| 87 | re = RegExp("a", "iig"); |
| 88 | assertFlags(re, true, false, true) |
| 89 | |
| 90 | re = RegExp("a", "gimi"); |
| 91 | assertFlags(re, true, true, true) |
| 92 | |
| 93 | re = RegExp("a", "giim"); |
| 94 | assertFlags(re, true, true, true) |
| 95 | |
| 96 | re = RegExp("a", "igim"); |
| 97 | assertFlags(re, true, true, true) |
| 98 | |
| 99 | // Tripple i's |
| 100 | |
| 101 | re = /a/iii; |
| 102 | assertFlags(re, false, false, true) |
| 103 | |
| 104 | re = /a/giii; |
| 105 | assertFlags(re, true, false, true) |
| 106 | |
| 107 | re = /a/igii; |
| 108 | assertFlags(re, true, false, true) |
| 109 | |
| 110 | re = /a/iigi; |
| 111 | assertFlags(re, true, false, true) |
| 112 | |
| 113 | re = /a/iiig; |
| 114 | assertFlags(re, true, false, true) |
| 115 | |
| 116 | re = /a/miiig; |
| 117 | assertFlags(re, true, true, true) |
| 118 | |
| 119 | |
| 120 | re = RegExp("a", "iii"); |
| 121 | assertFlags(re, false, false, true) |
| 122 | |
| 123 | re = RegExp("a", "giii"); |
| 124 | assertFlags(re, true, false, true) |
| 125 | |
| 126 | re = RegExp("a", "igii"); |
| 127 | assertFlags(re, true, false, true) |
| 128 | |
| 129 | re = RegExp("a", "iigi"); |
| 130 | assertFlags(re, true, false, true) |
| 131 | |
| 132 | re = RegExp("a", "iiig"); |
| 133 | assertFlags(re, true, false, true) |
| 134 | |
| 135 | re = RegExp("a", "miiig"); |
| 136 | assertFlags(re, true, true, true) |
| 137 | |
| 138 | // Illegal flags - flags late in string. |
| 139 | |
| 140 | re = /a/arglebargleglopglyf; |
| 141 | assertFlags(re, true, false, false) |
| 142 | |
| 143 | re = /a/arglebargleglopglif; |
| 144 | assertFlags(re, true, false, true) |
| 145 | |
| 146 | re = /a/arglebargleglopglym; |
| 147 | assertFlags(re, true, true, false) |
| 148 | |
| 149 | re = /a/arglebargleglopglim; |
| 150 | assertFlags(re, true, true, true) |
| 151 | |
| 152 | // Case of flags still matters. |
| 153 | |
| 154 | re = /a/gmi; |
| 155 | assertFlags(re, true, true, true) |
| 156 | |
| 157 | re = /a/Gmi; |
| 158 | assertFlags(re, false, true, true) |
| 159 | |
| 160 | re = /a/gMi; |
| 161 | assertFlags(re, true, false, true) |
| 162 | |
| 163 | re = /a/gmI; |
| 164 | assertFlags(re, true, true, false) |
| 165 | |
| 166 | re = /a/GMi; |
| 167 | assertFlags(re, false, false, true) |
| 168 | |
| 169 | re = /a/GmI; |
| 170 | assertFlags(re, false, true, false) |
| 171 | |
| 172 | re = /a/gMI; |
| 173 | assertFlags(re, true, false, false) |
| 174 | |
| 175 | re = /a/GMI; |
| 176 | assertFlags(re, false, false, false) |