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

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

Issue 9316129: Don't strip punctuation inside quotes in history search queries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New patch based on chat with mrossetti. Created 8 years, 10 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 | Annotate | Revision Log
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/utf_string_conversions.h" 7 #include "base/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
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // Quoted substring parsing. 50 // Quoted substring parsing.
51 TEST_F(QueryParserTest, Quoted) { 51 TEST_F(QueryParserTest, Quoted) {
52 // ASCII quotes 52 // ASCII quotes
53 EXPECT_EQ("\"Quoted\"", QueryToString("\"Quoted\"")); 53 EXPECT_EQ("\"Quoted\"", QueryToString("\"Quoted\""));
54 // Missing end quotes 54 // Missing end quotes
55 EXPECT_EQ("\"miss end\"", QueryToString("\"miss end")); 55 EXPECT_EQ("\"miss end\"", QueryToString("\"miss end"));
56 // Missing begin quotes 56 // Missing begin quotes
57 EXPECT_EQ("miss* beg*", QueryToString("miss beg\"")); 57 EXPECT_EQ("miss* beg*", QueryToString("miss beg\""));
58 // Weird formatting 58 // Weird formatting
59 EXPECT_EQ("\"Many\" \"quotes\"", QueryToString("\"Many \"\"quotes")); 59 EXPECT_EQ("\"Many\" \"quotes\"", QueryToString("\"Many \"\"quotes"));
60 EXPECT_EQ("\"ab\" cd \"ef\"", QueryToString("\"ab\" cd \"ef\""));
61 EXPECT_EQ("tra* \"la\" la", QueryToString("tra \"la\" la"));
60 } 62 }
61 63
62 // Apostrophes within words should be preserved, but otherwise stripped. 64 // Apostrophes within words should be preserved, but otherwise stripped.
63 TEST_F(QueryParserTest, Apostrophes) { 65 TEST_F(QueryParserTest, Apostrophes) {
64 EXPECT_EQ("foo* bar's*", QueryToString("foo bar's")); 66 EXPECT_EQ("foo* bar's*", QueryToString("foo bar's"));
65 EXPECT_EQ("l'foo*", QueryToString("l'foo")); 67 EXPECT_EQ("l'foo*", QueryToString("l'foo"));
66 EXPECT_EQ("foo*", QueryToString("'foo")); 68 EXPECT_EQ("foo*", QueryToString("'foo"));
67 } 69 }
68 70
69 // Special characters. 71 // Special characters.
70 TEST_F(QueryParserTest, SpecialChars) { 72 TEST_F(QueryParserTest, SpecialChars) {
71 EXPECT_EQ("foo* the* bar*", QueryToString("!#:/*foo#$*;'* the!#:/*bar")); 73 EXPECT_EQ("foo* the* bar*", QueryToString("!#:/*foo#$*;'* the!#:/*bar"));
74
75 // URL-like queries should be left intact.
76 EXPECT_EQ("chromium.org/fun*", QueryToString("chromium.org/fun"));
77 EXPECT_EQ("a.b.c/~x-y-zed*", QueryToString("a.b.c/~x-y-zed"));
78
79 // Special chars inside quotes should be preserved.
80 EXPECT_EQ("\"$FOO\" bar*", QueryToString("\"$FOO\" .bar*"));
81 EXPECT_EQ("\"aa #&$ bb\"", QueryToString("\"aa #&$ bb\""));
82
83 // Leading punctuation should always be stripped.
84 EXPECT_EQ("test*", QueryToString(".test"));
85 EXPECT_EQ("test.*", QueryToString("~test."));
86 EXPECT_EQ("test*", QueryToString("--test"));
mrossetti 2012/02/09 00:27:03 Excellent unit test additions! May I suggest addi
Patrick Dubroy 2012/02/09 14:47:00 Good idea, done.
72 } 87 }
73 88
74 TEST_F(QueryParserTest, NumWords) { 89 TEST_F(QueryParserTest, NumWords) {
75 TestData data[] = { 90 TestData data[] = {
76 { "blah", 1 }, 91 { "blah", 1 },
77 { "foo \"bar baz\"", 3 }, 92 { "foo \"bar baz\"", 3 },
78 { "foo \"baz\"", 2 }, 93 { "foo \"baz\"", 2 },
79 { "foo \"bar baz\" blah", 4 }, 94 { "foo \"bar baz\" blah", 4 },
80 }; 95 };
81 96
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 QueryParser parser; 169 QueryParser parser;
155 parser.ParseQueryWords(UTF8ToUTF16(data[i].text), &results); 170 parser.ParseQueryWords(UTF8ToUTF16(data[i].text), &results);
156 ASSERT_EQ(data[i].word_count, results.size()); 171 ASSERT_EQ(data[i].word_count, results.size());
157 EXPECT_EQ(data[i].w1, UTF16ToUTF8(results[0])); 172 EXPECT_EQ(data[i].w1, UTF16ToUTF8(results[0]));
158 if (results.size() == 2) 173 if (results.size() == 2)
159 EXPECT_EQ(data[i].w2, UTF16ToUTF8(results[1])); 174 EXPECT_EQ(data[i].w2, UTF16ToUTF8(results[1]));
160 if (results.size() == 3) 175 if (results.size() == 3)
161 EXPECT_EQ(data[i].w3, UTF16ToUTF8(results[2])); 176 EXPECT_EQ(data[i].w3, UTF16ToUTF8(results[2]));
162 } 177 }
163 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698