OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ios/web/public/string_util.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace web { |
| 11 |
| 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)); |
| 17 } |
| 18 |
| 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)); |
| 30 } |
| 31 |
| 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)); |
| 43 } |
| 44 |
| 45 } // namespace web |
OLD | NEW |