OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/google_apis/drive_api_util.h" | 5 #include "chrome/browser/google_apis/drive_api_util.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace google_apis { | 9 namespace google_apis { |
10 namespace drive { | 10 namespace drive { |
11 namespace util { | 11 namespace util { |
12 | 12 |
13 TEST(DriveApiUtilTest, EscapeQueryStringValue) { | 13 TEST(DriveApiUtilTest, EscapeQueryStringValue) { |
14 EXPECT_EQ("abcde", EscapeQueryStringValue("abcde")); | 14 EXPECT_EQ("abcde", EscapeQueryStringValue("abcde")); |
15 EXPECT_EQ("\\'", EscapeQueryStringValue("'")); | 15 EXPECT_EQ("\\'", EscapeQueryStringValue("'")); |
16 EXPECT_EQ("\\'abcde\\'", EscapeQueryStringValue("'abcde'")); | 16 EXPECT_EQ("\\'abcde\\'", EscapeQueryStringValue("'abcde'")); |
17 } | 17 } |
18 | 18 |
| 19 TEST(DriveApiUtilTest, TranslateQuery) { |
| 20 EXPECT_EQ("", TranslateQuery("")); |
| 21 EXPECT_EQ("fullText contains 'dog'", TranslateQuery("dog")); |
| 22 EXPECT_EQ("fullText contains 'dog' and fullText contains 'cat'", |
| 23 TranslateQuery("dog cat")); |
| 24 EXPECT_EQ("not fullText contains 'cat'", TranslateQuery("-cat")); |
| 25 EXPECT_EQ("fullText contains 'dog cat'", TranslateQuery("\"dog cat\"")); |
| 26 |
| 27 // Should handles full-width white space correctly. |
| 28 // Note: \xE3\x80\x80 (\u3000) is Ideographic Space (a.k.a. Japanese |
| 29 // full-width whitespace). |
| 30 EXPECT_EQ("fullText contains 'dog' and fullText contains 'cat'", |
| 31 TranslateQuery("dog" "\xE3\x80\x80" "cat")); |
| 32 |
| 33 // If the quoted token is not closed (i.e. the last '"' is missing), |
| 34 // we handle the remaining string is one token, as a fallback. |
| 35 EXPECT_EQ("fullText contains 'dog cat'", TranslateQuery("\"dog cat")); |
| 36 |
| 37 // For quoted text with leading '-'. |
| 38 EXPECT_EQ("not fullText contains 'dog cat'", TranslateQuery("-\"dog cat\"")); |
| 39 |
| 40 // Empty tokens should be simply ignored. |
| 41 EXPECT_EQ("", TranslateQuery("-")); |
| 42 EXPECT_EQ("", TranslateQuery("\"\"")); |
| 43 EXPECT_EQ("", TranslateQuery("-\"\"")); |
| 44 EXPECT_EQ("", TranslateQuery("\"\"\"\"")); |
| 45 EXPECT_EQ("", TranslateQuery("\"\" \"\"")); |
| 46 EXPECT_EQ("fullText contains 'dog'", TranslateQuery("\"\" dog \"\"")); |
| 47 } |
| 48 |
19 } // namespace util | 49 } // namespace util |
20 } // namespace drive | 50 } // namespace drive |
21 } // namespace google_apis | 51 } // namespace google_apis |
OLD | NEW |