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

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

Issue 2891763003: [WIP, DONOTCOMMIT] Test case for multi-result spellcheck (Closed)
Patch Set: Proposed fix 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 // If we have multiple replacements that all differ only by apostrophe type,
1218 // we should ignore this misspelling.
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, we should ignore the misspelling in this case too.
1228 spellcheck_results.push_back(SpellCheckResult(
1229 SpellCheckResult::SPELLING, 0, 5,
1230 std::vector<base::string16>(
1231 {base::UTF8ToUTF16("I've"),
1232 base::WideToUTF16(L"Ik" TYPOGRAPHICAL_APOSTROPHE "ve")})));
1233
1234 // If we have multiple replacements, none of which differ by apostrophe type,
1235 // we should keep this misspelling.
1236 spellcheck_results.push_back(SpellCheckResult(
1237 SpellCheckResult::SPELLING, 6, 10,
1238 std::vector<base::string16>(
1239 {base::UTF8ToUTF16("have"), base::UTF8ToUTF16("haven't")})));
1240
1216 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; 1241 blink::WebVector<blink::WebTextCheckingResult> textcheck_results;
1217 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, 1242 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0,
1218 text, spellcheck_results, 1243 text, spellcheck_results,
1219 &textcheck_results); 1244 &textcheck_results);
1220 1245
1221 static const wchar_t* kExpectedReplacements[] = { 1246 static std::vector<std::vector<const wchar_t*>> kExpectedReplacements = {
1222 L"I've", 1247 {L"I've"},
1223 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", 1248 {L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"},
1224 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's", 1249 {L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's"},
1225 L"I've", 1250 {L"I've"},
1226 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", 1251 {L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"},
1227 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s", 1252 {L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s"},
1253 {L"have", L"haven" TYPOGRAPHICAL_APOSTROPHE "t"},
1228 }; 1254 };
1229 1255
1230 ASSERT_EQ(arraysize(kExpectedReplacements), textcheck_results.size()); 1256 ASSERT_EQ(kExpectedReplacements.size(), textcheck_results.size());
1231 for (size_t i = 0; i < arraysize(kExpectedReplacements); ++i) { 1257 for (size_t i = 0; i < kExpectedReplacements.size(); ++i) {
1232 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i]), 1258 EXPECT_EQ(kExpectedReplacements[i].size(),
1233 textcheck_results[i].replacement.Utf16()) 1259 textcheck_results[i].replacements.size());
1234 << "i=" << i << "\nactual: \"" 1260 for (size_t j = 0; j < kExpectedReplacements[i].size(); ++j) {
1235 << textcheck_results[i].replacement.Utf16() << "\""; 1261 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i][j]),
1262 textcheck_results[i].replacements[j].Utf16())
1263 << "i=" << i << "\nj=" << j << "\nactual: \""
1264 << textcheck_results[i].replacements[j].Utf16() << "\"";
1265 }
1236 } 1266 }
1237 } 1267 }
1238 1268
1239 // Checks some words that should be present in all English dictionaries. 1269 // Checks some words that should be present in all English dictionaries.
1240 TEST_F(SpellCheckTest, EnglishWords) { 1270 TEST_F(SpellCheckTest, EnglishWords) {
1241 static const struct { 1271 static const struct {
1242 const char* input; 1272 const char* input;
1243 bool should_pass; 1273 bool should_pass;
1244 } kTestCases[] = { 1274 } kTestCases[] = {
1245 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking 1275 // 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. 1593 // to be updated accordingly.
1564 ASSERT_EQ(5, spellcheck::kMaxSuggestions); 1594 ASSERT_EQ(5, spellcheck::kMaxSuggestions);
1565 FillSuggestions(suggestions_list, &suggestion_results); 1595 FillSuggestions(suggestions_list, &suggestion_results);
1566 ASSERT_EQ(5U, suggestion_results.size()); 1596 ASSERT_EQ(5U, suggestion_results.size());
1567 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); 1597 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]);
1568 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); 1598 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]);
1569 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); 1599 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]);
1570 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); 1600 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]);
1571 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); 1601 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]);
1572 } 1602 }
OLDNEW
« no previous file with comments | « components/spellcheck/renderer/spellcheck_provider_unittest.cc ('k') | components/spellcheck/renderer/spellcheck_unittest2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698