| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 // When SpellcheckWordIterator uses an inconsistent ICU ruleset, the following | 158 // When SpellcheckWordIterator uses an inconsistent ICU ruleset, the following |
| 159 // iterator.GetNextWord() call gets stuck in an infinite loop. Therefore, this | 159 // iterator.GetNextWord() call gets stuck in an infinite loop. Therefore, this |
| 160 // test succeeds if this call returns without timeouts. | 160 // test succeeds if this call returns without timeouts. |
| 161 string16 actual_word; | 161 string16 actual_word; |
| 162 int actual_start, actual_end; | 162 int actual_start, actual_end; |
| 163 EXPECT_FALSE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); | 163 EXPECT_FALSE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); |
| 164 EXPECT_EQ(0, actual_start); | 164 EXPECT_EQ(0, actual_start); |
| 165 EXPECT_EQ(0, actual_end); | 165 EXPECT_EQ(0, actual_end); |
| 166 } | 166 } |
| 167 |
| 168 // Vertify our SpellcheckWordIterator can treat ASCII numbers as word characters |
| 169 // on LTR languages. On the other hand, it should not treat ASCII numbers as |
| 170 // word characters on RTL languages because they change the text direction from |
| 171 // RTL to LTR. |
| 172 TEST(SpellcheckWordIteratorTest, TreatNumbersAsWordCharacters) { |
| 173 // A set of a language, a dummy word, and a text direction used in this test. |
| 174 // For each language, this test splits a dummy word, which consists of ASCII |
| 175 // numbers and an alphabet of the language, into words. When ASCII numbers are |
| 176 // treated as word characters, the split word becomes equal to the dummy word. |
| 177 // Otherwise, the split word does not include ASCII numbers. |
| 178 static const struct { |
| 179 const char* language; |
| 180 const wchar_t* text; |
| 181 bool left_to_right; |
| 182 } kTestCases[] = { |
| 183 { |
| 184 // English |
| 185 "en-US", L"0123456789" L"a", true, |
| 186 }, { |
| 187 // Greek |
| 188 "el-GR", L"0123456789" L"\x03B1", true, |
| 189 }, { |
| 190 // Russian |
| 191 "ru-RU", L"0123456789" L"\x0430", true, |
| 192 }, { |
| 193 // Hebrew |
| 194 "he-IL", L"0123456789" L"\x05D0", false, |
| 195 }, { |
| 196 // Arabic |
| 197 "ar", L"0123456789" L"\x0627", false, |
| 198 }, { |
| 199 // Hindi |
| 200 "hi-IN", L"0123456789" L"\x0905", true, |
| 201 }, { |
| 202 // Thai |
| 203 "th-TH", L"0123456789" L"\x0e01", true, |
| 204 }, { |
| 205 // Korean |
| 206 "ko-KR", L"0123456789" L"\x1100\x1161", true, |
| 207 }, |
| 208 }; |
| 209 |
| 210 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 211 SCOPED_TRACE(base::StringPrintf("kTestCases[%" PRIuS "]: language=%s", i, |
| 212 kTestCases[i].language)); |
| 213 |
| 214 SpellcheckCharAttribute attributes; |
| 215 attributes.SetDefaultLanguage(kTestCases[i].language); |
| 216 |
| 217 string16 input_word(WideToUTF16(kTestCases[i].text)); |
| 218 SpellcheckWordIterator iterator; |
| 219 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
| 220 EXPECT_TRUE(iterator.SetText(input_word.c_str(), input_word.length())); |
| 221 |
| 222 string16 actual_word; |
| 223 int actual_start, actual_end; |
| 224 EXPECT_TRUE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); |
| 225 if (kTestCases[i].left_to_right) |
| 226 EXPECT_EQ(input_word, actual_word); |
| 227 else |
| 228 EXPECT_NE(input_word, actual_word); |
| 229 } |
| 230 } |
| OLD | NEW |