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/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 base::string16 actual_word; | 222 base::string16 actual_word; |
223 int actual_start, actual_end; | 223 int actual_start, actual_end; |
224 EXPECT_TRUE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); | 224 EXPECT_TRUE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); |
225 if (kTestCases[i].left_to_right) | 225 if (kTestCases[i].left_to_right) |
226 EXPECT_EQ(input_word, actual_word); | 226 EXPECT_EQ(input_word, actual_word); |
227 else | 227 else |
228 EXPECT_NE(input_word, actual_word); | 228 EXPECT_NE(input_word, actual_word); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
| 232 // Vertify SpellcheckWordIterator treats typographical apostrophe as a part of |
| 233 // the word. |
| 234 TEST(SpellcheckWordIteratorTest, TypographicalApostropheIsPartOfWord) { |
| 235 static const struct { |
| 236 const char* language; |
| 237 const wchar_t* word; |
| 238 } kTestCases[] = { |
| 239 // Typewriter apostrophe: |
| 240 { |
| 241 "en-AU", L"you're" |
| 242 }, { |
| 243 "en-CA", L"you're" |
| 244 }, { |
| 245 "en-GB", L"you're" |
| 246 }, { |
| 247 "en-US", L"you're" |
| 248 }, |
| 249 // Typographical apostrophe: |
| 250 { |
| 251 "en-AU", L"you\x2019re" |
| 252 }, { |
| 253 "en-CA", L"you\x2019re" |
| 254 }, { |
| 255 "en-GB", L"you\x2019re" |
| 256 }, { |
| 257 "en-US", L"you\x2019re" |
| 258 }, |
| 259 }; |
| 260 |
| 261 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 262 SpellcheckCharAttribute attributes; |
| 263 attributes.SetDefaultLanguage(kTestCases[i].language); |
| 264 |
| 265 base::string16 input_word(base::WideToUTF16(kTestCases[i].word)); |
| 266 SpellcheckWordIterator iterator; |
| 267 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
| 268 EXPECT_TRUE(iterator.SetText(input_word.c_str(), input_word.length())); |
| 269 |
| 270 base::string16 actual_word; |
| 271 int actual_start, actual_end; |
| 272 EXPECT_TRUE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); |
| 273 EXPECT_EQ(input_word, actual_word); |
| 274 EXPECT_EQ(0, actual_start); |
| 275 EXPECT_EQ(input_word.length(), |
| 276 static_cast<base::string16::size_type>(actual_end)); |
| 277 } |
| 278 } |
| 279 |
232 TEST(SpellcheckWordIteratorTest, Initialization) { | 280 TEST(SpellcheckWordIteratorTest, Initialization) { |
233 // Test initialization works when a default language is set. | 281 // Test initialization works when a default language is set. |
234 { | 282 { |
235 SpellcheckCharAttribute attributes; | 283 SpellcheckCharAttribute attributes; |
236 attributes.SetDefaultLanguage("en-US"); | 284 attributes.SetDefaultLanguage("en-US"); |
237 | 285 |
238 SpellcheckWordIterator iterator; | 286 SpellcheckWordIterator iterator; |
239 EXPECT_TRUE(iterator.Initialize(&attributes, true)); | 287 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
240 } | 288 } |
241 | 289 |
242 // Test initialization fails when no default language is set. | 290 // Test initialization fails when no default language is set. |
243 { | 291 { |
244 SpellcheckCharAttribute attributes; | 292 SpellcheckCharAttribute attributes; |
245 | 293 |
246 SpellcheckWordIterator iterator; | 294 SpellcheckWordIterator iterator; |
247 EXPECT_FALSE(iterator.Initialize(&attributes, true)); | 295 EXPECT_FALSE(iterator.Initialize(&attributes, true)); |
248 } | 296 } |
249 } | 297 } |
OLD | NEW |