| Index: chrome/browser/history/query_parser_unittest.cc
|
| diff --git a/chrome/browser/history/query_parser_unittest.cc b/chrome/browser/history/query_parser_unittest.cc
|
| index 4982b304032a009db6aeb96b1f35c9f4ea54b663..3a3b2ef64461475c8bc06504a1287a1eb2794264 100644
|
| --- a/chrome/browser/history/query_parser_unittest.cc
|
| +++ b/chrome/browser/history/query_parser_unittest.cc
|
| @@ -8,6 +8,10 @@
|
| #include "chrome/browser/history/query_parser.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +// Convenience macro to wrap a regexp expression in the expected format.
|
| +#define REGEXP_WB "(\\b|[\\u0E00-\\u0E7F]|[\\u4E00-\\u9FFF])"
|
| +#define REGEXP(MATCH_EXP) ("(?i).*" REGEXP_WB MATCH_EXP REGEXP_WB ".*")
|
| +
|
| class QueryParserTest : public testing::Test {
|
| public:
|
| struct TestData {
|
| @@ -163,3 +167,37 @@ TEST_F(QueryParserTest, ParseQueryWords) {
|
| EXPECT_EQ(data[i].w3, UTF16ToUTF8(results[2]));
|
| }
|
| }
|
| +
|
| +// Test Regexp Queries.
|
| +TEST_F(QueryParserTest, ParseRegexps) {
|
| + struct TestData3 {
|
| + const std::string text;
|
| + const std::string regexp1;
|
| + const std::string regexp2;
|
| + const std::string regexp3;
|
| + const size_t regexp_count;
|
| + } data[] = {
|
| + { "a", REGEXP("a"), "", "", 1 },
|
| + { "foo", REGEXP("foo\\w*"), "", "", 1 },
|
| + { "foo bar", REGEXP("foo\\w*"), REGEXP("bar\\w*"), "", 2 },
|
| + { "\"foo bar\"", REGEXP("foo\\W+bar"), "", "", 1 },
|
| + { "\"foo.com\"", REGEXP("foo\\W+com"), "", "", 1 },
|
| + { "\"foo bar\" a", REGEXP("foo\\W+bar"), REGEXP("a"), "", 2 },
|
| + { "\"foo bar\" a", REGEXP("foo\\W+bar"), REGEXP("a"), "", 2 },
|
| + { "\"miss end", REGEXP("miss\\W+end"), "", "", 1 },
|
| + { "miss beg\"", REGEXP("miss\\w*"), REGEXP("beg\\w*"), "", 2 },
|
| + { "!#:/*foo#$*;'* the!#:/*bar",
|
| + REGEXP("foo\\w*"), REGEXP("the\\w*"), REGEXP("bar\\w*"), 3 }
|
| + };
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
|
| + std::vector<string16> results;
|
| + QueryParser parser;
|
| + parser.ParseQueryAsRegexps(UTF8ToUTF16(data[i].text), &results);
|
| + ASSERT_EQ(data[i].regexp_count, results.size());
|
| + EXPECT_EQ(data[i].regexp1, UTF16ToUTF8(results[0]));
|
| + if (results.size() == 2)
|
| + EXPECT_EQ(data[i].regexp2, UTF16ToUTF8(results[1]));
|
| + if (results.size() == 3)
|
| + EXPECT_EQ(data[i].regexp3, UTF16ToUTF8(results[2]));
|
| + }
|
| +}
|
|
|