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

Side by Side Diff: chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc

Issue 1092243002: Handle typographical apostrophe with spelling service client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: base::char16 Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698