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. 4 5#include "chrome/browser/ui/app_list/search/tokenized_string.h" 6 7#include "base/strings/utf_string_conversions.h" 8#include "testing/gtest/include/gtest/gtest.h" 9 10namespace app_list { 11namespace test { 12 13namespace { 14 15string16 GetContent(const TokenizedString& tokenized) { 16 const TokenizedString::Tokens& tokens = tokenized.tokens(); 17 const TokenizedString::Mappings& mappings = tokenized.mappings(); 18 19 string16 str; 20 for (size_t i = 0; i < tokens.size(); ++i) { 21 if (i > 0) 22 str += ' '; 23 str += tokens[i]; 24 str += UTF8ToUTF16(mappings[i].ToString()); 25 } 26 return str; 27} 28 29} // namespace 30 31TEST(TokenizedStringTest, Empty) { 32 string16 empty; 33 TokenizedString tokens(empty); 34 EXPECT_EQ(string16(), GetContent(tokens)); 35} 36 37TEST(TokenizedStringTest, Basic) { 38 { 39 string16 text(UTF8ToUTF16("ScratchPad")); 40 TokenizedString tokens(text); 41 EXPECT_EQ(UTF8ToUTF16("scratch{0,7} pad{7,10}"), 42 GetContent(tokens)); 43 } 44 { 45 string16 text(UTF8ToUTF16("Chess2.0")); 46 TokenizedString tokens(text); 47 EXPECT_EQ(UTF8ToUTF16("chess{0,5} 2.0{5,8}"), 48 GetContent(tokens)); 49 } 50 { 51 string16 text(UTF8ToUTF16("Cut the rope")); 52 TokenizedString tokens(text); 53 EXPECT_EQ(UTF8ToUTF16("cut{0,3} the{4,7} rope{8,12}"), 54 GetContent(tokens)); 55 } 56 { 57 string16 text(UTF8ToUTF16("AutoCAD WS")); 58 TokenizedString tokens(text); 59 EXPECT_EQ(UTF8ToUTF16("auto{0,4} cad{4,7} ws{8,10}"), 60 GetContent(tokens)); 61 } 62 { 63 string16 text(UTF8ToUTF16("Great TweetDeck")); 64 TokenizedString tokens(text); 65 EXPECT_EQ(UTF8ToUTF16("great{0,5} tweet{6,11} deck{11,15}"), 66 GetContent(tokens)); 67 } 68 { 69 string16 text(UTF8ToUTF16("Draw-It!")); 70 TokenizedString tokens(text); 71 EXPECT_EQ(UTF8ToUTF16("draw{0,4} it{5,7}"), 72 GetContent(tokens)); 73 } 74 { 75 string16 text(UTF8ToUTF16("Faxing & Signing")); 76 TokenizedString tokens(text); 77 EXPECT_EQ(UTF8ToUTF16("faxing{0,6} signing{9,16}"), 78 GetContent(tokens)); 79 } 80 { 81 string16 text(UTF8ToUTF16("!@#$%^&*()<<<**>>>")); 82 TokenizedString tokens(text); 83 EXPECT_EQ(UTF8ToUTF16(""), 84 GetContent(tokens)); 85 } 86} 87 88} // namespace test 89} // namespace app_list 90