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

Side by Side Diff: content/shell/renderer/test_runner/MockGrammarCheck.cpp

Issue 110533009: Import TestRunner library into chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/shell/renderer/test_runner/MockGrammarCheck.h"
6
7 #include <algorithm>
8
9 #include "content/shell/renderer/test_runner/TestCommon.h"
10 #include "third_party/WebKit/public/platform/WebCString.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
12 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
13
14 using namespace blink;
15 using namespace std;
16
17 namespace WebTestRunner {
18
19 bool MockGrammarCheck::checkGrammarOfString(const WebString& text, vector<WebTex tCheckingResult>* results)
20 {
21 BLINK_ASSERT(results);
22 string16 stringText = text;
23 if (find_if(stringText.begin(), stringText.end(), isASCIIAlpha) == stringTex t.end())
24 return true;
25
26 // Find matching grammatical errors from known ones. This function has to
27 // check all errors because the given text may consist of two or more
28 // sentences that have grammatical errors.
29 static const struct {
30 const char* text;
31 int location;
32 int length;
33 } grammarErrors[] = {
34 {"I have a issue.", 7, 1},
35 {"I have an grape.", 7, 2},
36 {"I have an kiwi.", 7, 2},
37 {"I have an muscat.", 7, 2},
38 {"You has the right.", 4, 3},
39 {"apple orange zz.", 0, 16},
40 {"apple zz orange.", 0, 16},
41 {"apple,zz,orange.", 0, 16},
42 {"orange,zz,apple.", 0, 16},
43 {"the the adlj adaasj sdklj. there there", 4, 3},
44 {"the the adlj adaasj sdklj. there there", 33, 5},
45 {"zz apple orange.", 0, 16},
46 };
47 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(grammarErrors); ++i) {
48 size_t offset = 0;
49 string16 error(grammarErrors[i].text, grammarErrors[i].text + strlen(gra mmarErrors[i].text));
50 while ((offset = stringText.find(error, offset)) != string16::npos) {
51 results->push_back(WebTextCheckingResult(WebTextDecorationTypeGramma r, offset + grammarErrors[i].location, grammarErrors[i].length));
52 offset += grammarErrors[i].length;
53 }
54 }
55 return false;
56 }
57
58 }
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/MockGrammarCheck.h ('k') | content/shell/renderer/test_runner/MockSpellCheck.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698