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 "ui/app_list/search/term_break_iterator.h"
6
7#include "base/strings/utf_string_conversions.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10using base::UTF8ToUTF16;
11
12namespace app_list {
13namespace test {
14
15TEST(TermBreakIteratorTest, EmptyWord) {
16  base::string16 empty;
17  TermBreakIterator iter(empty);
18  EXPECT_FALSE(iter.Advance());
19}
20
21TEST(TermBreakIteratorTest, Simple) {
22  base::string16 word(UTF8ToUTF16("simple"));
23  TermBreakIterator iter(word);
24  EXPECT_TRUE(iter.Advance());
25  EXPECT_EQ(UTF8ToUTF16("simple"), iter.GetCurrentTerm());
26  EXPECT_FALSE(iter.Advance());  // Test unexpected advance after end.
27}
28
29TEST(TermBreakIteratorTest, CamelCase) {
30  base::string16 word(UTF8ToUTF16("CamelCase"));
31  TermBreakIterator iter(word);
32  EXPECT_TRUE(iter.Advance());
33  EXPECT_EQ(UTF8ToUTF16("Camel"), iter.GetCurrentTerm());
34  EXPECT_TRUE(iter.Advance());
35  EXPECT_EQ(UTF8ToUTF16("Case"), iter.GetCurrentTerm());
36  EXPECT_FALSE(iter.Advance());  // Test unexpected advance after end.
37}
38
39TEST(TermBreakIteratorTest, LowerToUpper) {
40  base::string16 word(UTF8ToUTF16("lowerToUpper"));
41  TermBreakIterator iter(word);
42  EXPECT_TRUE(iter.Advance());
43  EXPECT_EQ(UTF8ToUTF16("lower"), iter.GetCurrentTerm());
44  EXPECT_TRUE(iter.Advance());
45  EXPECT_EQ(UTF8ToUTF16("To"), iter.GetCurrentTerm());
46  EXPECT_TRUE(iter.Advance());
47  EXPECT_EQ(UTF8ToUTF16("Upper"), iter.GetCurrentTerm());
48  EXPECT_FALSE(iter.Advance());  // Test unexpected advance after end.
49}
50
51TEST(TermBreakIteratorTest, AlphaNumber) {
52  base::string16 word(UTF8ToUTF16("Chromium26.0.0.0"));
53  TermBreakIterator iter(word);
54  EXPECT_TRUE(iter.Advance());
55  EXPECT_EQ(UTF8ToUTF16("Chromium"), iter.GetCurrentTerm());
56  EXPECT_TRUE(iter.Advance());
57  EXPECT_EQ(UTF8ToUTF16("26.0.0.0"), iter.GetCurrentTerm());
58  EXPECT_FALSE(iter.Advance());  // Test unexpected advance after end.
59}
60
61TEST(TermBreakIteratorTest, StartsWithNumber) {
62  base::string16 word(UTF8ToUTF16("123startWithNumber"));
63  TermBreakIterator iter(word);
64  EXPECT_TRUE(iter.Advance());
65  EXPECT_EQ(UTF8ToUTF16("123"), iter.GetCurrentTerm());
66  EXPECT_TRUE(iter.Advance());
67  EXPECT_EQ(UTF8ToUTF16("start"), iter.GetCurrentTerm());
68  EXPECT_TRUE(iter.Advance());
69  EXPECT_EQ(UTF8ToUTF16("With"), iter.GetCurrentTerm());
70  EXPECT_TRUE(iter.Advance());
71  EXPECT_EQ(UTF8ToUTF16("Number"), iter.GetCurrentTerm());
72  EXPECT_FALSE(iter.Advance());  // Test unexpected advance after end.
73}
74
75TEST(TermBreakIteratorTest, CaseAndNoCase) {
76  // "English" + two Chinese chars U+4E2D U+6587 + "Word"
77  base::string16 word(UTF8ToUTF16("English\xe4\xb8\xad\xe6\x96\x87Word"));
78  TermBreakIterator iter(word);
79  EXPECT_TRUE(iter.Advance());
80  EXPECT_EQ(UTF8ToUTF16("English"), iter.GetCurrentTerm());
81  EXPECT_TRUE(iter.Advance());
82  EXPECT_EQ(UTF8ToUTF16("\xe4\xb8\xad\xe6\x96\x87"), iter.GetCurrentTerm());
83  EXPECT_TRUE(iter.Advance());
84  EXPECT_EQ(UTF8ToUTF16("Word"), iter.GetCurrentTerm());
85  EXPECT_FALSE(iter.Advance());  // Test unexpected advance after end.
86}
87
88}  // namespace test
89}  // namespace app_list
90