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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h" | 9 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace app_list { | 12 namespace app_list { |
13 namespace test { | 13 namespace test { |
14 | 14 |
15 // Returns a string of |text| marked the hits in |match| using block bracket. | 15 // Returns a string of |text| marked the hits in |match| using block bracket. |
16 // e.g. text= "Text", hits = [{0,1}], returns "[T]ext". | 16 // e.g. text= "Text", hits = [{0,1}], returns "[T]ext". |
17 std::string MatchHit(const string16& text, | 17 std::string MatchHit(const string16& text, |
18 const TokenizedStringMatch& match) { | 18 const TokenizedStringMatch& match) { |
19 string16 marked = text; | 19 string16 marked = text; |
20 | 20 |
21 const TokenizedStringMatch::Hits& hits = match.hits(); | 21 const TokenizedStringMatch::Hits& hits = match.hits(); |
22 for (TokenizedStringMatch::Hits::const_reverse_iterator it = hits.rbegin(); | 22 for (TokenizedStringMatch::Hits::const_reverse_iterator it = hits.rbegin(); |
23 it != hits.rend(); ++it) { | 23 it != hits.rend(); ++it) { |
24 const ui::Range& hit = *it; | 24 const gfx::Range& hit = *it; |
25 marked.insert(hit.end(), 1, ']'); | 25 marked.insert(hit.end(), 1, ']'); |
26 marked.insert(hit.start(), 1, '['); | 26 marked.insert(hit.start(), 1, '['); |
27 } | 27 } |
28 | 28 |
29 return UTF16ToUTF8(marked); | 29 return UTF16ToUTF8(marked); |
30 } | 30 } |
31 | 31 |
32 TEST(TokenizedStringMatchTest, NotMatch) { | 32 TEST(TokenizedStringMatchTest, NotMatch) { |
33 struct { | 33 struct { |
34 const char* text; | 34 const char* text; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 EXPECT_LT(match_low.relevance(), match_high.relevance()) | 106 EXPECT_LT(match_low.relevance(), match_high.relevance()) |
107 << "Test case " << i | 107 << "Test case " << i |
108 << " : text=" << kTestCases[i].text | 108 << " : text=" << kTestCases[i].text |
109 << ", query_low=" << kTestCases[i].query_low | 109 << ", query_low=" << kTestCases[i].query_low |
110 << ", query_high=" << kTestCases[i].query_high; | 110 << ", query_high=" << kTestCases[i].query_high; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 } // namespace test | 114 } // namespace test |
115 } // namespace app_list | 115 } // namespace app_list |
OLD | NEW |