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

Unified Diff: test/cctest/test-strings.cc

Issue 11962035: Fix some latin-1 webkit units tests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed last latin-1 webkit test failure Created 7 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/unicode-inl.h ('k') | test/mjsunit/regress/regress-latin-1.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index 3684b879738262d1875834cd9554dbaa3e34e10b..2e79dda6880c6ac06f39e362e40218c958119ab8 100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -1277,38 +1277,60 @@ TEST(IsAscii) {
}
-static bool CanBeConvertedToLatin1(uint16_t c) {
- CHECK(c > unibrow::Latin1::kMaxChar);
- uint32_t result[4];
+template<typename Op, bool return_first>
+static uint16_t ConvertLatin1(uint16_t c) {
+ uint32_t result[Op::kMaxWidth];
int chars;
- chars = unibrow::ToLowercase::Convert(c, 0, result, NULL);
- if (chars > 0) {
- CHECK_LE(chars, static_cast<int>(sizeof(result)));
- for (int i = 0; i < chars; i++) {
- if (result[i] <= unibrow::Latin1::kMaxChar) {
- return true;
- }
- }
- }
- chars = unibrow::ToUppercase::Convert(c, 0, result, NULL);
- if (chars > 0) {
- CHECK_LE(chars, static_cast<int>(sizeof(result)));
- for (int i = 0; i < chars; i++) {
- if (result[i] <= unibrow::Latin1::kMaxChar) {
- return true;
- }
- }
+ chars = Op::Convert(c, 0, result, NULL);
+ if (chars == 0) return 0;
+ CHECK_LE(chars, static_cast<int>(sizeof(result)));
+ if (!return_first && chars > 1) {
+ return 0;
}
- return false;
+ return result[0];
+}
+
+
+static void CheckCanonicalEquivalence(uint16_t c, uint16_t test) {
+ uint16_t expect = ConvertLatin1<unibrow::Ecma262UnCanonicalize, true>(c);
+ if (expect > unibrow::Latin1::kMaxChar) expect = 0;
+ CHECK_EQ(expect, test);
}
TEST(Latin1) {
#ifndef ENABLE_LATIN_1
- if (true) return;
+ if (true) return;
#endif
- for (uint16_t c = unibrow::Latin1::kMaxChar + 1; c != 0; c++) {
- CHECK_EQ(CanBeConvertedToLatin1(c),
- unibrow::Latin1::NonLatin1CanBeConvertedToLatin1(c));
+ using namespace unibrow;
+ for (uint16_t c = Latin1::kMaxChar + 1; c != 0; c++) {
+ uint16_t lower = ConvertLatin1<ToLowercase, false>(c);
+ uint16_t upper = ConvertLatin1<ToUppercase, false>(c);
+ uint16_t test = Latin1::ConvertNonLatin1ToLatin1(c);
+ // Filter out all character whose upper is not their lower or vice versa.
+ if (lower == 0 && upper == 0) {
+ CheckCanonicalEquivalence(c, test);
+ continue;
+ }
+ if (lower > Latin1::kMaxChar && upper > Latin1::kMaxChar) {
+ CheckCanonicalEquivalence(c, test);
+ continue;
+ }
+ if (lower == 0 && upper != 0) {
+ lower = ConvertLatin1<ToLowercase, false>(upper);
+ }
+ if (upper == 0 && lower != c) {
+ upper = ConvertLatin1<ToUppercase, false>(lower);
+ }
+ if (lower > Latin1::kMaxChar && upper > Latin1::kMaxChar) {
+ CheckCanonicalEquivalence(c, test);
+ continue;
+ }
+ if (upper != c && lower != c) {
+ CheckCanonicalEquivalence(c, test);
+ continue;
+ }
+ CHECK_EQ(Min(upper, lower), test);
}
}
+
« no previous file with comments | « src/unicode-inl.h ('k') | test/mjsunit/regress/regress-latin-1.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698