Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: test/mjsunit/cyrillic.js

Issue 361033: Fix bug 486, Cyrillic character ranges in case independent regexps.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2009 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 // Test Unicode character ranges in regexps.
29
30
31 // Cyrillic.
32 var cyrillic = {
33 FIRST: "\u0410", // A
34 first: "\u0430", // a
35 LAST: "\u042f", // YA
36 last: "\u044f", // ya
37 MIDDLE: "\u0427", // CHE
38 middle: "\u0447", // che
39 // Actually no characters are between the cases in Cyrillic.
40 BetweenCases: false};
41
42 var SIGMA = "\u03a3";
43 var sigma = "\u03c3";
44 var alternative_sigma = "\u03c2";
45
46 // Greek.
47 var greek = {
48 FIRST: "\u0391", // ALPHA
49 first: "\u03b1", // alpha
50 LAST: "\u03a9", // OMEGA
51 last: "\u03c9", // omega
52 MIDDLE: SIGMA, // SIGMA
53 middle: sigma, // sigma
54 // Epsilon acute is between ALPHA-OMEGA and alpha-omega, ie it
55 // is between OMEGA and alpha.
56 BetweenCases: "\u03ad"};
57
58
59 function Range(from, to, flags) {
60 return new RegExp("[" + from + "-" + to + "]", flags);
61 }
62
63 for (var lang = 0; lang < 2; lang++) {
64 var chars = (lang == 0) ? cyrillic : greek;
65
66 for (var i = 0; i < 2; i++) {
67 var lc = (i == 0); // Lower case.
68 var first = lc ? chars.first : chars.FIRST;
69 var middle = lc ? chars.middle : chars.MIDDLE;
70 var last = lc ? chars.last : chars.LAST;
71 var first_other_case = lc ? chars.FIRST : chars.first;
72 var middle_other_case = lc ? chars.MIDDLE : chars.middle;
73 var last_other_case = lc ? chars.LAST : chars.last;
74
75 assertTrue(Range(first, last).test(first), 1);
76 assertTrue(Range(first, last).test(middle), 2);
77 assertTrue(Range(first, last).test(last), 3);
78
79 assertFalse(Range(first, last).test(first_other_case), 4);
80 assertFalse(Range(first, last).test(middle_other_case), 5);
81 assertFalse(Range(first, last).test(last_other_case), 6);
82
83 assertTrue(Range(first, last, "i").test(first), 7);
84 assertTrue(Range(first, last, "i").test(middle), 8);
85 assertTrue(Range(first, last, "i").test(last), 9);
86
87 assertTrue(Range(first, last, "i").test(first_other_case), 10);
88 assertTrue(Range(first, last, "i").test(middle_other_case), 11);
89 assertTrue(Range(first, last, "i").test(last_other_case), 12);
90
91 if (chars.BetweenCases) {
92 assertFalse(Range(first, last).test(chars.BetweenCases), 13);
93 assertFalse(Range(first, last, "i").test(chars.BetweenCases), 14);
94 }
95 }
96 if (chars.BetweenCases) {
97 assertTrue(Range(chars.FIRST, chars.last).test(chars.BetweenCases), 15);
98 assertTrue(Range(chars.FIRST, chars.last, "i").test(chars.BetweenCases), 16) ;
99 }
100 }
101
102 for (key in greek) {
103 assertTrue(Range(greek.FIRST, cyrillic.last).test(greek[key]), 17 + key);
104 if (cyrillic[key]) {
105 assertTrue(Range(greek.FIRST, cyrillic.last).test(cyrillic[key]), 18 + key);
106 }
107 }
108
109
110 for (var i = 0; i < 2; i++) {
111 var ignore_case = (i == 0);
112 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.middle), 20);
115 assertTrue(Range(greek.first, cyrillic.LAST, flag).test(greek.last), 21);
116
117 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.LAST), 24);
120
121 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);
123 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(greek.L AST), 27);
124
125 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);
127 assertEquals(ignore_case, Range(greek.first, cyrillic.LAST, flag).test(cyrilli c.last), 30);
128 }
129
130
131 for (var i = 0; i < 2; i++) {
132 var simple = (i != 0);
133 var name = simple ? "" : "[]";
134 var regex = simple ? SIGMA : "[" + SIGMA + "]";
135
136 assertFalse(new RegExp(regex).test(sigma), 31 + name);
137 assertFalse(new RegExp(regex).test(alternative_sigma), 32 + name);
138 assertTrue(new RegExp(regex).test(SIGMA), 33 + name);
139
140 assertTrue(new RegExp(regex, "i").test(sigma), 34 + name);
141 // JSC and Tracemonkey fail this one.
142 assertTrue(new RegExp(regex, "i").test(alternative_sigma), 35 + name);
143 assertTrue(new RegExp(regex, "i").test(SIGMA), 36 + name);
144
145 regex = simple ? sigma : "[" + sigma + "]";
146
147 assertTrue(new RegExp(regex).test(sigma), 41 + name);
148 assertFalse(new RegExp(regex).test(alternative_sigma), 42 + name);
149 assertFalse(new RegExp(regex).test(SIGMA), 43 + name);
150
151 assertTrue(new RegExp(regex, "i").test(sigma), 44 + name);
152 // JSC and Tracemonkey fail this one.
153 assertTrue(new RegExp(regex, "i").test(alternative_sigma), 45 + name);
154 assertTrue(new RegExp(regex, "i").test(SIGMA), 46 + name);
155
156 regex = simple ? alternative_sigma : "[" + alternative_sigma + "]";
157
158 assertFalse(new RegExp(regex).test(sigma), 51 + name);
159 assertTrue(new RegExp(regex).test(alternative_sigma), 52 + name);
160 assertFalse(new RegExp(regex).test(SIGMA), 53 + name);
161
162 // JSC and Tracemonkey fail this one.
163 assertTrue(new RegExp(regex, "i").test(sigma), 54 + name);
164 assertTrue(new RegExp(regex, "i").test(alternative_sigma), 55 + name);
165 // JSC and Tracemonkey fail this one.
166 assertTrue(new RegExp(regex, "i").test(SIGMA), 56 + name);
167 }
168
169 print("ok");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698