Chromium Code Reviews| 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/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 kTestCases[i].allow_contraction)); | 134 kTestCases[i].allow_contraction)); |
| 135 EXPECT_TRUE(iterator.SetText(input.c_str(), input.length())); | 135 EXPECT_TRUE(iterator.SetText(input.c_str(), input.length())); |
| 136 | 136 |
| 137 std::vector<base::string16> expected_words = base::SplitString( | 137 std::vector<base::string16> expected_words = base::SplitString( |
| 138 base::WideToUTF16(kTestCases[i].expected_words), | 138 base::WideToUTF16(kTestCases[i].expected_words), |
| 139 base::string16(1, ' '), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 139 base::string16(1, ' '), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 140 | 140 |
| 141 base::string16 actual_word; | 141 base::string16 actual_word; |
| 142 int actual_start, actual_end; | 142 int actual_start, actual_end; |
| 143 size_t index = 0; | 143 size_t index = 0; |
| 144 while (iterator.GetNextWord(&actual_word, &actual_start, &actual_end)) { | 144 SpellcheckWordIterator::WordIteratorStatus status = |
| 145 iterator.GetNextWord(&actual_word, &actual_start, &actual_end); | |
|
please use gerrit instead
2015/08/11 22:54:11
for loop the heck out of this one.
Julius
2015/08/12 20:25:59
Done.
| |
| 146 while (status != | |
| 147 SpellcheckWordIterator::WordIteratorStatus::IS_END_OF_TEXT) { | |
| 148 if (status == | |
| 149 SpellcheckWordIterator::WordIteratorStatus::IS_SKIPPABLE_CHAR) { | |
| 150 status = iterator.GetNextWord(&actual_word, &actual_start, &actual_end); | |
| 151 continue; | |
| 152 } | |
| 145 EXPECT_TRUE(index < expected_words.size()); | 153 EXPECT_TRUE(index < expected_words.size()); |
| 146 if (index < expected_words.size()) | 154 if (index < expected_words.size()) |
| 147 EXPECT_EQ(expected_words[index], actual_word); | 155 EXPECT_EQ(expected_words[index], actual_word); |
| 148 ++index; | 156 ++index; |
| 157 status = iterator.GetNextWord(&actual_word, &actual_start, &actual_end); | |
| 149 } | 158 } |
| 150 } | 159 } |
| 151 } | 160 } |
| 152 | 161 |
| 153 // Tests whether our SpellcheckWordIterator extracts an empty word without | 162 // Tests whether our SpellcheckWordIterator extracts an empty word without |
| 154 // getting stuck in an infinite loop when inputting a Khmer text. (This is a | 163 // getting stuck in an infinite loop when inputting a Khmer text. (This is a |
| 155 // regression test for Issue 46278.) | 164 // regression test for Issue 46278.) |
| 156 TEST(SpellcheckWordIteratorTest, RuleSetConsistency) { | 165 TEST(SpellcheckWordIteratorTest, RuleSetConsistency) { |
| 157 SpellcheckCharAttribute attributes; | 166 SpellcheckCharAttribute attributes; |
| 158 attributes.SetDefaultLanguage("en-US"); | 167 attributes.SetDefaultLanguage("en-US"); |
| 159 | 168 |
| 160 const wchar_t kTestText[] = L"\x1791\x17c1\x002e"; | 169 const wchar_t kTestText[] = L"\x1791\x17c1\x002e"; |
| 161 base::string16 input(base::WideToUTF16(kTestText)); | 170 base::string16 input(base::WideToUTF16(kTestText)); |
| 162 | 171 |
| 163 SpellcheckWordIterator iterator; | 172 SpellcheckWordIterator iterator; |
| 164 EXPECT_TRUE(iterator.Initialize(&attributes, true)); | 173 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
| 165 EXPECT_TRUE(iterator.SetText(input.c_str(), input.length())); | 174 EXPECT_TRUE(iterator.SetText(input.c_str(), input.length())); |
| 166 | 175 |
| 167 // When SpellcheckWordIterator uses an inconsistent ICU ruleset, the following | 176 // When SpellcheckWordIterator uses an inconsistent ICU ruleset, the following |
| 168 // iterator.GetNextWord() call gets stuck in an infinite loop. Therefore, this | 177 // iterator.GetNextWord() call gets stuck in an infinite loop. Therefore, this |
| 169 // test succeeds if this call returns without timeouts. | 178 // test succeeds if this call returns without timeouts. |
| 170 base::string16 actual_word; | 179 base::string16 actual_word; |
| 171 int actual_start, actual_end; | 180 int actual_start, actual_end; |
| 172 EXPECT_FALSE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); | 181 SpellcheckWordIterator::WordIteratorStatus status; |
|
please use gerrit instead
2015/08/11 22:54:11
for loop.
Julius
2015/08/12 20:25:59
Done.
| |
| 182 do { | |
| 183 status = iterator.GetNextWord(&actual_word, &actual_start, &actual_end); | |
| 184 } while (status == | |
| 185 SpellcheckWordIterator::WordIteratorStatus::IS_SKIPPABLE_CHAR); | |
| 186 | |
| 187 EXPECT_EQ(status, SpellcheckWordIterator::WordIteratorStatus::IS_END_OF_TEXT); | |
|
please use gerrit instead
2015/08/11 22:54:11
Expected value (SpellcheckWordIterator::WordIterat
Julius
2015/08/12 20:25:59
Done.
| |
| 173 EXPECT_EQ(0, actual_start); | 188 EXPECT_EQ(0, actual_start); |
| 174 EXPECT_EQ(0, actual_end); | 189 EXPECT_EQ(0, actual_end); |
| 175 } | 190 } |
| 176 | 191 |
| 177 // Vertify our SpellcheckWordIterator can treat ASCII numbers as word characters | 192 // Vertify our SpellcheckWordIterator can treat ASCII numbers as word characters |
| 178 // on LTR languages. On the other hand, it should not treat ASCII numbers as | 193 // on LTR languages. On the other hand, it should not treat ASCII numbers as |
| 179 // word characters on RTL languages because they change the text direction from | 194 // word characters on RTL languages because they change the text direction from |
| 180 // RTL to LTR. | 195 // RTL to LTR. |
| 181 TEST(SpellcheckWordIteratorTest, TreatNumbersAsWordCharacters) { | 196 TEST(SpellcheckWordIteratorTest, TreatNumbersAsWordCharacters) { |
| 182 // A set of a language, a dummy word, and a text direction used in this test. | 197 // A set of a language, a dummy word, and a text direction used in this test. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 SpellcheckCharAttribute attributes; | 238 SpellcheckCharAttribute attributes; |
| 224 attributes.SetDefaultLanguage(kTestCases[i].language); | 239 attributes.SetDefaultLanguage(kTestCases[i].language); |
| 225 | 240 |
| 226 base::string16 input_word(base::WideToUTF16(kTestCases[i].text)); | 241 base::string16 input_word(base::WideToUTF16(kTestCases[i].text)); |
| 227 SpellcheckWordIterator iterator; | 242 SpellcheckWordIterator iterator; |
| 228 EXPECT_TRUE(iterator.Initialize(&attributes, true)); | 243 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
| 229 EXPECT_TRUE(iterator.SetText(input_word.c_str(), input_word.length())); | 244 EXPECT_TRUE(iterator.SetText(input_word.c_str(), input_word.length())); |
| 230 | 245 |
| 231 base::string16 actual_word; | 246 base::string16 actual_word; |
| 232 int actual_start, actual_end; | 247 int actual_start, actual_end; |
| 233 EXPECT_TRUE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); | 248 SpellcheckWordIterator::WordIteratorStatus status; |
|
please use gerrit instead
2015/08/11 22:54:11
for
loop
Julius
2015/08/12 20:25:59
D
o
n
e
.
| |
| 249 do { | |
| 250 status = iterator.GetNextWord(&actual_word, &actual_start, &actual_end); | |
| 251 } while (status == | |
| 252 SpellcheckWordIterator::WordIteratorStatus::IS_SKIPPABLE_CHAR); | |
| 253 | |
| 254 EXPECT_EQ(status, SpellcheckWordIterator::WordIteratorStatus::IS_WORD); | |
| 234 if (kTestCases[i].left_to_right) | 255 if (kTestCases[i].left_to_right) |
| 235 EXPECT_EQ(input_word, actual_word); | 256 EXPECT_EQ(input_word, actual_word); |
| 236 else | 257 else |
| 237 EXPECT_NE(input_word, actual_word); | 258 EXPECT_NE(input_word, actual_word); |
| 238 } | 259 } |
| 239 } | 260 } |
| 240 | 261 |
| 241 // Vertify SpellcheckWordIterator treats typographical apostrophe as a part of | 262 // Vertify SpellcheckWordIterator treats typographical apostrophe as a part of |
| 242 // the word. | 263 // the word. |
| 243 TEST(SpellcheckWordIteratorTest, TypographicalApostropheIsPartOfWord) { | 264 TEST(SpellcheckWordIteratorTest, TypographicalApostropheIsPartOfWord) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 271 SpellcheckCharAttribute attributes; | 292 SpellcheckCharAttribute attributes; |
| 272 attributes.SetDefaultLanguage(kTestCases[i].language); | 293 attributes.SetDefaultLanguage(kTestCases[i].language); |
| 273 | 294 |
| 274 base::string16 input_word(base::WideToUTF16(kTestCases[i].word)); | 295 base::string16 input_word(base::WideToUTF16(kTestCases[i].word)); |
| 275 SpellcheckWordIterator iterator; | 296 SpellcheckWordIterator iterator; |
| 276 EXPECT_TRUE(iterator.Initialize(&attributes, true)); | 297 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
| 277 EXPECT_TRUE(iterator.SetText(input_word.c_str(), input_word.length())); | 298 EXPECT_TRUE(iterator.SetText(input_word.c_str(), input_word.length())); |
| 278 | 299 |
| 279 base::string16 actual_word; | 300 base::string16 actual_word; |
| 280 int actual_start, actual_end; | 301 int actual_start, actual_end; |
| 281 EXPECT_TRUE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); | 302 SpellcheckWordIterator::WordIteratorStatus status; |
| 303 do { | |
| 304 status = iterator.GetNextWord(&actual_word, &actual_start, &actual_end); | |
| 305 } while (status == | |
| 306 SpellcheckWordIterator::WordIteratorStatus::IS_SKIPPABLE_CHAR); | |
| 307 | |
| 308 EXPECT_EQ(status, SpellcheckWordIterator::WordIteratorStatus::IS_WORD); | |
| 282 EXPECT_EQ(input_word, actual_word); | 309 EXPECT_EQ(input_word, actual_word); |
| 283 EXPECT_EQ(0, actual_start); | 310 EXPECT_EQ(0, actual_start); |
| 284 EXPECT_EQ(input_word.length(), | 311 EXPECT_EQ(input_word.length(), |
| 285 static_cast<base::string16::size_type>(actual_end)); | 312 static_cast<base::string16::size_type>(actual_end)); |
| 286 } | 313 } |
| 287 } | 314 } |
| 288 | 315 |
| 289 TEST(SpellcheckWordIteratorTest, Initialization) { | 316 TEST(SpellcheckWordIteratorTest, Initialization) { |
| 290 // Test initialization works when a default language is set. | 317 // Test initialization works when a default language is set. |
| 291 { | 318 { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 EXPECT_EQ(base::UTF8ToUTF16("."), iter.GetString()); | 470 EXPECT_EQ(base::UTF8ToUTF16("."), iter.GetString()); |
| 444 EXPECT_EQ(iter.GetWordBreakStatus(), BreakIterator::IS_SKIPPABLE_WORD); | 471 EXPECT_EQ(iter.GetWordBreakStatus(), BreakIterator::IS_SKIPPABLE_WORD); |
| 445 EXPECT_TRUE(iter.Advance()); | 472 EXPECT_TRUE(iter.Advance()); |
| 446 EXPECT_EQ(base::UTF8ToUTF16(" "), iter.GetString()); | 473 EXPECT_EQ(base::UTF8ToUTF16(" "), iter.GetString()); |
| 447 EXPECT_EQ(iter.GetWordBreakStatus(), BreakIterator::IS_SKIPPABLE_WORD); | 474 EXPECT_EQ(iter.GetWordBreakStatus(), BreakIterator::IS_SKIPPABLE_WORD); |
| 448 EXPECT_TRUE(iter.Advance()); | 475 EXPECT_TRUE(iter.Advance()); |
| 449 EXPECT_EQ(base::UTF8ToUTF16(","), iter.GetString()); | 476 EXPECT_EQ(base::UTF8ToUTF16(","), iter.GetString()); |
| 450 EXPECT_EQ(iter.GetWordBreakStatus(), BreakIterator::IS_SKIPPABLE_WORD); | 477 EXPECT_EQ(iter.GetWordBreakStatus(), BreakIterator::IS_SKIPPABLE_WORD); |
| 451 EXPECT_FALSE(iter.Advance()); | 478 EXPECT_FALSE(iter.Advance()); |
| 452 } | 479 } |
| OLD | NEW |