1 // Copyright (c) 2011 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/spellchecker/word_trimmer.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using base::ASCIIToUTF16
;
12 TEST(WordTrimmerTest
, TrimWordsEmptyText
) {
15 EXPECT_EQ(base::string16(), TrimWords(&start
, end
, base::string16(), 0));
16 EXPECT_EQ(0UL, start
);
19 TEST(WordTrimmerTest
, TrimWordsStart
) {
22 EXPECT_EQ(ASCIIToUTF16("one two three"),
23 TrimWords(&start
, end
, ASCIIToUTF16("one two three four"), 2));
24 EXPECT_EQ(0UL, start
);
27 TEST(WordTrimmerTest
, TrimWordsEnd
) {
30 EXPECT_EQ(ASCIIToUTF16("two three four"),
31 TrimWords(&start
, end
, ASCIIToUTF16("one two three four"), 2));
32 EXPECT_EQ(10UL, start
);
35 TEST(WordTrimmerTest
, TrimWordsMiddle
) {
38 EXPECT_EQ(ASCIIToUTF16("two three four five six seven"), TrimWords(
39 &start
, end
, ASCIIToUTF16("one two three four five six seven eight"), 2));
40 EXPECT_EQ(10UL, start
);
43 TEST(WordTrimmerTest
, TrimWordsEmptyKeep
) {
46 EXPECT_EQ(ASCIIToUTF16("two three four five six"), TrimWords(
47 &start
, end
, ASCIIToUTF16("one two three four five six seven eight"), 2));
48 EXPECT_EQ(14UL, start
);
51 TEST(WordTrimmerTest
, TrimWordsOutOfBounds
) {
54 EXPECT_EQ(ASCIIToUTF16("one"), TrimWords(
55 &start
, end
, ASCIIToUTF16("one"), 2));
56 EXPECT_EQ(4UL, start
);
59 TEST(WordTrimmerTest
, TrimWordsInvalid
) {
62 EXPECT_EQ(ASCIIToUTF16("one two three four five six seven eight"), TrimWords(
63 &start
, end
, ASCIIToUTF16("one two three four five six seven eight"), 2));
64 EXPECT_EQ(23UL, start
);