| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 middle: sigma, // sigma | 53 middle: sigma, // sigma |
| 54 // Epsilon acute is between ALPHA-OMEGA and alpha-omega, ie it | 54 // Epsilon acute is between ALPHA-OMEGA and alpha-omega, ie it |
| 55 // is between OMEGA and alpha. | 55 // is between OMEGA and alpha. |
| 56 BetweenCases: "\u03ad"}; | 56 BetweenCases: "\u03ad"}; |
| 57 | 57 |
| 58 | 58 |
| 59 function Range(from, to, flags) { | 59 function Range(from, to, flags) { |
| 60 return new RegExp("[" + from + "-" + to + "]", flags); | 60 return new RegExp("[" + from + "-" + to + "]", flags); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Test Cyrillic and Greek separately. |
| 63 for (var lang = 0; lang < 2; lang++) { | 64 for (var lang = 0; lang < 2; lang++) { |
| 64 var chars = (lang == 0) ? cyrillic : greek; | 65 var chars = (lang == 0) ? cyrillic : greek; |
| 65 | 66 |
| 66 for (var i = 0; i < 2; i++) { | 67 for (var i = 0; i < 2; i++) { |
| 67 var lc = (i == 0); // Lower case. | 68 var lc = (i == 0); // Lower case. |
| 68 var first = lc ? chars.first : chars.FIRST; | 69 var first = lc ? chars.first : chars.FIRST; |
| 69 var middle = lc ? chars.middle : chars.MIDDLE; | 70 var middle = lc ? chars.middle : chars.MIDDLE; |
| 70 var last = lc ? chars.last : chars.LAST; | 71 var last = lc ? chars.last : chars.LAST; |
| 71 var first_other_case = lc ? chars.FIRST : chars.first; | 72 var first_other_case = lc ? chars.FIRST : chars.first; |
| 72 var middle_other_case = lc ? chars.MIDDLE : chars.middle; | 73 var middle_other_case = lc ? chars.MIDDLE : chars.middle; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 92 assertFalse(Range(first, last).test(chars.BetweenCases), 13); | 93 assertFalse(Range(first, last).test(chars.BetweenCases), 13); |
| 93 assertFalse(Range(first, last, "i").test(chars.BetweenCases), 14); | 94 assertFalse(Range(first, last, "i").test(chars.BetweenCases), 14); |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 if (chars.BetweenCases) { | 97 if (chars.BetweenCases) { |
| 97 assertTrue(Range(chars.FIRST, chars.last).test(chars.BetweenCases), 15); | 98 assertTrue(Range(chars.FIRST, chars.last).test(chars.BetweenCases), 15); |
| 98 assertTrue(Range(chars.FIRST, chars.last, "i").test(chars.BetweenCases), 16)
; | 99 assertTrue(Range(chars.FIRST, chars.last, "i").test(chars.BetweenCases), 16)
; |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 | 102 |
| 103 // Test range that covers both greek and cyrillic characters. |
| 102 for (key in greek) { | 104 for (key in greek) { |
| 103 assertTrue(Range(greek.FIRST, cyrillic.last).test(greek[key]), 17 + key); | 105 assertTrue(Range(greek.FIRST, cyrillic.last).test(greek[key]), 17 + key); |
| 104 if (cyrillic[key]) { | 106 if (cyrillic[key]) { |
| 105 assertTrue(Range(greek.FIRST, cyrillic.last).test(cyrillic[key]), 18 + key); | 107 assertTrue(Range(greek.FIRST, cyrillic.last).test(cyrillic[key]), 18 + key); |
| 106 } | 108 } |
| 107 } | 109 } |
| 108 | 110 |
| 109 | |
| 110 for (var i = 0; i < 2; i++) { | 111 for (var i = 0; i < 2; i++) { |
| 111 var ignore_case = (i == 0); | 112 var ignore_case = (i == 0); |
| 112 var flag = ignore_case ? "i" : ""; | 113 var flag = ignore_case ? "i" : ""; |
| 113 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(greek.first), 19); | 114 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(greek.first), 19); |
| 114 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(greek.middle), 20); | 115 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(greek.middle), 20); |
| 115 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(greek.last), 21); | 116 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(greek.last), 21); |
| 116 | 117 |
| 117 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(cyrillic.FIRST), 22); | 118 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(cyrillic.FIRST), 22); |
| 118 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(cyrillic.MIDDLE), 23); | 119 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(cyrillic.MIDDLE), 23); |
| 119 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(cyrillic.LAST), 24); | 120 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(cyrillic.LAST), 24); |
| 120 | 121 |
| 122 // A range that covers the lower case greek letters and the upper case cyrilli
c |
| 123 // letters. |
| 121 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(greek.F
IRST), 25); | 124 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(greek.F
IRST), 25); |
| 122 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(greek.M
IDDLE), 26); | 125 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(greek.M
IDDLE), 26); |
| 123 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(greek.L
AST), 27); | 126 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(greek.L
AST), 27); |
| 124 | 127 |
| 125 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(cyrilli
c.first), 28); | 128 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(cyrilli
c.first), 28); |
| 126 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(cyrilli
c.middle), 29); | 129 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(cyrilli
c.middle), 29); |
| 127 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(cyrilli
c.last), 30); | 130 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(cyrilli
c.last), 30); |
| 128 } | 131 } |
| 129 | 132 |
| 130 | 133 |
| 134 // Sigma is special because there are two lower case versions of the same upper |
| 135 // case character. JS requires that case independece means that you should |
| 136 // convert everything to upper case, so the two sigma variants are equal to each |
| 137 // other in a case independt comparison. |
| 131 for (var i = 0; i < 2; i++) { | 138 for (var i = 0; i < 2; i++) { |
| 132 var simple = (i != 0); | 139 var simple = (i != 0); |
| 133 var name = simple ? "" : "[]"; | 140 var name = simple ? "" : "[]"; |
| 134 var regex = simple ? SIGMA : "[" + SIGMA + "]"; | 141 var regex = simple ? SIGMA : "[" + SIGMA + "]"; |
| 135 | 142 |
| 136 assertFalse(new RegExp(regex).test(sigma), 31 + name); | 143 assertFalse(new RegExp(regex).test(sigma), 31 + name); |
| 137 assertFalse(new RegExp(regex).test(alternative_sigma), 32 + name); | 144 assertFalse(new RegExp(regex).test(alternative_sigma), 32 + name); |
| 138 assertTrue(new RegExp(regex).test(SIGMA), 33 + name); | 145 assertTrue(new RegExp(regex).test(SIGMA), 33 + name); |
| 139 | 146 |
| 140 assertTrue(new RegExp(regex, "i").test(sigma), 34 + name); | 147 assertTrue(new RegExp(regex, "i").test(sigma), 34 + name); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 159 assertTrue(new RegExp(regex).test(alternative_sigma), 52 + name); | 166 assertTrue(new RegExp(regex).test(alternative_sigma), 52 + name); |
| 160 assertFalse(new RegExp(regex).test(SIGMA), 53 + name); | 167 assertFalse(new RegExp(regex).test(SIGMA), 53 + name); |
| 161 | 168 |
| 162 // JSC and Tracemonkey fail this one. | 169 // JSC and Tracemonkey fail this one. |
| 163 assertTrue(new RegExp(regex, "i").test(sigma), 54 + name); | 170 assertTrue(new RegExp(regex, "i").test(sigma), 54 + name); |
| 164 assertTrue(new RegExp(regex, "i").test(alternative_sigma), 55 + name); | 171 assertTrue(new RegExp(regex, "i").test(alternative_sigma), 55 + name); |
| 165 // JSC and Tracemonkey fail this one. | 172 // JSC and Tracemonkey fail this one. |
| 166 assertTrue(new RegExp(regex, "i").test(SIGMA), 56 + name); | 173 assertTrue(new RegExp(regex, "i").test(SIGMA), 56 + name); |
| 167 } | 174 } |
| 168 | 175 |
| 169 print("ok"); | 176 |
| 177 // Test all non-ASCII characters individually to ensure that our optimizations |
| 178 // didn't break anything. |
| 179 for (var i = 0x80; i <= 0xfffe; i++) { |
| 180 var c = String.fromCharCode(i); |
| 181 var c2 = String.fromCharCode(i + 1); |
| 182 var re = new RegExp("[" + c + "-" + c2 + "]", "i"); |
| 183 assertTrue(re.test(c), 57); |
| 184 } |
| 185 |
| 186 for (var add_non_ascii_character_to_subject = 0; |
| 187 add_non_ascii_character_to_subject < 2; |
| 188 add_non_ascii_character_to_subject++) { |
| 189 var suffix = add_non_ascii_character_to_subject ? "\ufffe" : ""; |
| 190 // A range that covers both ASCII and non-ASCII. |
| 191 for (var i = 0; i < 2; i++) { |
| 192 var full = (i != 0); |
| 193 var mixed = full ? "[a-\uffff]" : "[a-" + cyrillic.LAST + "]"; |
| 194 var f = full ? "f" : "c"; |
| 195 for (var j = 0; j < 2; j++) { |
| 196 var ignore_case = (j == 0); |
| 197 var flag = ignore_case ? "i" : ""; |
| 198 var re = new RegExp(mixed, flag); |
| 199 assertEquals(ignore_case || (full && add_non_ascii_character_to_subject), |
| 200 re.test("A" + suffix), |
| 201 58 + flag + f); |
| 202 assertTrue(re.test("a" + suffix), 59 + flag + f); |
| 203 assertTrue(re.test("~" + suffix), 60 + flag + f); |
| 204 assertTrue(re.test(cyrillic.MIDDLE), 61 + flag + f); |
| 205 assertEquals(ignore_case || full, re.test(cyrillic.middle), 62 + flag + f)
; |
| 206 } |
| 207 } |
| 208 } |
| OLD | NEW |