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

Side by Side Diff: components/spellcheck/renderer/spellcheck_unittest.cc

Issue 2848943002: Allow storing multiple replacements on SpellCheckResult (Closed)
Patch Set: Respond to comments Created 3 years, 7 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
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 "components/spellcheck/renderer/spellcheck.h" 5 #include "components/spellcheck/renderer/spellcheck.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 4, base::UTF8ToUTF16("I've"))); 1194 4, base::UTF8ToUTF16("I've")));
1195 1195
1196 // All typographical apostrophe results. 1196 // All typographical apostrophe results.
1197 spellcheck_results.push_back( 1197 spellcheck_results.push_back(
1198 SpellCheckResult(SpellCheckResult::SPELLING, 0, 5, 1198 SpellCheckResult(SpellCheckResult::SPELLING, 0, 5,
1199 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); 1199 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")));
1200 spellcheck_results.push_back(SpellCheckResult( 1200 spellcheck_results.push_back(SpellCheckResult(
1201 SpellCheckResult::SPELLING, 6, 6, 1201 SpellCheckResult::SPELLING, 6, 6,
1202 base::WideToUTF16(L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"))); 1202 base::WideToUTF16(L"haven" TYPOGRAPHICAL_APOSTROPHE L"t")));
1203 spellcheck_results.push_back(SpellCheckResult( 1203 spellcheck_results.push_back(SpellCheckResult(
1204 SpellCheckResult::SPELLING, 13, 10, base::WideToUTF16( 1204 SpellCheckResult::SPELLING, 13, 10,
1205 L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"out" 1205 base::WideToUTF16(
1206 TYPOGRAPHICAL_APOSTROPHE L"s"))); 1206 L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"ou"
1207 L"t" TYPOGRAPHICAL_APOSTROPHE L"s")));
1207 1208
1208 // Replacements that differ only by apostrophe type should be ignored. 1209 // Replacements that differ only by apostrophe type should be ignored.
1209 spellcheck_results.push_back( 1210 spellcheck_results.push_back(
1210 SpellCheckResult(SpellCheckResult::SPELLING, 24, 4, 1211 SpellCheckResult(SpellCheckResult::SPELLING, 24, 4,
1211 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); 1212 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")));
1212 spellcheck_results.push_back( 1213 spellcheck_results.push_back(
1213 SpellCheckResult(SpellCheckResult::SPELLING, 29, 4, 1214 SpellCheckResult(SpellCheckResult::SPELLING, 29, 4,
1214 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); 1215 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")));
1215 1216
1217 // Multiple replacements that all only differ by apostrophe type should be
1218 // ignored
1219 spellcheck_results.push_back(SpellCheckResult(
1220 SpellCheckResult::SPELLING, 0, 11,
1221 std::vector<base::string16>(
1222 {base::UTF8ToUTF16("Ik've havn'"),
1223 base::WideToUTF16(L"Ik" TYPOGRAPHICAL_APOSTROPHE
1224 "ve havn" TYPOGRAPHICAL_APOSTROPHE)})));
1225
1226 // If we have multiple replacements where some only differ by apostrophe type
1227 // and some don't, keep those that differ by something other than apostrophe
1228 // type.
1229 spellcheck_results.push_back(SpellCheckResult(
1230 SpellCheckResult::SPELLING, 0, 5,
1231 std::vector<base::string16>(
1232 {base::UTF8ToUTF16("I've"),
1233 base::WideToUTF16(L"Ik" TYPOGRAPHICAL_APOSTROPHE "ve")})));
1234
1216 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; 1235 blink::WebVector<blink::WebTextCheckingResult> textcheck_results;
1217 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, 1236 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0,
1218 text, spellcheck_results, 1237 text, spellcheck_results,
1219 &textcheck_results); 1238 &textcheck_results);
1220 1239
1221 static const wchar_t* kExpectedReplacements[] = { 1240 static std::vector<std::vector<const wchar_t*>> kExpectedReplacements = {
1222 L"I've", 1241 {L"I've"},
1223 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", 1242 {L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"},
1224 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's", 1243 {L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's"},
1225 L"I've", 1244 {L"I've"},
1226 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", 1245 {L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"},
1227 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s", 1246 {L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s"},
1247 {L"I've"},
1228 }; 1248 };
1229 1249
1230 ASSERT_EQ(arraysize(kExpectedReplacements), textcheck_results.size()); 1250 ASSERT_EQ(kExpectedReplacements.size(), textcheck_results.size());
1231 for (size_t i = 0; i < arraysize(kExpectedReplacements); ++i) { 1251 for (size_t i = 0; i < kExpectedReplacements.size(); ++i) {
1232 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i]), 1252 EXPECT_EQ(kExpectedReplacements[i].size(),
1233 textcheck_results[i].replacement.Utf16()) 1253 textcheck_results[i].replacements.size());
1234 << "i=" << i << "\nactual: \"" 1254 for (size_t j = 0; j < kExpectedReplacements[i].size(); ++j) {
1235 << textcheck_results[i].replacement.Utf16() << "\""; 1255 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i][j]),
1256 textcheck_results[i].replacements[j].Utf16())
1257 << "i=" << i << "\nj=" << j << "\nactual: \""
1258 << textcheck_results[i].replacements[j].Utf16() << "\"";
1259 }
1236 } 1260 }
1237 } 1261 }
1238 1262
1239 // Checks some words that should be present in all English dictionaries. 1263 // Checks some words that should be present in all English dictionaries.
1240 TEST_F(SpellCheckTest, EnglishWords) { 1264 TEST_F(SpellCheckTest, EnglishWords) {
1241 static const struct { 1265 static const struct {
1242 const char* input; 1266 const char* input;
1243 bool should_pass; 1267 bool should_pass;
1244 } kTestCases[] = { 1268 } kTestCases[] = {
1245 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking 1269 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 // to be updated accordingly. 1587 // to be updated accordingly.
1564 ASSERT_EQ(5, spellcheck::kMaxSuggestions); 1588 ASSERT_EQ(5, spellcheck::kMaxSuggestions);
1565 FillSuggestions(suggestions_list, &suggestion_results); 1589 FillSuggestions(suggestions_list, &suggestion_results);
1566 ASSERT_EQ(5U, suggestion_results.size()); 1590 ASSERT_EQ(5U, suggestion_results.size());
1567 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); 1591 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]);
1568 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); 1592 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]);
1569 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); 1593 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]);
1570 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); 1594 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]);
1571 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); 1595 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]);
1572 } 1596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698