summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/query_parser_unittest.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-29 19:48:58 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-29 19:48:58 +0000
commit6956cd63fd86015d328a3dfb669a68f34c5e21fa (patch)
tree10faa0ef5e17e000768e26e19b7777dea8186daa /chrome/browser/history/query_parser_unittest.cc
parentd364c659874cdc48ea7d2e6e26c9df1335be1863 (diff)
downloadchromium_src-6956cd63fd86015d328a3dfb669a68f34c5e21fa.zip
chromium_src-6956cd63fd86015d328a3dfb669a68f34c5e21fa.tar.gz
chromium_src-6956cd63fd86015d328a3dfb669a68f34c5e21fa.tar.bz2
Modifies the query parser to provide the position of the match in the
title. I'm going to use this in the omnibox. There are a couple of other random spelling errors I came across that are included for your review pleasure. BUG=1256202 TEST=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1546 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history/query_parser_unittest.cc')
-rw-r--r--chrome/browser/history/query_parser_unittest.cc42
1 files changed, 30 insertions, 12 deletions
diff --git a/chrome/browser/history/query_parser_unittest.cc b/chrome/browser/history/query_parser_unittest.cc
index d026df1..1e0b36d 100644
--- a/chrome/browser/history/query_parser_unittest.cc
+++ b/chrome/browser/history/query_parser_unittest.cc
@@ -88,25 +88,43 @@ TEST_F(QueryParserTest, ParseQueryNodesAndMatch) {
const std::wstring query;
const std::wstring text;
const bool matches;
+ const int m1_start;
+ const int m1_end;
+ const int m2_start;
+ const int m2_end;
} data[] = {
- { L"blah", L"blah", true },
- { L"blah", L"foo", false },
- { L"blah", L"blahblah", true },
- { L"blah", L"foo blah", true },
- { L"foo blah", L"blah", false },
- { L"foo blah", L"blahx foobar", true },
- { L"\"foo blah\"", L"foo blah", true },
- { L"\"foo blah\"", L"foox blahx", false },
- { L"\"foo blah\"", L"foo blah", true },
- { L"\"foo blah\"", L"\"foo blah\"", true },
- { L"foo blah", L"\"foo bar blah\"", true },
+ { L"blah", L"blah", true, 0, 4, 0, 0 },
+ { L"blah", L"foo", false, 0, 0, 0, 0 },
+ { L"blah", L"blahblah", true, 0, 4, 0, 0 },
+ { L"blah", L"foo blah", true, 4, 8, 0, 0 },
+ { L"foo blah", L"blah", false, 0, 0, 0, 0 },
+ { L"foo blah", L"blahx foobar", true, 6, 9, 0, 4 },
+ { L"\"foo blah\"", L"foo blah", true, 0, 8, 0, 0 },
+ { L"\"foo blah\"", L"foox blahx", false, 0, 0, 0, 0 },
+ { L"\"foo blah\"", L"foo blah", true, 0, 8, 0, 0 },
+ { L"\"foo blah\"", L"\"foo blah\"", true, 1, 9, 0, 0 },
+ { L"foo blah", L"\"foo bar blah\"", true, 1, 4, 9, 13 },
};
for (int i = 0; i < arraysize(data); ++i) {
std::vector<std::wstring> results;
QueryParser parser;
ScopedVector<QueryNode> query_nodes;
parser.ParseQuery(data[i].query, &query_nodes.get());
+ Snippet::MatchPositions match_positions;
ASSERT_EQ(data[i].matches,
- parser.DoesQueryMatch(data[i].text, query_nodes.get()));
+ parser.DoesQueryMatch(data[i].text, query_nodes.get(),
+ &match_positions));
+ size_t offset = 0;
+ if (data[i].m1_start != 0 || data[i].m1_end != 0) {
+ ASSERT_TRUE(match_positions.size() >= 1);
+ EXPECT_EQ(data[i].m1_start, match_positions[0].first);
+ EXPECT_EQ(data[i].m1_end, match_positions[0].second);
+ offset++;
+ }
+ if (data[i].m2_start != 0 || data[i].m2_end != 0) {
+ ASSERT_TRUE(match_positions.size() == 1 + offset);
+ EXPECT_EQ(data[i].m2_start, match_positions[offset].first);
+ EXPECT_EQ(data[i].m2_end, match_positions[offset].second);
+ }
}
}