| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // Base tests: we recognize the basic flags | 37 // Base tests: we recognize the basic flags |
| 38 | 38 |
| 39 function assertFlags(re, global, multiline, ignoreCase) { | 39 function assertFlags(re, global, multiline, ignoreCase) { |
| 40 var name = re + " flag: "; | 40 var name = re + " flag: "; |
| 41 (global ? assertTrue : assertFalse)(re.global, name + "g"); | 41 (global ? assertTrue : assertFalse)(re.global, name + "g"); |
| 42 (multiline ? assertTrue : assertFalse)(re.multiline, name + "m"); | 42 (multiline ? assertTrue : assertFalse)(re.multiline, name + "m"); |
| 43 (ignoreCase ? assertTrue : assertFalse)(re.ignoreCase, name + "i"); | 43 (ignoreCase ? assertTrue : assertFalse)(re.ignoreCase, name + "i"); |
| 44 } | 44 } |
| 45 | 45 |
| 46 var re = /a/; | 46 var re = /a/; |
| 47 assertFlags(re, false, false, false) | 47 assertFlags(re, false, false, false); |
| 48 | 48 |
| 49 re = /a/gim; | 49 re = /a/gim; |
| 50 assertFlags(re, true, true, true) | 50 assertFlags(re, true, true, true); |
| 51 | 51 |
| 52 re = RegExp("a",""); | 52 re = RegExp("a",""); |
| 53 assertFlags(re, false, false, false) | 53 assertFlags(re, false, false, false); |
| 54 | 54 |
| 55 re = RegExp("a", "gim"); | 55 re = RegExp("a", "gim"); |
| 56 assertFlags(re, true, true, true) | 56 assertFlags(re, true, true, true); |
| 57 | 57 |
| 58 // Double i's | 58 // Double i's |
| 59 | 59 |
| 60 assertThrows("/a/ii"); | 60 assertThrows("/a/ii"); |
| 61 | 61 |
| 62 assertThrows("/a/gii"); | 62 assertThrows("/a/gii"); |
| 63 | 63 |
| 64 assertThrows("/a/igi"); | 64 assertThrows("/a/igi"); |
| 65 | 65 |
| 66 assertThrows("/a/iig"); | 66 assertThrows("/a/iig"); |
| 67 | 67 |
| 68 assertThrows("/a/gimi"); | 68 assertThrows("/a/gimi"); |
| 69 | 69 |
| 70 assertThrows("/a/giim"); | 70 assertThrows("/a/giim"); |
| 71 | 71 |
| 72 assertThrows("/a/igim"); | 72 assertThrows("/a/igim"); |
| 73 | 73 |
| 74 assertThrows(function(){ return RegExp("a", "ii"); }) | 74 assertThrows(function(){ return RegExp("a", "ii"); }); |
| 75 | 75 |
| 76 assertThrows(function(){ return RegExp("a", "gii"); }) | 76 assertThrows(function(){ return RegExp("a", "gii"); }); |
| 77 | 77 |
| 78 assertThrows(function(){ return RegExp("a", "igi"); }) | 78 assertThrows(function(){ return RegExp("a", "igi"); }); |
| 79 | 79 |
| 80 assertThrows(function(){ return RegExp("a", "iig"); }) | 80 assertThrows(function(){ return RegExp("a", "iig"); }); |
| 81 | 81 |
| 82 assertThrows(function(){ return RegExp("a", "gimi"); }) | 82 assertThrows(function(){ return RegExp("a", "gimi"); }); |
| 83 | 83 |
| 84 assertThrows(function(){ return RegExp("a", "giim"); }) | 84 assertThrows(function(){ return RegExp("a", "giim"); }); |
| 85 | 85 |
| 86 assertThrows(function(){ return RegExp("a", "igim"); }) | 86 assertThrows(function(){ return RegExp("a", "igim"); }); |
| 87 | 87 |
| 88 // Tripple i's | 88 // Tripple i's |
| 89 | 89 |
| 90 assertThrows("/a/iii"); | 90 assertThrows("/a/iii"); |
| 91 | 91 |
| 92 assertThrows("/a/giii"); | 92 assertThrows("/a/giii"); |
| 93 | 93 |
| 94 assertThrows("/a/igii"); | 94 assertThrows("/a/igii"); |
| 95 | 95 |
| 96 assertThrows("/a/iigi"); | 96 assertThrows("/a/iigi"); |
| 97 | 97 |
| 98 assertThrows("/a/iiig"); | 98 assertThrows("/a/iiig"); |
| 99 | 99 |
| 100 assertThrows("/a/miiig"); | 100 assertThrows("/a/miiig"); |
| 101 | 101 |
| 102 assertThrows(function(){ return RegExp("a", "iii"); }) | 102 assertThrows(function(){ return RegExp("a", "iii"); }); |
| 103 | 103 |
| 104 assertThrows(function(){ return RegExp("a", "giii"); }) | 104 assertThrows(function(){ return RegExp("a", "giii"); }); |
| 105 | 105 |
| 106 assertThrows(function(){ return RegExp("a", "igii"); }) | 106 assertThrows(function(){ return RegExp("a", "igii"); }); |
| 107 | 107 |
| 108 assertThrows(function(){ return RegExp("a", "iigi"); }) | 108 assertThrows(function(){ return RegExp("a", "iigi"); }); |
| 109 | 109 |
| 110 assertThrows(function(){ return RegExp("a", "iiig"); }) | 110 assertThrows(function(){ return RegExp("a", "iiig"); }); |
| 111 | 111 |
| 112 assertThrows(function(){ return RegExp("a", "miiig"); }) | 112 assertThrows(function(){ return RegExp("a", "miiig"); }); |
| 113 | 113 |
| 114 // Illegal flags - valid flags late in string. | 114 // Illegal flags - valid flags late in string. |
| 115 | 115 |
| 116 assertThrows("/a/arglebargleglopglyf"); | 116 assertThrows("/a/arglebargleglopglyf"); |
| 117 | 117 |
| 118 assertThrows("/a/arglebargleglopglif"); | 118 assertThrows("/a/arglebargleglopglif"); |
| 119 | 119 |
| 120 assertThrows("/a/arglebargleglopglym"); | 120 assertThrows("/a/arglebargleglopglym"); |
| 121 | 121 |
| 122 assertThrows("/a/arglebargleglopglim"); | 122 assertThrows("/a/arglebargleglopglim"); |
| 123 | 123 |
| 124 // Case of flags still matters. | 124 // Case of flags still matters. |
| 125 | 125 |
| 126 var re = /a/gmi; | 126 var re = /a/gmi; |
| 127 assertFlags(re, true, true, true) | 127 assertFlags(re, true, true, true); |
| 128 | 128 |
| 129 assertThrows("/a/Gmi"); | 129 assertThrows("/a/Gmi"); |
| 130 | 130 |
| 131 assertThrows("/a/gMi"); | 131 assertThrows("/a/gMi"); |
| 132 | 132 |
| 133 assertThrows("/a/gmI"); | 133 assertThrows("/a/gmI"); |
| 134 | 134 |
| 135 assertThrows("/a/GMi"); | 135 assertThrows("/a/GMi"); |
| 136 | 136 |
| 137 assertThrows("/a/GmI"); | 137 assertThrows("/a/GmI"); |
| 138 | 138 |
| 139 assertThrows("/a/gMI"); | 139 assertThrows("/a/gMI"); |
| 140 | 140 |
| 141 assertThrows("/a/GMI"); | 141 assertThrows("/a/GMI"); |
| 142 | 142 |
| 143 // Unicode escape sequences are not interpreted. | 143 // Unicode escape sequences are not interpreted. |
| 144 | 144 |
| 145 assertThrows("/a/\\u0067"); | 145 assertThrows("/a/\\u0067"); |
| 146 assertThrows("/a/\\u0069"); | 146 assertThrows("/a/\\u0069"); |
| 147 assertThrows("/a/\\u006d"); | 147 assertThrows("/a/\\u006d"); |
| 148 assertThrows("/a/\\u006D"); | 148 assertThrows("/a/\\u006D"); |
| OLD | NEW |