Add ICU message format support
[chromium-blink-merge.git] / ios / web / string_util_unittest.cc
blob4899a92222794edf47e8173d4f1ab7f104b33169
1 // Copyright 2014 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 "ios/web/public/string_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace web {
12 // Tests that a regular sentence is clipped correctly.
13 TEST(StringByClippingLastWordTest, ClipRegularSentence) {
14 const base::string16 kInput =
15 base::UTF8ToUTF16("\nSome text here and there.");
16 EXPECT_EQ(kInput, GetStringByClippingLastWord(kInput, 100));
19 // Tests that a long sentence exceeding some length is clipped correctly.
20 TEST(StringByClippingLastWordTest, ClipLongSentence) {
21 // An arbitrary length.
22 const size_t kStringLength = 10;
23 base::string16 string(kStringLength, 'a');
24 string.append(base::UTF8ToUTF16(" b cdefghijklmnopqrstuvwxyz"));
25 // The string should be cut at the last whitespace, after the 'b' character.
26 base::string16 result =
27 GetStringByClippingLastWord(string, kStringLength + 3);
28 EXPECT_EQ(kStringLength + 2, result.size());
29 EXPECT_EQ(0u, string.find_first_of(result));
32 // Tests that a block of text with no space is truncated to kLongStringLength.
33 TEST(StringByClippingLastWordTest, ClipLongTextContentNoSpace) {
34 // Very long string.
35 const size_t kLongStringLength = 65536;
36 // A string slightly longer than |kLongStringLength|.
37 base::string16 long_string(kLongStringLength + 10, 'a');
38 // Block of text with no space should be truncated to kLongStringLength.
39 base::string16 result =
40 GetStringByClippingLastWord(long_string, kLongStringLength);
41 EXPECT_EQ(kLongStringLength, result.size());
42 EXPECT_EQ(0u, long_string.find_first_of(result));
45 } // namespace web