| 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 | |
| 280 TEST(SpellcheckWordIteratorTest, Initialization) { | 232 TEST(SpellcheckWordIteratorTest, Initialization) { |
| 281 // Test initialization works when a default language is set. | 233 // Test initialization works when a default language is set. |
| 282 { | 234 { |
| 283 SpellcheckCharAttribute attributes; | 235 SpellcheckCharAttribute attributes; |
| 284 attributes.SetDefaultLanguage("en-US"); | 236 attributes.SetDefaultLanguage("en-US"); |
| 285 | 237 |
| 286 SpellcheckWordIterator iterator; | 238 SpellcheckWordIterator iterator; |
| 287 EXPECT_TRUE(iterator.Initialize(&attributes, true)); | 239 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
| 288 } | 240 } |
| 289 | 241 |
| 290 // Test initialization fails when no default language is set. | 242 // Test initialization fails when no default language is set. |
| 291 { | 243 { |
| 292 SpellcheckCharAttribute attributes; | 244 SpellcheckCharAttribute attributes; |
| 293 | 245 |
| 294 SpellcheckWordIterator iterator; | 246 SpellcheckWordIterator iterator; |
| 295 EXPECT_FALSE(iterator.Initialize(&attributes, true)); | 247 EXPECT_FALSE(iterator.Initialize(&attributes, true)); |
| 296 } | 248 } |
| 297 } | 249 } |
| OLD | NEW |