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

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

Issue 2911253003: [Reland] Allow storing multiple replacements on SpellCheckResult (Closed)
Patch Set: Rebase Created 3 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
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 // If we have no suggested replacements, we should keep this misspelling.
1218 spellcheck_results.push_back(SpellCheckResult(
1219 SpellCheckResult::SPELLING, 0, 5, std::vector<base::string16>()));
1220
1221 // If we have multiple replacements that all differ only by apostrophe type,
1222 // we should ignore this misspelling.
1223 spellcheck_results.push_back(SpellCheckResult(
1224 SpellCheckResult::SPELLING, 0, 11,
1225 std::vector<base::string16>(
1226 {base::UTF8ToUTF16("Ik've havn'"),
1227 base::WideToUTF16(L"Ik" TYPOGRAPHICAL_APOSTROPHE
1228 "ve havn" TYPOGRAPHICAL_APOSTROPHE)})));
1229
1230 // If we have multiple replacements where some only differ by apostrophe type
1231 // and some don't, we should keep this misspelling, but remove the
1232 // replacements that only differ by apostrophe type.
1233 spellcheck_results.push_back(SpellCheckResult(
1234 SpellCheckResult::SPELLING, 0, 5,
1235 std::vector<base::string16>(
1236 {base::UTF8ToUTF16("I've"), base::UTF8ToUTF16("Ive"),
1237 base::WideToUTF16(L"Ik" TYPOGRAPHICAL_APOSTROPHE "ve")})));
1238
1239 // Similar to the previous case except with the apostrophe changing from
1240 // typographical to straight instead of the other direction
1241 spellcheck_results.push_back(SpellCheckResult(
1242 SpellCheckResult::SPELLING, 6, 6,
1243 std::vector<base::string16>({base::UTF8ToUTF16("havn't"),
1244 base::UTF8ToUTF16("havnt"),
1245 base::UTF8ToUTF16("haven't")})));
1246
1247 // If we have multiple replacements, none of which differ only by apostrophe
1248 // type, we should keep this misspelling.
1249 spellcheck_results.push_back(SpellCheckResult(
1250 SpellCheckResult::SPELLING, 6, 6,
1251 std::vector<base::string16>(
1252 {base::UTF8ToUTF16("have"), base::UTF8ToUTF16("haven't")})));
1253
1216 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; 1254 blink::WebVector<blink::WebTextCheckingResult> textcheck_results;
1217 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, 1255 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0,
1218 text, spellcheck_results, 1256 text, spellcheck_results,
1219 &textcheck_results); 1257 &textcheck_results);
1220 1258
1221 static const wchar_t* kExpectedReplacements[] = { 1259 static std::vector<std::vector<const wchar_t*>> kExpectedReplacements = {
1222 L"I've", 1260 {L"I've"},
1223 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", 1261 {L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"},
1224 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's", 1262 {L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's"},
1225 L"I've", 1263 {L"I've"},
1226 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", 1264 {L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"},
1227 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s", 1265 {L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s"},
1266 std::vector<const wchar_t*>(),
1267 {L"I've", L"Ive"},
1268 {L"havnt", L"haven" TYPOGRAPHICAL_APOSTROPHE "t"},
1269 {L"have", L"haven" TYPOGRAPHICAL_APOSTROPHE "t"},
1228 }; 1270 };
1229 1271
1230 ASSERT_EQ(arraysize(kExpectedReplacements), textcheck_results.size()); 1272 ASSERT_EQ(kExpectedReplacements.size(), textcheck_results.size());
1231 for (size_t i = 0; i < arraysize(kExpectedReplacements); ++i) { 1273 for (size_t i = 0; i < kExpectedReplacements.size(); ++i) {
1232 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i]), 1274 EXPECT_EQ(kExpectedReplacements[i].size(),
1233 textcheck_results[i].replacement.Utf16()) 1275 textcheck_results[i].replacements.size());
1234 << "i=" << i << "\nactual: \"" 1276 for (size_t j = 0; j < kExpectedReplacements[i].size(); ++j) {
1235 << textcheck_results[i].replacement.Utf16() << "\""; 1277 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i][j]),
1278 textcheck_results[i].replacements[j].Utf16())
1279 << "i=" << i << "\nj=" << j << "\nactual: \""
1280 << textcheck_results[i].replacements[j].Utf16() << "\"";
1281 }
1236 } 1282 }
1237 } 1283 }
1238 1284
1239 // Checks some words that should be present in all English dictionaries. 1285 // Checks some words that should be present in all English dictionaries.
1240 TEST_F(SpellCheckTest, EnglishWords) { 1286 TEST_F(SpellCheckTest, EnglishWords) {
1241 static const struct { 1287 static const struct {
1242 const char* input; 1288 const char* input;
1243 bool should_pass; 1289 bool should_pass;
1244 } kTestCases[] = { 1290 } kTestCases[] = {
1245 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking 1291 // 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. 1609 // to be updated accordingly.
1564 ASSERT_EQ(5, spellcheck::kMaxSuggestions); 1610 ASSERT_EQ(5, spellcheck::kMaxSuggestions);
1565 FillSuggestions(suggestions_list, &suggestion_results); 1611 FillSuggestions(suggestions_list, &suggestion_results);
1566 ASSERT_EQ(5U, suggestion_results.size()); 1612 ASSERT_EQ(5U, suggestion_results.size());
1567 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); 1613 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]);
1568 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); 1614 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]);
1569 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); 1615 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]);
1570 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); 1616 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]);
1571 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); 1617 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]);
1572 } 1618 }
OLDNEW
« no previous file with comments | « components/spellcheck/renderer/spellcheck_provider_unittest.cc ('k') | content/shell/test_runner/mock_spell_check.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698