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.
4
5#include "chrome/browser/spellchecker/word_trimmer.h"
6
7#include "base/strings/utf_string_conversions.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10using base::ASCIIToUTF16;
11
12TEST(WordTrimmerTest, TrimWordsEmptyText) {
13  size_t start = 0;
14  size_t end = 0;
15  EXPECT_EQ(base::string16(), TrimWords(&start, end, base::string16(), 0));
16  EXPECT_EQ(0UL, start);
17}
18
19TEST(WordTrimmerTest, TrimWordsStart) {
20  size_t start = 0;
21  size_t end = 3;
22  EXPECT_EQ(ASCIIToUTF16("one two three"),
23            TrimWords(&start, end, ASCIIToUTF16("one two three four"), 2));
24  EXPECT_EQ(0UL, start);
25}
26
27TEST(WordTrimmerTest, TrimWordsEnd) {
28  size_t start = 14;
29  size_t end = 18;
30  EXPECT_EQ(ASCIIToUTF16("two three four"),
31            TrimWords(&start, end, ASCIIToUTF16("one two three four"), 2));
32  EXPECT_EQ(10UL, start);
33}
34
35TEST(WordTrimmerTest, TrimWordsMiddle) {
36  size_t start = 14;
37  size_t end = 23;
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);
41}
42
43TEST(WordTrimmerTest, TrimWordsEmptyKeep) {
44  size_t start = 18;
45  size_t end = 18;
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);
49}
50
51TEST(WordTrimmerTest, TrimWordsOutOfBounds) {
52  size_t start = 4;
53  size_t end = 5;
54  EXPECT_EQ(ASCIIToUTF16("one"), TrimWords(
55      &start, end, ASCIIToUTF16("one"), 2));
56  EXPECT_EQ(4UL, start);
57}
58
59TEST(WordTrimmerTest, TrimWordsInvalid) {
60  size_t start = 23;
61  size_t end = 14;
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);
65}
66