OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/query_parser/query_parser.h" | 8 #include "components/query_parser/query_parser.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 { "blah", "blahblah", true, 0, 4, 0, 0 }, | 109 { "blah", "blahblah", true, 0, 4, 0, 0 }, |
110 { "blah", "foo blah", true, 4, 8, 0, 0 }, | 110 { "blah", "foo blah", true, 4, 8, 0, 0 }, |
111 { "foo blah", "blah", false, 0, 0, 0, 0 }, | 111 { "foo blah", "blah", false, 0, 0, 0, 0 }, |
112 { "foo blah", "blahx foobar", true, 0, 4, 6, 9 }, | 112 { "foo blah", "blahx foobar", true, 0, 4, 6, 9 }, |
113 { "\"foo blah\"", "foo blah", true, 0, 8, 0, 0 }, | 113 { "\"foo blah\"", "foo blah", true, 0, 8, 0, 0 }, |
114 { "\"foo blah\"", "foox blahx", false, 0, 0, 0, 0 }, | 114 { "\"foo blah\"", "foox blahx", false, 0, 0, 0, 0 }, |
115 { "\"foo blah\"", "foo blah", true, 0, 8, 0, 0 }, | 115 { "\"foo blah\"", "foo blah", true, 0, 8, 0, 0 }, |
116 { "\"foo blah\"", "\"foo blah\"", true, 1, 9, 0, 0 }, | 116 { "\"foo blah\"", "\"foo blah\"", true, 1, 9, 0, 0 }, |
117 { "foo blah", "\"foo bar blah\"", true, 1, 4, 9, 13 }, | 117 { "foo blah", "\"foo bar blah\"", true, 1, 4, 9, 13 }, |
118 }; | 118 }; |
119 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 119 for (size_t i = 0; i < arraysize(data); ++i) { |
120 QueryParser parser; | 120 QueryParser parser; |
121 ScopedVector<QueryNode> query_nodes; | 121 ScopedVector<QueryNode> query_nodes; |
122 parser.ParseQueryNodes(base::UTF8ToUTF16(data[i].query), | 122 parser.ParseQueryNodes(base::UTF8ToUTF16(data[i].query), |
123 &query_nodes.get()); | 123 &query_nodes.get()); |
124 Snippet::MatchPositions match_positions; | 124 Snippet::MatchPositions match_positions; |
125 ASSERT_EQ(data[i].matches, | 125 ASSERT_EQ(data[i].matches, |
126 parser.DoesQueryMatch(base::UTF8ToUTF16(data[i].text), | 126 parser.DoesQueryMatch(base::UTF8ToUTF16(data[i].text), |
127 query_nodes.get(), | 127 query_nodes.get(), |
128 &match_positions)); | 128 &match_positions)); |
129 size_t offset = 0; | 129 size_t offset = 0; |
(...skipping 17 matching lines...) Expand all Loading... |
147 const std::string w1; | 147 const std::string w1; |
148 const std::string w2; | 148 const std::string w2; |
149 const std::string w3; | 149 const std::string w3; |
150 const size_t word_count; | 150 const size_t word_count; |
151 } data[] = { | 151 } data[] = { |
152 { "foo", "foo", "", "", 1 }, | 152 { "foo", "foo", "", "", 1 }, |
153 { "foo bar", "foo", "bar", "", 2 }, | 153 { "foo bar", "foo", "bar", "", 2 }, |
154 { "\"foo bar\"", "foo", "bar", "", 2 }, | 154 { "\"foo bar\"", "foo", "bar", "", 2 }, |
155 { "\"foo bar\" a", "foo", "bar", "a", 3 }, | 155 { "\"foo bar\" a", "foo", "bar", "a", 3 }, |
156 }; | 156 }; |
157 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 157 for (size_t i = 0; i < arraysize(data); ++i) { |
158 std::vector<base::string16> results; | 158 std::vector<base::string16> results; |
159 QueryParser parser; | 159 QueryParser parser; |
160 parser.ParseQueryWords(base::UTF8ToUTF16(data[i].text), &results); | 160 parser.ParseQueryWords(base::UTF8ToUTF16(data[i].text), &results); |
161 ASSERT_EQ(data[i].word_count, results.size()); | 161 ASSERT_EQ(data[i].word_count, results.size()); |
162 EXPECT_EQ(data[i].w1, base::UTF16ToUTF8(results[0])); | 162 EXPECT_EQ(data[i].w1, base::UTF16ToUTF8(results[0])); |
163 if (results.size() == 2) | 163 if (results.size() == 2) |
164 EXPECT_EQ(data[i].w2, base::UTF16ToUTF8(results[1])); | 164 EXPECT_EQ(data[i].w2, base::UTF16ToUTF8(results[1])); |
165 if (results.size() == 3) | 165 if (results.size() == 3) |
166 EXPECT_EQ(data[i].w3, base::UTF16ToUTF8(results[2])); | 166 EXPECT_EQ(data[i].w3, base::UTF16ToUTF8(results[2])); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 } // namespace query_parser | 170 } // namespace query_parser |
OLD | NEW |