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

Side by Side Diff: chrome/browser/history/query_parser_unittest.cc

Issue 16776004: Replace FTS in the history_service with a brute force text search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix kSafeRegexWordBoundary for Korean. Created 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/history/query_parser.h" 8 #include "chrome/browser/history/query_parser.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 // Convenience macro to wrap a regexp expression in the expected format.
12 #define REGEXP_WB "(\\b|[\\u0E00-\\u0E7F]|[\\u4E00-\\u9FFF])"
13 #define REGEXP(MATCH_EXP) ("(?i).*" REGEXP_WB MATCH_EXP REGEXP_WB ".*")
14
11 class QueryParserTest : public testing::Test { 15 class QueryParserTest : public testing::Test {
12 public: 16 public:
13 struct TestData { 17 struct TestData {
14 const char* input; 18 const char* input;
15 const int expected_word_count; 19 const int expected_word_count;
16 }; 20 };
17 21
18 std::string QueryToString(const std::string& query); 22 std::string QueryToString(const std::string& query);
19 23
20 protected: 24 protected:
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 QueryParser parser; 160 QueryParser parser;
157 parser.ParseQueryWords(UTF8ToUTF16(data[i].text), &results); 161 parser.ParseQueryWords(UTF8ToUTF16(data[i].text), &results);
158 ASSERT_EQ(data[i].word_count, results.size()); 162 ASSERT_EQ(data[i].word_count, results.size());
159 EXPECT_EQ(data[i].w1, UTF16ToUTF8(results[0])); 163 EXPECT_EQ(data[i].w1, UTF16ToUTF8(results[0]));
160 if (results.size() == 2) 164 if (results.size() == 2)
161 EXPECT_EQ(data[i].w2, UTF16ToUTF8(results[1])); 165 EXPECT_EQ(data[i].w2, UTF16ToUTF8(results[1]));
162 if (results.size() == 3) 166 if (results.size() == 3)
163 EXPECT_EQ(data[i].w3, UTF16ToUTF8(results[2])); 167 EXPECT_EQ(data[i].w3, UTF16ToUTF8(results[2]));
164 } 168 }
165 } 169 }
170
171 // Test Regexp Queries.
172 TEST_F(QueryParserTest, ParseRegexps) {
173 struct TestData3 {
174 const std::string text;
175 const std::string regexp1;
176 const std::string regexp2;
177 const std::string regexp3;
178 const size_t regexp_count;
179 } data[] = {
180 { "a", REGEXP("a"), "", "", 1 },
181 { "foo", REGEXP("foo\\w*"), "", "", 1 },
182 { "foo bar", REGEXP("foo\\w*"), REGEXP("bar\\w*"), "", 2 },
183 { "\"foo bar\"", REGEXP("foo\\W+bar"), "", "", 1 },
184 { "\"foo.com\"", REGEXP("foo\\W+com"), "", "", 1 },
185 { "\"foo bar\" a", REGEXP("foo\\W+bar"), REGEXP("a"), "", 2 },
186 { "\"foo bar\" a", REGEXP("foo\\W+bar"), REGEXP("a"), "", 2 },
187 { "\"miss end", REGEXP("miss\\W+end"), "", "", 1 },
188 { "miss beg\"", REGEXP("miss\\w*"), REGEXP("beg\\w*"), "", 2 },
189 { "!#:/*foo#$*;'* the!#:/*bar",
190 REGEXP("foo\\w*"), REGEXP("the\\w*"), REGEXP("bar\\w*"), 3 }
191 };
192 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
193 std::vector<string16> results;
194 QueryParser parser;
195 parser.ParseQueryAsRegexps(UTF8ToUTF16(data[i].text), &results);
196 ASSERT_EQ(data[i].regexp_count, results.size());
197 EXPECT_EQ(data[i].regexp1, UTF16ToUTF8(results[0]));
198 if (results.size() == 2)
199 EXPECT_EQ(data[i].regexp2, UTF16ToUTF8(results[1]));
200 if (results.size() == 3)
201 EXPECT_EQ(data[i].regexp3, UTF16ToUTF8(results[2]));
202 }
203 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698