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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/app_list/search/tokenized_string.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
15 base::string16
GetContent(const TokenizedString
& tokenized
) {
16 const TokenizedString::Tokens
& tokens
= tokenized
.tokens();
17 const TokenizedString::Mappings
& mappings
= tokenized
.mappings();
20 for (size_t i
= 0; i
< tokens
.size(); ++i
) {
24 str
+= base::UTF8ToUTF16(mappings
[i
].ToString());
31 TEST(TokenizedStringTest
, Empty
) {
33 TokenizedString
tokens(empty
);
34 EXPECT_EQ(base::string16(), GetContent(tokens
));
37 TEST(TokenizedStringTest
, Basic
) {
39 base::string16
text(base::UTF8ToUTF16("ScratchPad"));
40 TokenizedString
tokens(text
);
41 EXPECT_EQ(base::UTF8ToUTF16("scratch{0,7} pad{7,10}"),
45 base::string16
text(base::UTF8ToUTF16("Chess2.0"));
46 TokenizedString
tokens(text
);
47 EXPECT_EQ(base::UTF8ToUTF16("chess{0,5} 2.0{5,8}"),
51 base::string16
text(base::UTF8ToUTF16("Cut the rope"));
52 TokenizedString
tokens(text
);
53 EXPECT_EQ(base::UTF8ToUTF16("cut{0,3} the{4,7} rope{8,12}"),
57 base::string16
text(base::UTF8ToUTF16("AutoCAD WS"));
58 TokenizedString
tokens(text
);
59 EXPECT_EQ(base::UTF8ToUTF16("auto{0,4} cad{4,7} ws{8,10}"),
63 base::string16
text(base::UTF8ToUTF16("Great TweetDeck"));
64 TokenizedString
tokens(text
);
65 EXPECT_EQ(base::UTF8ToUTF16("great{0,5} tweet{6,11} deck{11,15}"),
69 base::string16
text(base::UTF8ToUTF16("Draw-It!"));
70 TokenizedString
tokens(text
);
71 EXPECT_EQ(base::UTF8ToUTF16("draw{0,4} it{5,7}"),
75 base::string16
text(base::UTF8ToUTF16("Faxing & Signing"));
76 TokenizedString
tokens(text
);
77 EXPECT_EQ(base::UTF8ToUTF16("faxing{0,6} signing{9,16}"),
81 base::string16
text(base::UTF8ToUTF16("!@#$%^&*()<<<**>>>"));
82 TokenizedString
tokens(text
);
83 EXPECT_EQ(base::UTF8ToUTF16(""),
89 } // namespace app_list